diff options
-rw-r--r-- | tests/test5/TOREAD | 2 | ||||
-rw-r--r-- | tests/test5/capture.c | 1 | ||||
-rw-r--r-- | tests/test5/compute.c | 52 | ||||
-rw-r--r-- | tests/test5/test5.c | 2 | ||||
-rw-r--r-- | tests/test5/win_main.c | 3 | ||||
-rwxr-xr-x | tests/test6/compil.sh | 1 | ||||
-rw-r--r-- | tests/test6/test6.c | 23 |
7 files changed, 57 insertions, 27 deletions
diff --git a/tests/test5/TOREAD b/tests/test5/TOREAD index b1abccf..c3acc33 100644 --- a/tests/test5/TOREAD +++ b/tests/test5/TOREAD @@ -5,3 +5,5 @@ http://www.developpez.net/forums/d467150/autres-langages/algorithmes/fft-role/ http://code.google.com/p/jivemodular/source/browse/trunk/apps/jive/src/model/plugins/meters/AudioSpecMeterEditor.cpp?r=67 http://en.wikipedia.org/wiki/Frequency_weighting +http://en.wikipedia.org/wiki/Root_mean_square#RMS_in_frequency_domain + diff --git a/tests/test5/capture.c b/tests/test5/capture.c index 26d345c..e8ca2fd 100644 --- a/tests/test5/capture.c +++ b/tests/test5/capture.c @@ -124,6 +124,7 @@ pa_stream *create_stream(pa_context *c, const pa_source_info *si) { .tlength=1024, .prebuf=-1, .minreq=-1, + // .minreq=256, //For FFT calculus .fragsize=512 }; diff --git a/tests/test5/compute.c b/tests/test5/compute.c index e8b03fc..d64f8c1 100644 --- a/tests/test5/compute.c +++ b/tests/test5/compute.c @@ -3,8 +3,9 @@ #include "fft.h" #include <math.h> +#define MIN_SAMPLES 256 #define MAX_SAMPLES 2048 -static inline float todB_a(const float *x); +//static inline float todB_a(const float *x); void compute_spectrum(float * data, int width, double rate, float *output); @@ -13,42 +14,49 @@ 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[128]; - float level; + float value; + int gain=20, range=80; if (nsamples >= MAX_SAMPLES) { printf("WARN : nsamples >= MAX_SAMPLES : %i >= %i\n", nsamples, MAX_SAMPLES); nsamples=MAX_SAMPLES; } -/* Just return the max peak - for (i=0;i<nsamples;i+=nchan) { - val=((float *)data)[i]; - //printf("val==%i\n", val); - if (val<0) val=-val; - if (level<val) level=val; + if (nsamples < MIN_SAMPLES) { + printf("WARN : nsamples < MIN_SAMPLES : %i >= %i\n", nsamples, MIN_SAMPLES); + for (i=0;i<MIN_SAMPLES;i++) { + if ( (i/nsamples)%2==1 ) + input[i]=data[i/**nchan*/]; + else + input[i]=data[nsamples-i-1]; + } + nsamples=MIN_SAMPLES; + } else { + for (i=0;i<nsamples;i++) { + input[i]=data[i/**nchan*/]; + } } -*/ - for (i=0;i<nsamples;i++) { - input[i]=data[i/**nchan*/]; -/* printf("\r%f ", input[i]); - fflush(stdout); -*/ - } -// printf("\n"); compute_spectrum(input, nsamples, rate, output); //printf("%f\n", output[0]); - level=0.f; + value=0.f; for (i=1;i<128;i++) { - level+=output[i]; + value+=output[i]; } - level/=127.f; - return level; + // Mean value + value/=127.f; + // 0.0 to 1.0 range + value=(value + gain + range) / (double)range; + value=MAX(0.f,value); + value=MIN(value,1.f); + +// printf("DEBUG: nsamples=%8i value==%f\n", nsamples, value); + return value; } - +/* static inline float todB_a(const float *x){ return (float)((*(int32_t *)x)&0x7fffffff) * 7.17711438e-7f -764.6161886f; } - +*/ // Adapted from Audacity void compute_spectrum(float * data, int width, double rate, float *output) { diff --git a/tests/test5/test5.c b/tests/test5/test5.c index 7bf6a88..a80bf75 100644 --- a/tests/test5/test5.c +++ b/tests/test5/test5.c @@ -49,7 +49,7 @@ void my_process(float *data, size_t nsamples, size_t nchan) { sound_level=compute_level(data, nsamples, nchan); // Update sound vumeter value (refreshed asynchronously) - *audio_vumeter_val=(int)(sound_level*10.f); + *audio_vumeter_val=(int)(sound_level*100.f); // Transfert Function audio2hsv_1(*audio_vumeter_val,light_h,light_s,light_v); diff --git a/tests/test5/win_main.c b/tests/test5/win_main.c index 66b2c6b..c36a1a0 100644 --- a/tests/test5/win_main.c +++ b/tests/test5/win_main.c @@ -23,7 +23,7 @@ GtkWidget *win_main_build() { //TODO : gtk_vumeter_set_min_max (GTK_VU_METER(vumeter), min, max); vumeter_sound = gtk_vu_meter_new (TRUE); - gtk_vu_meter_set_min_max(GTK_VU_METER(vumeter_sound), -600, 0); + gtk_vu_meter_set_min_max(GTK_VU_METER(vumeter_sound), 0, 100); gtk_box_pack_start(GTK_BOX(hbox1), vumeter_sound, FALSE, FALSE, 0); vumeter_h = gtk_vu_meter_new (TRUE); @@ -61,7 +61,6 @@ GtkWidget *win_main_build() { } gboolean win_main_update_vumeters(gpointer vals) { - printf("%i\n", ((gint*)vals)[0]); gtk_vu_meter_set_level(GTK_VU_METER(vumeter_sound), ((gint*)vals)[0]); gtk_vu_meter_set_level(GTK_VU_METER(vumeter_h), ((gint*)vals)[1]); gtk_vu_meter_set_level(GTK_VU_METER(vumeter_s), ((gint*)vals)[2]); diff --git a/tests/test6/compil.sh b/tests/test6/compil.sh index 4ac3ca3..2e49576 100755 --- a/tests/test6/compil.sh +++ b/tests/test6/compil.sh @@ -1 +1,2 @@ +#!/bin/bash -xe gcc -Wall -g -o test6 test6.c -lm diff --git a/tests/test6/test6.c b/tests/test6/test6.c index 3a78c0c..2cb7074 100644 --- a/tests/test6/test6.c +++ b/tests/test6/test6.c @@ -1,5 +1,6 @@ #include <math.h> #include <stdio.h> +#include <stdlib.h> //#if 1 //(UGLY_IEEE754_FLOAT32_HACK :-) /* @@ -24,8 +25,7 @@ static inline float todB_a2(const float *x){ } //#endif - -int main() { +void test_todb_a() { float f, dbav[32]={0.f}, dbaf[32]={0.f}; int i=0; for(f=1024000.f;f>1.f;f/=2.f) { @@ -36,6 +36,25 @@ int main() { for (i=0;i<32;i++) printf("f==%f\tv==%f\n", dbaf[i], dbav[i]); +} + +void dump_testfile() { + int i,n; + float f[256]; + FILE *fh=fopen("./test.raw", "r"); + if (fh==NULL) return; + while ( (n=fread(f, sizeof(float), 256, fh)) > 0 ) { + for(i=0;i<n;i++) { + printf("%+.3f\t", f[i]); + } + } + fclose(fh); +} + +int main() { + //test_todb_a(); + dump_testfile(); + return 0; } |