diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2012-06-17 16:18:53 +0000 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2012-06-17 16:18:53 +0000 |
commit | c8e2aaf6999da491d6ea8dab2bc99752fa94b6d4 (patch) | |
tree | 49ef9be6a6ce6044aa2780cc52d7292f2836ab61 /src | |
parent | 71dad10fdabd700f036893c725f02c9b4b4ac49b (diff) | |
download | 2012-violon-leds-c8e2aaf6999da491d6ea8dab2bc99752fa94b6d4.tar.gz 2012-violon-leds-c8e2aaf6999da491d6ea8dab2bc99752fa94b6d4.tar.bz2 2012-violon-leds-c8e2aaf6999da491d6ea8dab2bc99752fa94b6d4.zip |
Ajout d'une fonction pour linéariser un peu la réponse du projecteur (illuminate.c)
Ajout d'une moyenne sur 8 valeurs pour la luminosité (mais on garde la valeur instantanée pour altérer la couleur)
Correction du vumeter qui s'initialisais à 1px par 1px au lancement de l'appli.
Avec le lud-msi, le projo à Ju et les sons enregistrés par Laurent, ça pète pas mal :P
git-svn-id: file:///var/svn/2012-violon-leds/trunk@24 6be1fa4d-33ac-4c33-becc-79fcb3794bb6
Diffstat (limited to 'src')
-rw-r--r-- | src/compute.c | 24 | ||||
-rw-r--r-- | src/gtkvumeter.c | 42 | ||||
-rw-r--r-- | src/illuminate.c | 17 | ||||
-rw-r--r-- | src/music2light.c | 2 |
4 files changed, 78 insertions, 7 deletions
diff --git a/src/compute.c b/src/compute.c index 54d6929..ce0575f 100644 --- a/src/compute.c +++ b/src/compute.c @@ -100,20 +100,38 @@ void compute_spectrum(float *data, int width, float output[PSHalf]) { void audio2hsv_1(float audio_level, float *light_h, float *light_s, float *light_v) { static float hue=0; + static float value_decay[8]={0.f}; + static int decay_idx=0; - float level_norm=(38.f+audio_level)/30.f; + int i; + float level_norm, temp; + // Testé avec micro externe sur lud-msi + //[-38dB;0dB] -> [0.0;1.0] + level_norm=(38.f+audio_level)/38.f; if (level_norm<0.0f) level_norm=0.f; //if (level_norm<0.1f) level_norm=0.f; //FIXME : ici cache misere pour le tremblement sur plancher bruit if (level_norm>1.f) level_norm=1.f; + + if (decay_idx>=8) decay_idx=0; + value_decay[decay_idx++]=level_norm; + hue=(hue+0.0002f); if (hue>1.f) hue-=1.f; // printf("%+3.1f %+1.3f\n", audio_level, level_norm); // Dummy code - *light_h=hue; +// *light_h=hue; + temp=hue+level_norm/3.f; + *light_h=temp-(int)temp; // Fractionnal part + *light_s=1.f; - *light_v=level_norm; + +// *light_v=level_norm; + temp=0.f; + for(i=0;i<8;i++) temp+=value_decay[i]; + temp/=8.f; + *light_v=temp; } diff --git a/src/gtkvumeter.c b/src/gtkvumeter.c index d57cc62..34a2038 100644 --- a/src/gtkvumeter.c +++ b/src/gtkvumeter.c @@ -1,3 +1,11 @@ +/* + Adapted From GtkVuMeter by Todd Goyen + Copyright 2003 Todd Goyen + wettoad@knighthoodofbuh.or + + Improved rendering performance (no individual drawline calls) + +*/ #include <string.h> #include "gtkvumeter.h" @@ -18,10 +26,12 @@ static void free_drawbuf(guchar *pixels, gpointer data); static void gtk_vu_meter_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_vu_meter_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static gint gtk_vu_meter_sound_level_to_draw_level (GtkVuMeter *vumeter); +static void gtk_vu_meter_realize (GtkWidget *widget); static void gtk_vu_meter_class_init (GtkVuMeterClass *class) { GtkWidgetClass *widget_class; widget_class = GTK_WIDGET_CLASS (class); + widget_class->realize = gtk_vu_meter_realize; widget_class->expose_event = gtk_vu_meter_expose; widget_class->size_request = gtk_vu_meter_size_request; widget_class->size_allocate = gtk_vu_meter_size_allocate; @@ -33,6 +43,38 @@ static void gtk_vu_meter_init (GtkVuMeter *vumeter) { gtk_vu_meter_setup_colors(vumeter); } +static void gtk_vu_meter_realize (GtkWidget *widget) +{ + GtkVuMeter *vumeter; + GdkWindowAttr attributes; + gint attributes_mask; + + g_return_if_fail (widget != NULL); + g_return_if_fail (GTK_IS_VU_METER (widget)); + + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + vumeter = GTK_VU_METER (widget); + + attributes.x = widget->allocation.x; + attributes.y = widget->allocation.y; + attributes.width = widget->allocation.width; + attributes.height = widget->allocation.height; + attributes.wclass = GDK_INPUT_OUTPUT; + attributes.window_type = GDK_WINDOW_CHILD; + attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; + attributes.visual = gtk_widget_get_visual (widget); + attributes.colormap = gtk_widget_get_colormap (widget); + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; + widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask); + + widget->style = gtk_style_attach (widget->style, widget->window); + + gdk_window_set_user_data (widget->window, widget); + gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); + + gtk_vu_meter_setup_colors (vumeter); +} + void gtk_vu_meter_set_gradient (GtkVuMeter *vumeter, gint f_gradient_key_count, GdkColor *f_gradient_keys, gint b_gradient_key_count, GdkColor *b_gradient_keys) { //XXX : memdup is a bad idea ? GdkColor *fgk = g_memdup(f_gradient_keys, f_gradient_key_count*sizeof(GdkColor)); diff --git a/src/illuminate.c b/src/illuminate.c index a0f146d..92c8fac 100644 --- a/src/illuminate.c +++ b/src/illuminate.c @@ -3,6 +3,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <math.h> #include "illuminate.h" // FTDI Vendor ID @@ -84,12 +85,22 @@ int dmx_init() { return 0; } +inline int projector_correction(int in) { + //int out=powf(((in-108.f)/162.f),3.f)*256.f+80.f; + int out=in*0.25f+0.75*(powf(((in-100.f)/162.f),3.f)*256.f+48.f); + if (out>255) out=255; + if (out<0) out=0; + return out; +} + int dmx_write_rgb(int r, int g, int b) { if (! ftdi.usb_dev ) return -1; - universe[2]=r; - universe[3]=g; - universe[4]=b; + universe[2]=projector_correction(r); + universe[3]=projector_correction(g); + universe[4]=projector_correction(b); + +// printf("rgb %3i %3i %3i dmx %3i %3i %3i\n", r,g,b, universe[2], universe[3], universe[4]); return dmx_universe_write(&ftdi, universe, DMX_CHANNELS); } diff --git a/src/music2light.c b/src/music2light.c index b82525b..7d29b56 100644 --- a/src/music2light.c +++ b/src/music2light.c @@ -57,7 +57,7 @@ void my_process(float *data, size_t nsamples, size_t nchan) { //FIXME : rate should came from PulseAudio sound_level=compute_level(data, nsamples, 44100); -// printf("sound_level==%f\n", sound_level); +// printf("sound_level==%+8f nsamples==%8i\n", sound_level, nsamples); // Update sound vumeter value (refreshed asynchronously) *audio_vumeter_val=(int)sound_level; |