1 From fb8e3c74d582038a358936d827f53c4c0c43d4e6 Mon Sep 17 00:00:00 2001
2 From: Matt Harvey <mattharvey@google.com>
3 Date: Mon, 27 Nov 2023 16:28:53 -0800
4 Subject: [PATCH] Fix testresample.c output span; add exit code
6 Prior to this chance, the "Resample with different factors" test only
7 passed for 60 of the 63 factors, with the 3 failing ones being the
10 1. Since only 63 distinct factors were being considered, 100 random
12 2. To support noticing failure in continuous build systems, it's nice if
13 the test exit()s with nonzero when there are failures.
14 3. The root cause was a formula error when determining which indices in
15 the resampled output ought be compared. Details are explained in a
18 tests/testresample.c | 32 ++++++++++++++++++++++++--------
19 1 file changed, 24 insertions(+), 8 deletions(-)
21 diff --git a/tests/testresample.c b/tests/testresample.c
22 index aa83a46..640df5a 100644
23 --- a/tests/testresample.c
24 +++ b/tests/testresample.c
27 #define MIN(A, B) (A) < (B)? (A) : (B)
31 void runtest(int srclen, double freq, double factor,
32 int srcblocksize, int dstblocksize)
34 @@ -65,10 +67,12 @@ void runtest(int srclen, double freq, double factor,
37 printf("Error: resample_process returned an error: %d\n", o);
42 printf("Error: resample_process returned %d samples\n", out);
47 @@ -79,15 +83,16 @@ void runtest(int srclen, double freq, double factor,
48 printf(" Expected ~%d, got %d samples out\n",
57 - /* Don't compute statistics on all output values; the last few
58 - are guaranteed to be off because it's based on far less
60 - statlen = out - fwidth;
61 + /* Don't compute statistics on all output values; the last small fraction
62 + are guaranteed to be off since they are interpolated based on far fewer
63 + values. When upsampling, the length of the range where this concern
64 + applies is in direct proportion to the upsampling factor. */
65 + statlen = out - ((int)round(fwidth * factor));
67 for(i=0; i<statlen; i++) {
68 double diff = sin((i/freq)/factor) - dst[i];
69 @@ -117,6 +122,7 @@ void runtest(int srclen, double freq, double factor,
70 printf(" i=%d: expected %.3f, got %.3f\n",
71 i, sin((i/freq)/factor), dst[i]);
72 printf(" At least %d samples had significant error.\n", errcount);
76 rmserr = sqrt(sumsq / statlen);
77 @@ -130,6 +136,8 @@ int main(int argc, char **argv)
78 int i, srclen, dstlen, ifreq;
83 printf("\n*** Vary source block size*** \n\n");
86 @@ -172,11 +180,19 @@ int main(int argc, char **argv)
87 printf("\n*** Resample with different factors ***\n\n");
90 - for(i=0; i<100; i++) {
91 - factor = ((rand() % 64) + 1) / 4.0;
92 + for (i = 1; i < 64; i++) {
94 + dstlen = (int)(srclen * factor + 10);
95 + runtest(srclen, (double)ifreq, factor, srclen, dstlen);
98 + printf("\n*** Resample with large factors ***\n\n");
101 + for (factor = 25.0; factor < 1000.0; factor *= 1.7) {
102 dstlen = (int)(srclen * factor + 10);
103 runtest(srclen, (double)ifreq, factor, srclen, dstlen);
107 + return global_error;