Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix testresample.c output span; add exit code #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions tests/testresample.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#define MIN(A, B) (A) < (B)? (A) : (B)

int global_error;

void runtest(int srclen, double freq, double factor,
int srcblocksize, int dstblocksize)
{
Expand Down Expand Up @@ -65,10 +67,12 @@ void runtest(int srclen, double freq, double factor,

if (o < 0) {
printf("Error: resample_process returned an error: %d\n", o);
global_error = 1;
}

if (out <= 0) {
printf("Error: resample_process returned %d samples\n", out);
global_error = 1;
free(src);
free(dst);
return;
Expand All @@ -79,15 +83,16 @@ void runtest(int srclen, double freq, double factor,
printf(" Expected ~%d, got %d samples out\n",
expectedlen, out);
}

sum = 0.0;
sumsq = 0.0;
errcount = 0.0;

/* Don't compute statistics on all output values; the last few
are guaranteed to be off because it's based on far less
interpolation. */
statlen = out - fwidth;
/* Don't compute statistics on all output values; the last small fraction
are guaranteed to be off since they are interpolated based on far fewer
values. When upsampling, the length of the range where this concern
applies is in direct proportion to the upsampling factor. */
statlen = out - ((int)round(fwidth * factor));

for(i=0; i<statlen; i++) {
double diff = sin((i/freq)/factor) - dst[i];
Expand Down Expand Up @@ -117,6 +122,7 @@ void runtest(int srclen, double freq, double factor,
printf(" i=%d: expected %.3f, got %.3f\n",
i, sin((i/freq)/factor), dst[i]);
printf(" At least %d samples had significant error.\n", errcount);
global_error = 1;
}
err = sum / statlen;
rmserr = sqrt(sumsq / statlen);
Expand All @@ -130,6 +136,8 @@ int main(int argc, char **argv)
int i, srclen, dstlen, ifreq;
double factor;

global_error = 0;

printf("\n*** Vary source block size*** \n\n");
srclen = 10000;
ifreq = 100;
Expand Down Expand Up @@ -172,11 +180,19 @@ int main(int argc, char **argv)
printf("\n*** Resample with different factors ***\n\n");
srclen = 10000;
ifreq = 100;
for(i=0; i<100; i++) {
factor = ((rand() % 64) + 1) / 4.0;
for (i = 1; i < 64; i++) {
factor = i / 4.0;
dstlen = (int)(srclen * factor + 10);
runtest(srclen, (double)ifreq, factor, srclen, dstlen);
}

printf("\n*** Resample with large factors ***\n\n");
srclen = 200;
ifreq = 100;
for (factor = 25.0; factor < 1000.0; factor *= 1.7) {
dstlen = (int)(srclen * factor + 10);
runtest(srclen, (double)ifreq, factor, srclen, dstlen);
}

return 0;
return global_error;
}