28 int frame, nFrames, ch, i, nBands, procDelay, band, nHops;
31 float** insig, **outsig, **inframe, **outframe;
32 float_complex*** inspec, ***outspec;
35 const float acceptedTolerance = 0.01f;
37 const int signalLength = 1*fs;
38 const int framesize = 512;
39 const int hopsize = 128;
41 const int hybridMode = 1;
42 const int nCHout = 64;
43 insig = (
float**)
malloc2d(nCHin,signalLength,
sizeof(
float));
44 outsig = (
float**)
malloc2d(nCHout,signalLength,
sizeof(
float));
45 inframe = (
float**)
malloc2d(nCHin,framesize,
sizeof(
float));
46 outframe = (
float**)
malloc2d(nCHout,framesize,
sizeof(
float));
50 nHops = framesize/hopsize;
54 freqVector =
malloc1d(nBands*
sizeof(
float));
56 inspec = (float_complex***)
malloc3d(nBands, nCHin, nHops,
sizeof(float_complex));
58 outspec = (float_complex***)
malloc3d(nBands, nCHout, nHops,
sizeof(float_complex));
68 nFrames = (int)((
float)signalLength/(float)framesize);
69 for(frame = 0; frame<nFrames; frame++){
71 for(ch=0; ch<nCHin; ch++)
72 memcpy(inframe[ch], &insig[ch][frame*framesize], framesize*
sizeof(
float));
77 for(band=0; band<nBands; band++)
78 for(ch=0; ch<nCHout; ch++)
79 memcpy(outspec[band][ch], inspec[band][0], nHops*
sizeof(float_complex));
83 for(ch=0; ch<nCHout; ch++)
84 memcpy(&outsig[ch][frame*framesize], outframe[ch], framesize*
sizeof(
float));
88 for(i=0; i<signalLength-procDelay-framesize; i++)
89 TEST_ASSERT_TRUE( fabsf(insig[0][i] - outsig[0][i+procDelay]) <= acceptedTolerance );
104 typedef struct _test_data{
111 test_data reference[6][6];
112 for(i=0, k=0; i<6; i++){
113 for(j=0; j<6; j++, k++){
114 reference[i][j].ID = k;
121 test = (test_data**)
malloc2d(1,3,
sizeof(test_data));
124 memcpy(&test[s][r], &reference[s][r],
sizeof(test_data));
127 test = (test_data**)
realloc2d_r((
void**)test, 4, 3, 1, 3,
sizeof(test_data));
130 TEST_ASSERT_TRUE(test[i][j].ID==reference[i][j].ID);
131 TEST_ASSERT_TRUE(test[i][j].val1==reference[i][j].val1);
132 TEST_ASSERT_TRUE(test[i][j].val2==reference[i][j].val2);
139 memcpy(&test[s][r], &reference[s][r],
sizeof(test_data));
142 TEST_ASSERT_TRUE(test[i][j].ID==reference[i][j].ID);
143 TEST_ASSERT_TRUE(test[i][j].val1==reference[i][j].val1);
144 TEST_ASSERT_TRUE(test[i][j].val2==reference[i][j].val2);
149 test = (test_data**)
realloc2d_r((
void**)test, 4, 2, 4, 3,
sizeof(test_data));
152 TEST_ASSERT_TRUE(test[i][j].ID==reference[i][j].ID);
153 TEST_ASSERT_TRUE(test[i][j].val1==reference[i][j].val1);
154 TEST_ASSERT_TRUE(test[i][j].val2==reference[i][j].val2);
166 int**** test_malloc_4d;
167 test_malloc_4d = (
int****)
malloc4d(3, 4, 2, 5,
sizeof(
int));
174 test_malloc_4d[i][j][k][l] = i*4*2*5 + j*2*5 + k*5 + l;
175 REF[i][j][k][l] = i*4*2*5 + j*2*5 + k*5 + l;
182 memcpy(CPY,
FLATTEN4D(test_malloc_4d), 3*4*2*5*
sizeof(
int));
187 TEST_ASSERT_TRUE(CPY[i][j][k][l] == REF[i][j][k][l]);
190 free(test_malloc_4d);
195 int REF[2][4][3][5][2];
196 int CPY[2][4][3][5][2];
197 int***** test_malloc_5d;
198 test_malloc_5d = (
int*****)
malloc5d(2, 4, 3, 5, 2,
sizeof(
int));
206 test_malloc_5d[i][j][k][l][p] = i*4*3*5*2 + j*3*5*2 + k*5*2 + l*2 + p;
207 REF[i][j][k][l][p] = i*4*3*5*2 + j*3*5*2 + k*5*2 + l*2 + p;
215 memcpy(CPY,
FLATTEN5D(test_malloc_5d), 2*4*3*5*2*
sizeof(
int));
221 TEST_ASSERT_TRUE(CPY[i][j][k][l][p] == REF[i][j][k][l][p]);
224 free(test_malloc_5d);
229 int REF[2][3][2][4][2][3];
230 int CPY[2][3][2][4][2][3];
231 int****** test_malloc_6d;
232 test_malloc_6d = (
int******)
malloc6d(2, 3, 2, 4, 2, 3,
sizeof(
int));
241 test_malloc_6d[i][j][k][l][p][o] = i*3*2*4*2*3 + j*2*4*2*3 + k*4*2*3 + l*2*3 + p*3 + o;
242 REF[i][j][k][l][p][o] = i*3*2*4*2*3 + j*2*4*2*3 + k*4*2*3 + l*2*3 + p*3 + o;
251 memcpy(CPY,
FLATTEN6D(test_malloc_6d), 2*3*2*4*2*3*
sizeof(
int));
258 TEST_ASSERT_TRUE(CPY[i][j][k][l][p][o] == REF[i][j][k][l][p][o]);
261 free(test_malloc_6d);
int afSTFT_getNBands(void *const hSTFT)
Returns number of frequency bands.
void afSTFT_clearBuffers(void *const hSTFT)
Flushes time-domain buffers with zeros.
void afSTFT_create(void **const phSTFT, int nCHin, int nCHout, int hopsize, int lowDelayMode, int hybridmode, AFSTFT_FDDATA_FORMAT format)
Creates an instance of afSTFT.
int afSTFT_getProcDelay(void *const hSTFT)
Returns current processing delay, in samples.
void afSTFT_forward(void *const hSTFT, float **dataTD, int framesize, float_complex ***dataFD)
Performs forward afSTFT transform.
void afSTFT_getCentreFreqs(void *const hSTFT, float fs, int nBands, float *freqVector)
Returns current frequency vector.
void afSTFT_destroy(void **const phSTFT)
Destroys an instance of afSTFT.
void afSTFT_channelChange(void *const hSTFT, int new_nCHin, int new_nCHout)
Re-allocates memory to support a change in the number of input/output channels.
void afSTFT_backward(void *const hSTFT, float_complex ***dataFD, int framesize, float **dataTD)
Performs backward afSTFT transform.
@ AFSTFT_BANDS_CH_TIME
nBands x nChannels x nTimeHops
void rand_m1_1(float *vector, int length)
Generates random numbers between -1 and 1 and stores them in the input vector.
void ** malloc2d(size_t dim1, size_t dim2, size_t data_size)
2-D malloc (contiguously allocated, so use free() as usual to deallocate)
void * malloc1d(size_t dim1_data_size)
1-D malloc (same as malloc, but with error checking)
void ****** malloc6d(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t dim6, size_t data_size)
6-D malloc (contiguously allocated, so use free() as usual to deallocate)
void *** malloc3d(size_t dim1, size_t dim2, size_t dim3, size_t data_size)
3-D malloc (contiguously allocated, so use free() as usual to deallocate)
void **** malloc4d(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t data_size)
4-D malloc (contiguously allocated, so use free() as usual to deallocate)
void ** realloc2d_r(void **ptr, size_t new_dim1, size_t new_dim2, size_t prev_dim1, size_t prev_dim2, size_t data_size)
2-D realloc which does retain previous data order
void ***** malloc5d(size_t dim1, size_t dim2, size_t dim3, size_t dim4, size_t dim5, size_t data_size)
5-D malloc (contiguously allocated, so use free() as usual to deallocate)
#define FLATTEN6D(A)
Use this macro when passing a 6-D dynamic multi-dimensional array to memset, memcpy or any other func...
#define FLATTEN4D(A)
Use this macro when passing a 4-D dynamic multi-dimensional array to memset, memcpy or any other func...
#define FLATTEN2D(A)
Use this macro when passing a 2-D dynamic multi-dimensional array to memset, memcpy or any other func...
#define FLATTEN5D(A)
Use this macro when passing a 5-D dynamic multi-dimensional array to memset, memcpy or any other func...
Unit test program for the Spatial_Audio_Framework.
void test__realloc2d_r(void)
Testing the realloc2d_r() function (reallocating 2-D array, while retaining the previous data order; ...
void test__malloc6d(void)
Testing that malloc6d() works, and is truely contiguously allocated.
void test__afSTFT(void)
Testing the alias-free STFT filterbank (near)-perfect reconstruction performance.
void test__malloc5d(void)
Testing that malloc5d() works, and is truely contiguously allocated.
void test__malloc4d(void)
Testing that malloc4d() works, and is truely contiguously allocated.