25 #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) 26 #define FFMAX(a,b) ((a) > (b) ? (a) : (b)) 27 #define FFABS(a) ((a) >= 0 ? (a) : (-(a))) 30 int64_t
end,
pos = ftell(f);
31 fseek(f, 0, SEEK_END);
33 fseek(f, pos, SEEK_SET);
37 int main(
int argc,
char **argv) {
44 int16_t *signal, *
data;
48 printf(
"audiomatch <testfile> <reffile>\n");
49 printf(
"WAV headers are skipped automatically.\n");
53 f[0] = fopen(argv[1],
"rb");
54 f[1] = fopen(argv[2],
"rb");
56 fprintf(stderr,
"Could not open input files.\n");
60 for (i = 0; i < 2; i++) {
62 if (fread(p, 1, 12, f[i]) != 12)
64 if (!memcmp(p,
"RIFF", 4) &&
65 !memcmp(p + 8,
"WAVE", 4)) {
66 if (fread(p, 1, 8, f[i]) != 8)
68 while (memcmp(p,
"data", 4)) {
69 int s = p[4] | p[5] << 8 | p[6] << 16 | p[7] << 24;
70 fseek(f[i], s, SEEK_CUR);
71 if (fread(p, 1, 8, f[i]) != 8)
75 fseek(f[i], -12, SEEK_CUR);
79 datlen =
fsize(f[0]) - ftell(f[0]);
80 siglen =
fsize(f[1]) - ftell(f[1]);
81 data = malloc(datlen *
sizeof(*data));
82 signal = malloc(siglen *
sizeof(*signal));
84 if (fread(data , 1, datlen, f[0]) != datlen)
86 if (fread(signal, 1, siglen, f[1]) != siglen)
91 for (i = 0; i < siglen; i++) {
93 sigamp += signal[
i] * signal[
i];
95 for (i = 0; i < datlen; i++)
98 for (pos = 0; pos < maxshift; pos = pos < 0 ? -pos: -pos-1) {
100 int testlen =
FFMIN(siglen, datlen-pos);
101 for (i =
FFMAX(0, -pos); i < testlen; i++) {
103 c += signal[
i] * data[j];
105 if (
FFABS(c) > sigamp * 0.94)
112 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)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
printf("static const uint8_t my_array[100] = {\n")
static int64_t fsize(FILE *f)