25 #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
26 #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
29 int64_t
end, pos= ftell(f);
30 fseek(f, 0, SEEK_END);
32 fseek(f, pos, SEEK_SET);
36 int main(
int argc,
char **argv){
43 int16_t *signal, *
data;
47 printf(
"audiomatch <testfile> <reffile>\n");
48 printf(
"WAV headers are skipped automatically.\n");
52 f[0] = fopen(argv[1],
"rb");
53 f[1] = fopen(argv[2],
"rb");
55 fprintf(stderr,
"Could not open input files.\n");
59 for (i = 0; i < 2; i++) {
61 if (fread(p, 1, 12, f[i]) != 12)
63 if (!memcmp(p,
"RIFF", 4) &&
64 !memcmp(p + 8,
"WAVE", 4)) {
65 if (fread(p, 1, 8, f[i]) != 8)
67 while (memcmp(p,
"data", 4)) {
68 int s = p[4] | p[5] << 8 | p[6] << 16 | p[7] << 24;
69 fseek(f[i], s, SEEK_CUR);
70 if (fread(p, 1, 8, f[i]) != 8)
74 fseek(f[i], -12, SEEK_CUR);
78 datlen =
fsize(f[0]) - ftell(f[0]);
79 siglen =
fsize(f[1]) - ftell(f[1]);
80 data = malloc(datlen *
sizeof(*data));
81 signal = malloc(siglen *
sizeof(*signal));
83 fread(data , 1, datlen, f[0]);
84 fread(signal, 1, siglen, f[1]);
88 for(i=0; i<siglen; i++){
89 signal[i] = ((
uint8_t*)(signal + i))[0] + 256*((
uint8_t*)(signal + i))[1];
90 sigamp += signal[i] * signal[i];
92 for(i=0; i<datlen; i++)
93 data[i] = ((
uint8_t*)(data + i))[0] + 256*((
uint8_t*)(data + i))[1];
95 for(pos = 0; pos<maxshift; pos = pos < 0 ? -pos: -pos-1){
97 int testlen =
FFMIN(siglen, datlen-pos);
98 for(i=
FFMAX(0, -pos); i<testlen; i++){
100 c += signal[i] * data[j];
102 if(fabs(c) > sigamp * 0.94)
103 maxshift =
FFMIN(maxshift, fabs(pos)+32);
104 if(fabs(c)>fabs(bestc)){
109 printf(
"presig: %d postsig:%d c:%7.4f lenerr:%d\n", bestpos, datlen - siglen - bestpos, bestc / sigamp, datlen - siglen);
ptrdiff_t const GLvoid * data
int main(int argc, char **argv)
static av_cold int end(AVCodecContext *avctx)
static int64_t fsize(FILE *f)