summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test5/TOREAD2
-rw-r--r--tests/test5/capture.c2
-rw-r--r--tests/test5/compute.c26
-rw-r--r--tests/test5/test5.c4
-rw-r--r--tests/test5/win_main.c2
-rwxr-xr-xtests/test6/compil.sh1
-rw-r--r--tests/test6/octave1.txt16
-rw-r--r--tests/test6/test6.c36
8 files changed, 71 insertions, 18 deletions
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<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);
diff --git a/tests/test5/test5.c b/tests/test5/test5.c
index 809aaa6..9eadb65 100644
--- a/tests/test5/test5.c
+++ b/tests/test5/test5.c
@@ -34,7 +34,7 @@ int main (int argc, char **argv) {
printf("debug : main my_process==%p\n", my_process);
printf("debug : main (void *)my_process==%p\n", (void *)my_process);
pthread_create (&audio_analyzer, (void *)NULL, (void *)audio_thread, (void *)my_process);
- g_timeout_add (100, win_main_update_vumeters, (gpointer)vals_for_vumeters);
+ g_timeout_add (25, win_main_update_vumeters, (gpointer)vals_for_vumeters);
gtk_main ();
gdk_threads_leave();
@@ -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=sound_level*65535;
+ *audio_vumeter_val=((int)sound_level*10.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 f44c940..66b2c6b 100644
--- a/tests/test5/win_main.c
+++ b/tests/test5/win_main.c
@@ -23,6 +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_box_pack_start(GTK_BOX(hbox1), vumeter_sound, FALSE, FALSE, 0);
vumeter_h = gtk_vu_meter_new (TRUE);
@@ -60,6 +61,7 @@ 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
new file mode 100755
index 0000000..4ac3ca3
--- /dev/null
+++ b/tests/test6/compil.sh
@@ -0,0 +1 @@
+gcc -Wall -g -o test6 test6.c -lm
diff --git a/tests/test6/octave1.txt b/tests/test6/octave1.txt
new file mode 100644
index 0000000..616628f
--- /dev/null
+++ b/tests/test6/octave1.txt
@@ -0,0 +1,16 @@
+function s=son_pur(f,v,d,sr)
+ n = 1:(d*sr);
+ s = v*sin(2.*pi.*f*n/sr);
+endfunction
+
+sr=8000;
+f=440;
+d=1;
+v=0.9;
+
+s=son_pur(f,v,d,sr);
+[y,c]=stft(s,128);
+c
+s2=synthesis(y,c);
+sound(s2);
+
diff --git a/tests/test6/test6.c b/tests/test6/test6.c
new file mode 100644
index 0000000..fc99598
--- /dev/null
+++ b/tests/test6/test6.c
@@ -0,0 +1,36 @@
+#include <math.h>
+#include <stdio.h>
+
+//#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;
+}
+