Mercurial > audlegacy-plugins
annotate src/spectrum/spectrum.c @ 2284:d19b53359b24
cleaned up the sndfile wav plugin, currently limiting it ONLY TO WAV
PLAYBACK. if somebody is more experienced with it and wants to restore
the other formats, go ahead (maybe change the name of the plugin too?).
author | mf0102 <0102@gmx.at> |
---|---|
date | Wed, 09 Jan 2008 15:41:22 +0100 |
parents | e4b077cebfac |
children | bd3a24b39058 |
rev | line source |
---|---|
147 | 1 /* Spectrum Analyzer Visualization Plugin for Audacious |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
2 * |
147 | 3 * Copyright (C) 2006 William Pitcock |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
4 * Copyright (C) 1998-2001 V�gv�lgyi Attila, Peter Alm, Mikael Alm, |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
5 * Olle Hallnas, Thomas Nilsson and 4Front Technologies |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
6 * |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
7 * This program is free software; you can redistribute it and/or modify |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
10 * (at your option) any later version. |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
11 * |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
15 * GNU General Public License for more details. |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
16 * |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
18 * along with this program; if not, write to the Free Software |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
20 */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
21 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
22 #include "config.h" |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
23 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
24 #include <gtk/gtk.h> |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
25 #include <math.h> |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
26 #include <audacious/plugin.h> |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
27 #include <audacious/util.h> |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
28 #include <audacious/i18n.h> |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
29 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
30 #include "logo.xpm" |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
31 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
32 /* WIDTH should be kept 256, this is the hardwired resolution of the |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
33 spectrum given by XMMS */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
34 #define WIDTH 256 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
35 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
36 /* HEIGHT can be modified at your pleasure */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
37 #define HEIGHT 128 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
38 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
39 /* Linearity of the amplitude scale (0.5 for linear, keep in [0.1, 0.9]) */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
40 #define d 0.33 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
41 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
42 /* Time factor of the band dinamics. 3 means that the coefficient of the |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
43 last value is half of the current one's. (see source) */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
44 #define tau 3 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
45 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
46 /* Factor used for the diffusion. 4 means that half of the height is |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
47 added to the neighbouring bars */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
48 #define dif 4 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
49 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
50 static GtkWidget *window = NULL,*area; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
51 static GdkPixmap *bg_pixmap = NULL, *draw_pixmap = NULL, *bar = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
52 static GdkGC *gc = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
53 static gint16 bar_heights[WIDTH]; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
54 /*static gint timeout_tag;*/ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
55 static gdouble scale, x00, y00; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
56 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
57 static void fsanalyzer_init(void); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
58 static void fsanalyzer_cleanup(void); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
59 static void fsanalyzer_playback_start(void); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
60 static void fsanalyzer_playback_stop(void); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
61 static void fsanalyzer_render_freq(gint16 data[2][256]); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
62 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
63 VisPlugin fsanalyzer_vp = { |
1646 | 64 .description = "Spectrum Analyzer", |
65 .num_pcm_chs_wanted = 0, | |
66 .num_freq_chs_wanted = 1, | |
67 .init = fsanalyzer_init, /* init */ | |
68 .cleanup = fsanalyzer_cleanup, /* cleanup */ | |
69 .playback_start = fsanalyzer_playback_start, /* playback_start */ | |
70 .playback_stop = fsanalyzer_playback_stop, /* playback_stop */ | |
71 .render_freq = fsanalyzer_render_freq /* render_freq */ | |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
72 }; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
73 |
1142
b10c821f0b4e
[svn] - spectrum: convert to plugin2 architecture.
nenolod
parents:
1061
diff
changeset
|
74 VisPlugin *spectrum_vplist[] = { &fsanalyzer_vp, NULL }; |
b10c821f0b4e
[svn] - spectrum: convert to plugin2 architecture.
nenolod
parents:
1061
diff
changeset
|
75 |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1325
diff
changeset
|
76 DECLARE_PLUGIN(spectrum, NULL, NULL, NULL, NULL, NULL, NULL, spectrum_vplist,NULL); |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
77 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
78 static void fsanalyzer_destroy_cb(GtkWidget *w,gpointer data) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
79 fsanalyzer_vp.disable_plugin(&fsanalyzer_vp); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
80 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
81 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
82 static void fsanalyzer_init(void) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
83 GdkColor color; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
84 int i; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
85 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
86 if(window) |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
87 return; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
88 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
89 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
90 gtk_window_set_title(GTK_WINDOW(window), _("Spectrum Analyzer")); |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
91 gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
92 gtk_widget_realize(window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
93 bg_pixmap = gdk_pixmap_create_from_xpm_d(window->window,NULL,NULL,logo_xpm); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
94 gdk_window_set_back_pixmap(window->window,bg_pixmap,0); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
95 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(fsanalyzer_destroy_cb),NULL); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
96 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_widget_destroyed), &window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
97 gtk_widget_set_size_request(GTK_WIDGET(window), WIDTH, HEIGHT); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
98 gc = gdk_gc_new(window->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
99 draw_pixmap = gdk_pixmap_new(window->window,WIDTH,HEIGHT,gdk_rgb_get_visual()->depth); |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
100 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
101 bar = gdk_pixmap_new(window->window,25, HEIGHT, gdk_rgb_get_visual()->depth); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
102 for(i = 0; i < HEIGHT / 2; i++) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
103 color.red = 0xFFFF; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
104 color.green = ((i * 255) / (HEIGHT / 2)) << 8; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
105 color.blue = 0; |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
106 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
107 gdk_color_alloc(gdk_colormap_get_system(),&color); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
108 gdk_gc_set_foreground(gc,&color); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
109 gdk_draw_line(bar,gc,0,i,24,i); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
110 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
111 for(i = 0; i < HEIGHT / 2; i++) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
112 color.red = (255 - ((i * 255) / (HEIGHT / 2))) <<8; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
113 color.green = 0xFFFF; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
114 color.blue = 0; |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
115 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
116 gdk_color_alloc(gdk_colormap_get_system(),&color); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
117 gdk_gc_set_foreground(gc,&color); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
118 gdk_draw_line(bar,gc,0,i + (HEIGHT / 2),24,i + (HEIGHT / 2)); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
119 } |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
120 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
121 scale = HEIGHT / ( log((1 - d) / d) * 2 ); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
122 x00 = d*d*32768.0/(2 * d - 1); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
123 y00 = -log(-x00) * scale; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
124 |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
125 /* d=0.2, HEIGHT=128 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
126 scale = 46.1662413084; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
127 x00 = -2184.53333333; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
128 y00 = -354.979500941; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
129 */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
130 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
131 gdk_color_black(gdk_colormap_get_system(),&color); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
132 gdk_gc_set_foreground(gc,&color); |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
133 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
134 area = gtk_drawing_area_new(); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
135 gtk_container_add(GTK_CONTAINER(window),area); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
136 gtk_widget_realize(area); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
137 gdk_window_set_back_pixmap(area->window,bg_pixmap,0); |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
138 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
139 gtk_widget_show(area); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
140 gtk_widget_show(window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
141 gdk_window_clear(window->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
142 gdk_window_clear(area->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
143 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
144 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
145 static void fsanalyzer_cleanup(void) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
146 if(window) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
147 gtk_widget_destroy(window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
148 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
149 if(gc) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
150 gdk_gc_unref(gc); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
151 gc = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
152 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
153 if(bg_pixmap) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
154 gdk_pixmap_unref(bg_pixmap); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
155 bg_pixmap = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
156 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
157 if(draw_pixmap) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
158 gdk_pixmap_unref(draw_pixmap); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
159 draw_pixmap = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
160 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
161 if(bar) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
162 gdk_pixmap_unref(bar); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
163 bar = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
164 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
165 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
166 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
167 static gint draw_func(gpointer data) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
168 gint i; |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
169 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
170 /* FIXME: should allow spare redrawing like the vis. in the main window */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
171 if(!window) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
172 /* timeout_tag = 0;*/ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
173 return FALSE; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
174 } |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
175 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
176 GDK_THREADS_ENTER(); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
177 gdk_draw_rectangle(draw_pixmap, gc, TRUE, 0, 0, WIDTH, HEIGHT); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
178 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
179 for(i = 0; i < WIDTH; i++) |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
180 gdk_draw_pixmap(draw_pixmap, gc, bar, 0, HEIGHT-1-bar_heights[i], i, HEIGHT-1-bar_heights[i], 1, bar_heights[i]); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
181 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
182 gdk_window_clear(area->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
183 GDK_THREADS_LEAVE(); |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
184 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
185 return TRUE; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
186 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
187 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
188 static void fsanalyzer_playback_start(void) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
189 if(window) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
190 gdk_window_set_back_pixmap(area->window,draw_pixmap,0); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
191 gdk_window_clear(area->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
192 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
193 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
194 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
195 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
196 static void fsanalyzer_playback_stop(void) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
197 if(GTK_WIDGET_REALIZED(area)) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
198 gdk_window_set_back_pixmap(area->window,bg_pixmap,0); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
199 gdk_window_clear(area->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
200 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
201 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
202 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
203 static void fsanalyzer_render_freq(gint16 data[2][256]) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
204 gint i; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
205 gdouble y; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
206 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
207 if(!window) |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
208 return; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
209 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
210 /* FIXME: can anything taken out of the main thread? */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
211 for (i = 0; i < WIDTH; i++) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
212 y = (gdouble)data[0][i] * (i + 1); /* Compensating the energy */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
213 y = ( log(y - x00) * scale + y00 ); /* Logarithmic amplitude */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
214 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
215 y = ( (dif-2)*y + /* FIXME: conditionals should be rolled out of the loop */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
216 (i==0 ? y : bar_heights[i-1]) + |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
217 (i==WIDTH-1 ? y : bar_heights[i+1])) / dif; /* Add some diffusion */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
218 y = ((tau-1)*bar_heights[i] + y) / tau; /* Add some dynamics */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
219 bar_heights[i] = (gint16)y; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
220 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
221 draw_func(NULL); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
222 return; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
223 } |