From 22079050f23cd4e019fc7dc98c25d5e06b1f8ead Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Fri, 8 Jun 2012 22:49:38 +0000 Subject: Bon, la détection de volume commence à ressembler à qque chose mais les valeurs semblent pas forcément bonnes. Le filtre A n'est pas appliqué encore. Dans le test6, quelques essais de maths... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2012-violon-leds/trunk@14 6be1fa4d-33ac-4c33-becc-79fcb3794bb6 --- tests/test5/TOREAD | 2 ++ tests/test5/capture.c | 2 -- tests/test5/compute.c | 26 ++++++++++++-------------- tests/test5/test5.c | 4 ++-- tests/test5/win_main.c | 2 ++ tests/test6/compil.sh | 1 + tests/test6/octave1.txt | 16 ++++++++++++++++ tests/test6/test6.c | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 71 insertions(+), 18 deletions(-) create mode 100755 tests/test6/compil.sh create mode 100644 tests/test6/octave1.txt create mode 100644 tests/test6/test6.c diff --git a/tests/test5/TOREAD b/tests/test5/TOREAD index e84ab7e..acb1aca 100644 --- a/tests/test5/TOREAD +++ b/tests/test5/TOREAD @@ -1,2 +1,4 @@ http://freedesktop.org/software/pulseaudio/doxygen/async.html#overv_sec +http://www.developpez.net/forums/d467150/autres-langages/algorithmes/fft-role/ + diff --git a/tests/test5/capture.c b/tests/test5/capture.c index 00d9c54..26d345c 100644 --- a/tests/test5/capture.c +++ b/tests/test5/capture.c @@ -195,8 +195,6 @@ void stream_read_callback(pa_stream *s, size_t nbytes, void *userdata) { //printf("debug : before call capture_sound_level_cb==%p\n", capture_sound_level_cb); my_process((float *)p,nbytes/sizeof(float), pa_stream_get_sample_spec(s)->channels); -// (*capture_sound_level_cb)(compute_level(p,nbytes), NULL); - //printf("debug : after call capture_sound_level_cb==%p\n", capture_sound_level_cb); pa_stream_drop(s); 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 +#include + +//#if 1 //(UGLY_IEEE754_FLOAT32_HACK :-) +/* +static inline float todB_a(const float *x){ + return (float)((*(int *)x)&0x7fffffff) * 7.17711438e-7f -764.6161886f; +} +*/ +static inline float todB_a(const float *x){ + union { + //int32_t i; + int i; + float f; + } ix; + ix.f = *x; + ix.i = ix.i&0x7fffffff; + return (float)(ix.i * 7.17711438e-7f -764.6161886f); +} +//#else + +static inline float todB_a2(const float *x){ + return (*(x)==0?-400.f:logf(*(x)**(x))*4.34294480f); +} + +//#endif + +int main() { + float f; + + for(f=1.f;f<100000000.f;f*=1.2f) + printf("%f\t%f\n", todB_a(&f), todB_a2(&f)); + + return 0; +} + -- cgit v1.2.3