changeset 4596:a77d02342ee1

change visualization timeout; export calc_stereo_pcm, calc_mono_pcm and calc_mono_freq to PAPI
author Tomasz Mon <desowin@gmail.com>
date Sat, 31 May 2008 14:17:15 +0200
parents d69b2bcea170
children aec8fc12e075
files src/audacious/input.c src/audacious/input.h src/audacious/plugin.h src/audacious/pluginenum.c src/audacious/ui_main_evlisteners.c src/audacious/ui_svis.c src/audacious/ui_vis.c src/audacious/visualization.c src/audacious/visualization.h
diffstat 9 files changed, 195 insertions(+), 164 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/input.c	Fri May 30 16:05:03 2008 +0200
+++ b/src/audacious/input.c	Sat May 31 14:17:15 2008 +0200
@@ -59,16 +59,6 @@
 
 G_LOCK_DEFINE_STATIC(vis_mutex);
 
-struct _VisNode {
-    gint time;
-    gint nch;
-    gint length;                /* number of samples per channel */
-    gint16 data[2][512];
-};
-
-typedef struct _VisNode VisNode;
-
-
 InputPluginData ip_data = {
     NULL,
     NULL,
@@ -770,10 +760,11 @@
 
     if (found) {
         vis_send_data(vis->data, vis->nch, vis->length);
+        hook_call("visualization timeout", vis);
         g_free(vis);
     }
     else
-        vis_send_data(NULL, 0, 0);
+        hook_call("visualization timeout", NULL);
 }
 
 /* FIXME: move this somewhere else */
--- a/src/audacious/input.h	Fri May 30 16:05:03 2008 +0200
+++ b/src/audacious/input.h	Sat May 31 14:17:15 2008 +0200
@@ -39,6 +39,15 @@
     GMutex *playback_mutex;
 };
 
+struct _VisNode {
+    gint time;
+    gint nch;
+    gint length;                /* number of samples per channel */
+    gint16 data[2][512];
+};
+
+typedef struct _VisNode VisNode;
+
 GList *get_input_list(void);
 InputPlayback *get_current_input_playback(void);
 void set_current_input_playback(InputPlayback * ip);
--- a/src/audacious/plugin.h	Fri May 30 16:05:03 2008 +0200
+++ b/src/audacious/plugin.h	Sat May 31 14:17:15 2008 +0200
@@ -645,6 +645,10 @@
 
     void (*event_queue)(const gchar *name, gpointer user_data);
 
+    void (*calc_mono_freq)(gint16 dest[2][256], gint16 src[2][512], gint nch);
+    void (*calc_mono_pcm)(gint16 dest[2][512], gint16 src[2][512], gint nch);
+    void (*calc_stereo_pcm)(gint16 dest[2][512], gint16 src[2][512], gint nch);
+
     /* VFS endianess helper functions */
     gboolean (*vfs_fget_le16)(guint16 *value, VFSFile *stream);
     gboolean (*vfs_fget_le32)(guint32 *value, VFSFile *stream);
@@ -998,6 +1002,10 @@
 
 #define aud_event_queue             _audvt->event_queue
 
+#define aud_calc_mono_freq          _audvt->calc_mono_freq
+#define aud_calc_mono_pcm           _audvt->calc_mono_pcm
+#define aud_calc_stereo_pcm         _audvt->calc_stereo_pcm
+
 #include "audacious/auddrct.h"
 
 /* for multi-file plugins :( */
--- a/src/audacious/pluginenum.c	Fri May 30 16:05:03 2008 +0200
+++ b/src/audacious/pluginenum.c	Sat May 31 14:17:15 2008 +0200
@@ -396,6 +396,9 @@
 
     .event_queue = event_queue,
 
+    .calc_mono_freq = calc_mono_freq,
+    .calc_mono_pcm = calc_mono_pcm,
+    .calc_stereo_pcm = calc_stereo_pcm,
 };
 
 /*****************************************************************/
--- a/src/audacious/ui_main_evlisteners.c	Fri May 30 16:05:03 2008 +0200
+++ b/src/audacious/ui_main_evlisteners.c	Sat May 31 14:17:15 2008 +0200
@@ -259,10 +259,165 @@
 static void
 ui_main_evlistener_visualization_timeout(gpointer hook_data, gpointer user_data)
 {
+    if (hook_data == NULL) {
+        if (cfg.player_shaded && cfg.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 (cfg.vis_type == VIS_OFF)
+        return;
+
+    if (cfg.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)
+                calc_mono_freq(mono_freq, vis->data, vis->nch);
+
+            memset(intern_vis_data, 0, 75);
+
+            if (cfg.analyzer_type == ANALYZER_BARS) {
+                if (cfg.player_shaded) {
+                    max = 13;
+                }
+                else {
+                    max = 19;
+                }
+                xscale = short_xscale;
+            }
+            else {
+                if (cfg.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(cfg.vis_type == VIS_VOICEPRINT){
+        if (cfg.player_shaded && cfg.player_visible) {
+            /* VU */
+            gint vu, val;
+
+            if (!stereo_pcm_calced)
+                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)
+                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 { /* (cfg.vis_type == VIS_SCOPE) */
+
+        /* Oscilloscope */
+        gint pos, step;
+
+        if (!mono_pcm_calced)
+            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 (cfg.player_shaded && cfg.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
--- a/src/audacious/ui_svis.c	Fri May 30 16:05:03 2008 +0200
+++ b/src/audacious/ui_svis.c	Sat May 31 14:17:15 2008 +0200
@@ -487,8 +487,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++) {
@@ -497,6 +498,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;
--- a/src/audacious/ui_vis.c	Fri May 30 16:05:03 2008 +0200
+++ b/src/audacious/ui_vis.c	Sat May 31 14:17:15 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;
--- a/src/audacious/visualization.c	Fri May 30 16:05:03 2008 +0200
+++ b/src/audacious/visualization.c	Sat May 31 14:17:15 2008 +0200
@@ -197,7 +197,7 @@
     g_strfreev(plugins);
 }
 
-static void
+void
 calc_stereo_pcm(gint16 dest[2][512], gint16 src[2][512], gint nch)
 {
     memcpy(dest[0], src[0], 512 * sizeof(gint16));
@@ -207,7 +207,7 @@
         memcpy(dest[1], src[1], 512 * sizeof(gint16));
 }
 
-static void
+void
 calc_mono_pcm(gint16 dest[2][512], gint16 src[2][512], gint nch)
 {
     gint i;
@@ -241,7 +241,7 @@
         dest[i] = ((gint) sqrt(tmp_out[i + 1])) >> 8;
 }
 
-static void
+void
 calc_mono_freq(gint16 dest[2][256], gint16 src[2][512], gint nch)
 {
     gint i;
@@ -260,7 +260,7 @@
     }
 }
 
-static void
+void
 calc_stereo_freq(gint16 dest[2][256], gint16 src[2][512], gint nch)
 {
     calc_freq(dest[0], src[0]);
@@ -280,14 +280,9 @@
     gboolean mono_freq_calced = FALSE, stereo_freq_calced = FALSE;
     gint16 mono_pcm[2][512], stereo_pcm[2][512];
     gboolean mono_pcm_calced = FALSE, stereo_pcm_calced = FALSE;
-    guint8 intern_vis_data[512];
-    gint i;
 
-    if (!pcm_data || nch < 1) {
-        if (cfg.vis_type != VIS_OFF)
-            hook_call("visualization timeout", NULL);
+    if (!pcm_data || nch < 1)
         return;
-    }
 
     while (node) {
         vp = node->data;
@@ -329,146 +324,6 @@
         }
         node = g_list_next(node);
     }
-
-    if (cfg.vis_type == VIS_OFF)
-        return;
-
-    if (cfg.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)
-                calc_mono_freq(mono_freq, pcm_data, nch);
-
-            memset(intern_vis_data, 0, 75);
-
-            if (cfg.analyzer_type == ANALYZER_BARS) {
-                if (cfg.player_shaded) {
-                    max = 13;
-                }
-                else {
-                    max = 19;
-                }
-                xscale = short_xscale;
-            }
-            else {
-                if (cfg.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(cfg.vis_type == VIS_VOICEPRINT){
-        if (cfg.player_shaded && cfg.player_visible) {
-            /* VU */
-            gint vu, val;
-
-            if (!stereo_pcm_calced)
-                calc_stereo_pcm(stereo_pcm, pcm_data, 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 (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)
-                calc_mono_freq(mono_freq, pcm_data, 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 { /* (cfg.vis_type == VIS_SCOPE) */
-
-        /* Oscilloscope */
-        gint pos, step;
-
-        if (!mono_pcm_calced)
-            calc_mono_pcm(mono_pcm, pcm_data, nch);
-
-        step = (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; */
-        }
-    }
-
-    hook_call("visualization timeout", intern_vis_data);
 }
 
 void
--- a/src/audacious/visualization.h	Fri May 30 16:05:03 2008 +0200
+++ b/src/audacious/visualization.h	Sat May 31 14:17:15 2008 +0200
@@ -45,6 +45,9 @@
 void vis_playback_stop(void);
 gchar *vis_stringify_enabled_list(void);
 void vis_enable_from_stringified_list(gchar * list);
+void calc_stereo_pcm(gint16 dest[2][512], gint16 src[2][512], gint nch);
+void calc_mono_pcm(gint16 dest[2][512], gint16 src[2][512], gint nch);
+void calc_mono_freq(gint16 dest[2][256], gint16 src[2][512], gint nch);
 void vis_send_data(gint16 pcm_data[2][512], gint nch, gint length);
 void vis_flow(FlowContext *context);