2929#include <stdlib.h>
3030#include <math.h>
3131#include <string.h>
32+ #include "mini_kfft.c"
3233
3334#define MAX (a ,b ) ((a)>(b) ? (a) : (b))
3435#define OPUS_PI (3.14159265F)
@@ -56,6 +57,11 @@ static void *opus_realloc(void *_ptr,size_t _size){
5657#define FORMAT_S24_LE 1
5758#define FORMAT_F32_LE 2
5859
60+ #define NBANDS (28)
61+ #define NFREQS (240*2)
62+ #define TEST_WIN_SIZE (480*2)
63+ #define TEST_WIN_STEP (120*2)
64+
5965static const int format_size [3 ] = {2 , 3 , 4 };
6066typedef union {
6167 int i ;
@@ -125,55 +131,38 @@ static size_t read_pcm(float **_samples,FILE *_fin,int _nchannels, int format){
125131static void band_energy (float * _out ,float * _ps ,const int * _bands ,int _nbands ,
126132 const float * _in ,int _nchannels ,size_t _nframes ,int _window_sz ,
127133 int _step ,int _downsample ){
128- float * window ;
129- float * x ;
130- float * c ;
131- float * s ;
134+ float window [TEST_WIN_SIZE ];
135+ float x [TEST_WIN_SIZE ];
132136 size_t xi ;
133137 int xj ;
134138 int ps_sz ;
135- window = (float * )opus_malloc ((3 + _nchannels )* _window_sz * sizeof (* window ));
136- c = window + _window_sz ;
137- s = c + _window_sz ;
138- x = s + _window_sz ;
139+ kiss_fft_cpx X [2 ][NFREQS + 1 ];
140+ kiss_fftr_cfg kfft ;
139141 ps_sz = _window_sz /2 ;
140142 /* Blackman-Harris window. */
141143 for (xj = 0 ;xj < _window_sz ;xj ++ ){
142144 double n = (xj + .5 )/_window_sz ;
143145 window [xj ]= 0.35875 - 0.48829 * cos (2 * OPUS_PI * n ) + 0.14128 * cos (4 * OPUS_PI * n ) - 0.01168 * cos (6 * OPUS_PI * n );
144146 }
145- for (xj = 0 ;xj < _window_sz ;xj ++ ){
146- c [xj ]= OPUS_COSF ((2 * OPUS_PI /_window_sz )* xj );
147- }
148- for (xj = 0 ;xj < _window_sz ;xj ++ ){
149- s [xj ]= OPUS_SINF ((2 * OPUS_PI /_window_sz )* xj );
150- }
147+ kfft = mini_kiss_fftr_alloc (_window_sz , 0 , NULL , NULL );
151148 for (xi = 0 ;xi < _nframes ;xi ++ ){
152149 int ci ;
153150 int xk ;
154151 int bi ;
155152 for (ci = 0 ;ci < _nchannels ;ci ++ ){
156153 for (xk = 0 ;xk < _window_sz ;xk ++ ){
157- x [ci * _window_sz + xk ]= window [xk ]* _in [(xi * _step + xk )* _nchannels + ci ];
154+ x [xk ]= window [xk ]* _in [(xi * _step + xk )* _nchannels + ci ];
158155 }
156+ mini_kiss_fftr (kfft , x , X [ci ]);
159157 }
160158 for (bi = xj = 0 ;bi < _nbands ;bi ++ ){
161159 float p [2 ]= {0 };
162160 for (;xj < _bands [bi + 1 ];xj ++ ){
163161 for (ci = 0 ;ci < _nchannels ;ci ++ ){
164162 float re ;
165163 float im ;
166- int ti ;
167- ti = 0 ;
168- re = im = 0 ;
169- for (xk = 0 ;xk < _window_sz ;xk ++ ){
170- re += c [ti ]* x [ci * _window_sz + xk ];
171- im -= s [ti ]* x [ci * _window_sz + xk ];
172- ti += xj ;
173- if (ti >=_window_sz )ti -= _window_sz ;
174- }
175- re *=_downsample ;
176- im *=_downsample ;
164+ re = X [ci ][xj ].r * _downsample ;
165+ im = X [ci ][xj ].i * _downsample ;
177166 _ps [(xi * ps_sz + xj )* _nchannels + ci ]= re * re + im * im + .1 ;
178167 p [ci ]+= _ps [(xi * ps_sz + xj )* _nchannels + ci ];
179168 }
@@ -186,20 +175,16 @@ static void band_energy(float *_out,float *_ps,const int *_bands,int _nbands,
186175 }
187176 }
188177 }
189- free (window );
178+ free (kfft );
190179}
191180
192- #define NBANDS (28)
193- #define NFREQS (240*2)
194181
195182/*Bands on which we compute the pseudo-NMR (Bark-derived
196183 CELT bands).*/
197184static const int BANDS [NBANDS + 1 ]= {
198185 0 ,2 ,4 ,6 ,8 ,10 ,12 ,14 ,16 ,20 ,24 ,28 ,32 ,40 ,48 ,56 ,68 ,80 ,96 ,120 ,156 ,200 , 240 ,280 ,320 ,360 ,400 ,440 ,480
199186};
200187
201- #define TEST_WIN_SIZE (480*2)
202- #define TEST_WIN_STEP (120*2)
203188
204189void usage (const char * _argv0 ) {
205190 fprintf (stderr ,"Usage: %s [-s] [-48k] [-s16|-s24|-f32] [-r rate2] <file1.sw> <file2.sw>\n" ,
0 commit comments