# HG changeset patch # User Tomasz Mon # Date 1212236257 -7200 # Node ID ed0ad7b373d3d42e904ab6c7bb0a4d3d29748eb5 # Parent a1431a900f2807522b582077a135f63b8fbc5f71 make vis working diff -r a1431a900f28 -r ed0ad7b373d3 src/skins/ui_main_evlisteners.c --- a/src/skins/ui_main_evlisteners.c Fri May 30 21:02:12 2008 +0200 +++ b/src/skins/ui_main_evlisteners.c Sat May 31 14:17:37 2008 +0200 @@ -30,6 +30,7 @@ #include "visualization.h" #endif #include +#include #if 0 #include "ui_credits.h" #endif @@ -220,10 +221,164 @@ static void ui_main_evlistener_visualization_timeout(gpointer hook_data, gpointer user_data) { + if (hook_data == NULL) { + if (config.player_shaded && config.player_visible) + ui_svis_timeout_func(mainwin_svis, NULL); + else + ui_vis_timeout_func(mainwin_vis, NULL); + return; + } + + VisNode *vis = (VisNode*) hook_data; + + guint8 intern_vis_data[512]; + gint16 mono_freq[2][256]; + gboolean mono_freq_calced = FALSE; + gint16 mono_pcm[2][512], stereo_pcm[2][512]; + gboolean mono_pcm_calced = FALSE, stereo_pcm_calced = FALSE; + gint i; + + if (config.vis_type == VIS_OFF) + return; + + if (config.vis_type == VIS_ANALYZER) { + /* Spectrum analyzer */ + /* 76 values */ + const gint long_xscale[] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, + 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, + 52, 53, 54, 55, 56, 57, 58, 61, 66, 71, 76, 81, 87, 93, + 100, 107, + 114, 122, 131, 140, 150, 161, 172, 184, 255 + }; + /* 20 values */ + const int short_xscale[] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 15, 20, 27, + 36, 47, 62, 82, 107, 141, 184, 255 + }; + const double y_scale = 3.60673760222; /* 20.0 / log(256) */ + const int *xscale; + gint j, y, max; + + if (!mono_freq_calced) + aud_calc_mono_freq(mono_freq, vis->data, vis->nch); + + memset(intern_vis_data, 0, 75); + + if (config.analyzer_type == ANALYZER_BARS) { + if (config.player_shaded) { + max = 13; + } + else { + max = 19; + } + xscale = short_xscale; + } + else { + if (config.player_shaded) { + max = 37; + } + else { + max = 75; + } + xscale = long_xscale; + } + + for (i = 0; i < max; i++) { + for (j = xscale[i], y = 0; j < xscale[i + 1]; j++) { + if (mono_freq[0][j] > y) + y = mono_freq[0][j]; + } + y >>= 7; + if (y != 0) { + intern_vis_data[i] = log(y) * y_scale; + if (intern_vis_data[i] > 15) + intern_vis_data[i] = 15; + } + else + intern_vis_data[i] = 0; + } + } + else if(config.vis_type == VIS_VOICEPRINT){ + if (config.player_shaded && config.player_visible) { + /* VU */ + gint vu, val; + + if (!stereo_pcm_calced) + aud_calc_stereo_pcm(stereo_pcm, vis->data, vis->nch); + vu = 0; + for (i = 0; i < 512; i++) { + val = abs(stereo_pcm[0][i]); + if (val > vu) + vu = val; + } + intern_vis_data[0] = (vu * 37) >> 15; + if (intern_vis_data[0] > 37) + intern_vis_data[0] = 37; + if (vis->nch == 2) { + vu = 0; + for (i = 0; i < 512; i++) { + val = abs(stereo_pcm[1][i]); + if (val > vu) + vu = val; + } + intern_vis_data[1] = (vu * 37) >> 15; + if (intern_vis_data[1] > 37) + intern_vis_data[1] = 37; + } + else + intern_vis_data[1] = intern_vis_data[0]; + } + else { /*Voiceprint*/ + if (!mono_freq_calced) + aud_calc_mono_freq(mono_freq, vis->data, vis->nch); + memset(intern_vis_data, 0, 256); + + /* For the values [0-16] we use the frequency that's 3/2 as much. + If we assume the 512 values calculated by calc_mono_freq to + cover 0-22kHz linearly we get a range of + [0-16] * 3/2 * 22000/512 = [0-1,031] Hz. + Most stuff above that is harmonics and we want to utilize the + 16 samples we have to the max[tm] + */ + for (i = 0; i < 50 ; i+=3){ + intern_vis_data[i/3] += (mono_freq[0][i/2] >> 5); + + /*Boost frequencies above 257Hz a little*/ + //if(i > 4 * 3) + // intern_vis_data[i/3] += 8; + } + } + } + else { /* (config.vis_type == VIS_SCOPE) */ + + /* Oscilloscope */ + gint pos, step; + + if (!mono_pcm_calced) + aud_calc_mono_pcm(mono_pcm, vis->data, vis->nch); + + step = (vis->length << 8) / 74; + for (i = 0, pos = 0; i < 75; i++, pos += step) { + intern_vis_data[i] = ((mono_pcm[0][pos >> 8]) >> 12) + 7; + if (intern_vis_data[i] == 255) + intern_vis_data[i] = 0; + else if (intern_vis_data[i] > 12) + intern_vis_data[i] = 12; + /* Do not see the point of that? (comparison always false) -larne. + if (intern_vis_data[i] < 0) + intern_vis_data[i] = 0; */ + } + } + if (config.player_shaded && config.player_visible) - ui_svis_timeout_func(mainwin_svis, hook_data); + ui_svis_timeout_func(mainwin_svis, intern_vis_data); else - ui_vis_timeout_func(mainwin_vis, hook_data); + ui_vis_timeout_func(mainwin_vis, intern_vis_data); } static void diff -r a1431a900f28 -r ed0ad7b373d3 src/skins/ui_svis.c --- a/src/skins/ui_svis.c Fri May 30 21:02:12 2008 +0200 +++ b/src/skins/ui_svis.c Sat May 31 14:17:37 2008 +0200 @@ -486,8 +486,9 @@ } void ui_svis_clear_data(GtkWidget *widget) { + g_return_if_fail(UI_IS_SVIS(widget)); + gint i; - UiSVis *svis = UI_SVIS (widget); for (i = 0; i < 75; i++) { @@ -496,6 +497,8 @@ } void ui_svis_timeout_func(GtkWidget *widget, guchar * data) { + g_return_if_fail(UI_IS_SVIS(widget)); + UiSVis *svis = UI_SVIS (widget); static GTimer *timer = NULL; gulong micros = 9999999; diff -r a1431a900f28 -r ed0ad7b373d3 src/skins/ui_vis.c --- a/src/skins/ui_vis.c Fri May 30 21:02:12 2008 +0200 +++ b/src/skins/ui_vis.c Sat May 31 14:17:37 2008 +0200 @@ -631,6 +631,8 @@ } void ui_vis_clear_data(GtkWidget *widget) { + g_return_if_fail(UI_IS_VIS(widget)); + gint i; UiVis *vis = UI_VIS (widget); @@ -642,6 +644,8 @@ } void ui_vis_timeout_func(GtkWidget *widget, guchar * data) { + g_return_if_fail(UI_IS_VIS(widget)); + UiVis *vis = UI_VIS (widget); static GTimer *timer = NULL; gulong micros = 9999999;