Mercurial > audlegacy-plugins
annotate src/spectrum/spectrum.c @ 3047:4434b4c4a715
ported EsounD plugin
author | Andrew O. Shadoura <bugzilla@tut.by> |
---|---|
date | Fri, 17 Apr 2009 16:17:10 +0300 |
parents | 3134a0987162 |
children |
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 |
2835 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
146
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> |
2971
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2835
diff
changeset
|
26 #include <audlegacy/plugin.h> |
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2835
diff
changeset
|
27 #include <audlegacy/i18n.h> |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
28 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
29 #include "logo.xpm" |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
30 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
31 /* 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
|
32 spectrum given by XMMS */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
33 #define WIDTH 256 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
34 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
35 /* 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
|
36 #define HEIGHT 128 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
37 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
38 /* 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
|
39 #define d 0.33 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
40 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
41 /* 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
|
42 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
|
43 #define tau 3 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
44 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
45 /* 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
|
46 added to the neighbouring bars */ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
47 #define dif 4 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
48 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
49 static GtkWidget *window = NULL,*area; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
50 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
|
51 static GdkGC *gc = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
52 static gint16 bar_heights[WIDTH]; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
53 /*static gint timeout_tag;*/ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
54 static gdouble scale, x00, y00; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
55 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
56 static void fsanalyzer_init(void); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
57 static void fsanalyzer_cleanup(void); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
58 static void fsanalyzer_playback_start(void); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
59 static void fsanalyzer_playback_stop(void); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
60 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
|
61 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
62 VisPlugin fsanalyzer_vp = { |
1646 | 63 .description = "Spectrum Analyzer", |
64 .num_pcm_chs_wanted = 0, | |
65 .num_freq_chs_wanted = 1, | |
66 .init = fsanalyzer_init, /* init */ | |
67 .cleanup = fsanalyzer_cleanup, /* cleanup */ | |
68 .playback_start = fsanalyzer_playback_start, /* playback_start */ | |
69 .playback_stop = fsanalyzer_playback_stop, /* playback_stop */ | |
70 .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
|
71 }; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
72 |
1142
b10c821f0b4e
[svn] - spectrum: convert to plugin2 architecture.
nenolod
parents:
1061
diff
changeset
|
73 VisPlugin *spectrum_vplist[] = { &fsanalyzer_vp, NULL }; |
b10c821f0b4e
[svn] - spectrum: convert to plugin2 architecture.
nenolod
parents:
1061
diff
changeset
|
74 |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1325
diff
changeset
|
75 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
|
76 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
77 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
|
78 fsanalyzer_vp.disable_plugin(&fsanalyzer_vp); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
79 } |
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 static void fsanalyzer_init(void) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
82 GdkColor color; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
83 int i; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
84 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
85 if(window) |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
86 return; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
87 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
88 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
89 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
|
90 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
|
91 gtk_widget_realize(window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 gc = gdk_gc_new(window->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
98 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
|
99 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
100 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
|
101 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
|
102 color.red = 0xFFFF; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
103 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
|
104 color.blue = 0; |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
105 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
106 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
|
107 gdk_gc_set_foreground(gc,&color); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
108 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
|
109 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
110 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
|
111 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
|
112 color.green = 0xFFFF; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
113 color.blue = 0; |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
114 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
115 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
|
116 gdk_gc_set_foreground(gc,&color); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
117 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
|
118 } |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
119 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
120 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
|
121 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
|
122 y00 = -log(-x00) * scale; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
123 |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
124 /* d=0.2, HEIGHT=128 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
125 scale = 46.1662413084; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
126 x00 = -2184.53333333; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
127 y00 = -354.979500941; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
128 */ |
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 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
|
131 gdk_gc_set_foreground(gc,&color); |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
132 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
133 area = gtk_drawing_area_new(); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
134 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
|
135 gtk_widget_realize(area); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
136 gdk_window_set_back_pixmap(area->window,bg_pixmap,0); |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
137 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
138 gtk_widget_show(area); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
139 gtk_widget_show(window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
140 gdk_window_clear(window->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
141 gdk_window_clear(area->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
142 } |
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 static void fsanalyzer_cleanup(void) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
145 if(window) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
146 gtk_widget_destroy(window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
147 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
148 if(gc) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
149 gdk_gc_unref(gc); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
150 gc = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
151 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
152 if(bg_pixmap) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
153 gdk_pixmap_unref(bg_pixmap); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
154 bg_pixmap = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
155 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
156 if(draw_pixmap) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
157 gdk_pixmap_unref(draw_pixmap); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
158 draw_pixmap = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
159 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
160 if(bar) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
161 gdk_pixmap_unref(bar); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
162 bar = NULL; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
163 } |
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 static gint draw_func(gpointer data) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
167 gint i; |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
168 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
169 /* 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
|
170 if(!window) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
171 /* timeout_tag = 0;*/ |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
172 return FALSE; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
173 } |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
174 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
175 GDK_THREADS_ENTER(); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
176 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
|
177 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
178 for(i = 0; i < WIDTH; i++) |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
179 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
|
180 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
181 gdk_window_clear(area->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
182 GDK_THREADS_LEAVE(); |
1325
a33da9237bed
Several "i18n" improvements.
Stany HENRY <StrassBoy@gmail.com>
parents:
1142
diff
changeset
|
183 |
146
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
184 return TRUE; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
185 } |
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 static void fsanalyzer_playback_start(void) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
188 if(window) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
189 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
|
190 gdk_window_clear(area->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
191 } |
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 static void fsanalyzer_playback_stop(void) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
196 if(GTK_WIDGET_REALIZED(area)) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
197 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
|
198 gdk_window_clear(area->window); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
199 } |
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 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
|
203 gint i; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
204 gdouble y; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
205 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
206 if(!window) |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
207 return; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
208 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
209 /* 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
|
210 for (i = 0; i < WIDTH; i++) { |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
211 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
|
212 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
|
213 |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
214 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
|
215 (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
|
216 (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
|
217 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
|
218 bar_heights[i] = (gint16)y; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
219 } |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
220 draw_func(NULL); |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
221 return; |
03cfb311eafd
[svn] - spectrum analyzer plugin based on blurscope and a little of xmms-finespectrum
nenolod
parents:
diff
changeset
|
222 } |