ref: 3aac1946f105ec900381341ff90fe6f9fb853d80
parent: d8b116187410e34448847af9a2df9269625b4538
parent: 95e3cba8835a77e9042793b4bfcb71f44384e7f1
author: Paul Brossier <piem@piem.org>
date: Sat Sep 15 12:27:29 EDT 2018
Merge branch 'feature/dct_multiopt' into feature/fastmfcc
--- a/python/tests/test_dct.py
+++ b/python/tests/test_dct.py
@@ -24,12 +24,12 @@
""" test that dct(arange(8)) is computed correctly
>>> from scipy.fftpack import dct
- >>> a_in = np.arange(8).astype('float32')
+ >>> a_in = np.arange(8).astype(aubio.float_type)
>>> precomputed = dct(a_in, norm='ortho')
"""
N = len(precomputed_arange)
a_dct = aubio.dct(8)
- a_in = np.arange(8).astype('float32')
+ a_in = np.arange(8).astype(aubio.float_type)
a_expected = aubio.fvec(precomputed_arange)
assert_almost_equal(a_dct(a_in), a_expected, decimal=6)
@@ -36,7 +36,7 @@
def test_some_ones(self):
""" test that dct(somevector) is computed correctly """
a_dct = aubio.dct(16)
- a_in = np.ones(16).astype('float32')
+ a_in = np.ones(16).astype(aubio.float_type)
a_in[1] = 0
a_in[3] = np.pi
a_expected = aubio.fvec(precomputed_some_ones)
@@ -45,7 +45,7 @@
def test_reconstruction(self):
""" test that some_ones vector can be recontructed """
a_dct = aubio.dct(16)
- a_in = np.ones(16).astype('float32')
+ a_in = np.ones(16).astype(aubio.float_type)
a_in[1] = 0
a_in[3] = np.pi
a_dct_in = a_dct(a_in)
--- a/src/spectral/dct_accelerate.c
+++ b/src/spectral/dct_accelerate.c
@@ -28,7 +28,7 @@
#warning "no double-precision dct with accelerate"
#endif
-struct _aubio_dct_t {
+struct _aubio_dct_accelerate_t {
uint_t size;
fvec_t *tmp;
vDSP_DFT_Setup setup;
@@ -35,12 +35,16 @@
vDSP_DFT_Setup setupInv;
};
-aubio_dct_t * new_aubio_dct (uint_t size) {
- aubio_dct_t * s = AUBIO_NEW(aubio_dct_t);
+typedef struct _aubio_dct_accelerate_t aubio_dct_accelerate_t;
+void del_aubio_dct_accelerate (aubio_dct_accelerate_t *s);
+
+aubio_dct_accelerate_t * new_aubio_dct_accelerate (uint_t size) {
+ aubio_dct_accelerate_t * s = AUBIO_NEW(aubio_dct_accelerate_t);
+
if ((sint_t)size < 16 || !aubio_is_power_of_two(size)) {
AUBIO_ERR("dct: can only create with sizes greater than 16 and"
- "that are powers of two, requested %d\n", size);
+ " that are powers of two, requested %d\n", size);
goto beach;
}
@@ -55,17 +59,17 @@
return s;
beach:
- del_aubio_dct(s);
+ del_aubio_dct_accelerate(s);
return NULL;
}
-void del_aubio_dct(aubio_dct_t *s) {
+void del_aubio_dct_accelerate(aubio_dct_accelerate_t *s) {
if (s->setup) vDSP_DFT_DestroySetup(s->setup);
if (s->setupInv) vDSP_DFT_DestroySetup(s->setupInv);
AUBIO_FREE(s);
}
-void aubio_dct_do(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
+void aubio_dct_accelerate_do(aubio_dct_accelerate_t *s, const fvec_t *input, fvec_t *output) {
vDSP_DCT_Execute(s->setup, (const float *)input->data, (float *)output->data);
@@ -78,7 +82,7 @@
}
-void aubio_dct_rdo(aubio_dct_t *s, const fvec_t *input, fvec_t *output) {
+void aubio_dct_accelerate_rdo(aubio_dct_accelerate_t *s, const fvec_t *input, fvec_t *output) {
output->data[0] = input->data[0] / SQRT(1./s->size);
smpl_t scaler = 1./SQRT(2./s->size);
--- 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;
}