diff options
Diffstat (limited to 'tests/test5/compute.c')
-rw-r--r-- | tests/test5/compute.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/tests/test5/compute.c b/tests/test5/compute.c index 2658904..3a94efe 100644 --- a/tests/test5/compute.c +++ b/tests/test5/compute.c @@ -9,7 +9,7 @@ gfloat compute_level(const float *data, size_t nsamples, size_t nchan) { double rate=44100; //TODO dynamique size_t i; - float input[MAX_SAMPLES], output[MAX_SAMPLES]; + float input[MAX_SAMPLES], output[128]; float level; if (nsamples >= MAX_SAMPLES) { @@ -33,25 +33,23 @@ gfloat compute_level(const float *data, size_t nsamples, size_t nchan) { // printf("\n"); compute_spectrom(input, nsamples, rate, output); - - level=0; - for (i=0;i<nsamples;i++) { + level=0.f; + for (i=1;i<128;i++) { level+=output[i]; - //printf("\r%f ", output[i]); - //fflush(stdout); } - //printf("\n"); - - return level/nsamples; + level/=127.f; + //printf("%f\n", level); + return level; } // From Audacity void compute_spectrom(float * data, int width, double rate, float *output) { int i; - float processed[256]={ 0.0f }; - float in[256]; - float out[256]; + float processed[256]={0.0f}; +//TODO : remove init here + float in[256]={0.0f}; + float out[256]={0.0f}; int start = 0; int windows = 0; @@ -62,7 +60,6 @@ void compute_spectrom(float * data, int width, double rate, float *output) { // Hanning for (i=0; i<256; i++) in[i] *= 0.50 - 0.50 * cos(2 * M_PI * i / (256 - 1)); - break; PowerSpectrum(in, out); @@ -111,7 +108,8 @@ void PowerSpectrum(float *In, float *Out) for (i = 0; i < 128; i++) { tmpReal[i] = In[2 * i]; - tmpImag[i] = In[2 * i + 1]; + tmpImag[i] = In[2 * i + 1]; //FIXME : WTFFFF ? + tmpImag[i]=0; } FFT(128, 0, tmpReal, tmpImag, RealOut, ImagOut); |