Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/alexmarsev/soxr.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Sykes <robs@users.sourceforge.net>2015-08-20 20:15:47 +0300
committerRob Sykes <robs@users.sourceforge.net>2015-08-20 20:15:47 +0300
commitb93320cba798d8857577f2da13e6844e82cc2157 (patch)
tree5cb052103a54a1791d3ef5d45d88136e8d9d3ac9
parent4527588beae35c0aefd10df1f9936cb81f9851cc (diff)
add test for previous 2 fixes
-rw-r--r--tests/1-delay-clear.c64
-rw-r--r--tests/CMakeLists.txt2
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/1-delay-clear.c b/tests/1-delay-clear.c
new file mode 100644
index 0000000..ba4d47c
--- /dev/null
+++ b/tests/1-delay-clear.c
@@ -0,0 +1,64 @@
+/* SoX Resampler Library Copyright (c) 2007-15 robs@users.sourceforge.net
+ * Licence for this file: LGPL v2.1 See LICENCE for details. */
+
+/* Test 1: exercises soxr_delay and soxr_clear */
+
+#ifdef NDEBUG /* N.B. assert used with active statements so enable always. */
+#undef NDEBUG /* Must undef above assert.h or other that might include it. */
+#endif
+
+#include <soxr.h>
+#include "../examples/examples-common.h"
+
+#define ranqd1(x) ((x) = 1664525 * (x) + 1013904223) /* int32_t x */
+#define franqd1(x) (float)(ranqd1(x) * (1. / (65536. * 32768.))) /* [-1,1) */
+
+#define irate 9600
+#define orate 4410
+
+int main(int argc, char const * arg[])
+{
+ soxr_error_t error;
+ int32_t ran = 0;
+ int j;
+
+ soxr_t soxr = soxr_create(irate, orate, 1, &error, NULL, NULL, NULL);
+ assert(!error);
+
+ for (j=0; j<2; ++j) {
+ float ibuf[irate], out[orate+2], obuf[orate+2], * ibuf1 = ibuf;
+ size_t ilen = AL(ibuf)-1, olen = AL(obuf), i, odone = 0, odone0, odone1=0;
+ soxr_quality_spec_t q_spec = soxr_quality_spec(SOXR_HQ, 0);
+
+ for (i=0; i<irate; ibuf[i++] = franqd1(ran));
+
+ error = soxr_oneshot(irate, orate, 1, ibuf, ilen, NULL,
+ out, AL(out), &odone0, NULL, &q_spec, NULL);
+ assert(!error);
+ assert(odone0==orate);
+
+ for (i=0; ilen || odone1; ++i) {
+ double out_samples = (double)orate / irate * (double)ilen;
+ double delayed_samples = soxr_delay(soxr);
+ unsigned max_out_samples = (unsigned)(out_samples + delayed_samples + .5);
+ assert(delayed_samples >= 0);
+ fprintf(stderr, "%5u %5u %5u\n",
+ (unsigned)ilen, max_out_samples, (unsigned)odone);
+ assert(max_out_samples+odone==odone0);
+ error = soxr_process(soxr, ibuf1, ilen, NULL, obuf+odone, olen, &odone1);
+ assert(!error);
+ odone += odone1;
+ ibuf1 = NULL, ilen = 0;
+ olen = min(100, AL(obuf)-odone);
+ }
+ assert(odone==odone0);
+
+ for (i=0; i<odone && out[i]==obuf[i]; ++i);
+ assert(i==odone);
+
+ soxr_clear(soxr);
+ }
+ soxr_delete(soxr);
+
+ return 0 * argc * !arg;
+}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 277fc55..333c0bd 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -48,3 +48,5 @@ foreach (b ${test_bits})
endforeach ()
add_custom_target (test-vectors ALL DEPENDS ${vectors})
+
+add_test (1-delay-clear ${BIN}1-delay-clear)