ref: 52c1de9c473cbc257503ac72e4daa160dbda2f9c
parent: 3beacb38cc3ea159fb66bcc2c2bd675d5678996c
author: Paul Brossier <piem@piem.org>
date: Wed Aug 22 11:56:50 EDT 2018
tests/src/spectral/test-dct.c: check reconstruction works
--- a/tests/src/spectral/test-dct.c
+++ b/tests/src/spectral/test-dct.c
@@ -1,15 +1,18 @@
-#include <aubio.h>
+#include <math.h>
+#include "aubio.h"
+#include "utils_tests.h"
int main (void)
{
int return_code = 0;
uint_t win_s = 32; // window size
- uint_t i, n_iters = 10; // number of iterations
+ uint_t i, j, n_iters = 10; // number of iterations
// create dct object
aubio_dct_t * dct = new_aubio_dct(win_s);
fvec_t * in = new_fvec (win_s); // input buffer
fvec_t * dctout = new_fvec (win_s); // output buffer
+ fvec_t * out = new_fvec (win_s); // input buffer
if (!dct || !in || !dctout) {
return_code = 1;
@@ -19,13 +22,22 @@
in->data[0] = 1.;
for (i = 0; i < n_iters; i++) {
aubio_dct_do (dct, in, dctout);
- aubio_dct_rdo (dct, dctout, in);
+ aubio_dct_rdo (dct, dctout, out);
+ for (j = 0; j < in->length; j++) {
+ if (fabsf(in->data[j] - out->data[j]) > 10.e-4) {
+ fprintf(stderr, "dct reconstruction failed\n");
+ }
+ }
}
- fvec_print(dctout);
+
fvec_print(in);
+ fvec_print(dctout);
+ fvec_print(out);
+
del_fvec(dctout);
del_fvec(in);
-
+ del_fvec(out);
del_aubio_dct(dct);
+
return return_code;
}