Mercurial > audlegacy
annotate audacious/visualization.c @ 2106:33f768ab6418 trunk
[svn] Remove leftover plugin-related bits that don't do anything any more.
author | kiyoshi |
---|---|
date | Tue, 12 Dec 2006 14:03:08 -0800 |
parents | f18a5b617c34 |
children | c12319817d7e |
rev | line source |
---|---|
0 | 1 /* BMP - Cross-platform multimedia player |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
2105
f18a5b617c34
[svn] - move to GPLv2-only. Based on my interpretation of the license, we are
nenolod
parents:
1653
diff
changeset
|
9 * the Free Software Foundation; under version 2 of the License. |
0 | 10 * |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
1459 | 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
0 | 19 */ |
20 | |
21 #include "visualization.h" | |
22 | |
23 #include <glib.h> | |
24 #include <stdlib.h> | |
25 #include <math.h> | |
26 #include <string.h> | |
27 | |
28 #include "fft.h" | |
29 #include "input.h" | |
30 #include "main.h" | |
538
e4e897d20791
[svn] remove libaudcore, we never did anything with it
nenolod
parents:
284
diff
changeset
|
31 #include "playback.h" |
0 | 32 #include "plugin.h" |
33 #include "prefswin.h" | |
1653 | 34 #include "widgets/widgetcore.h" |
0 | 35 |
36 VisPluginData vp_data = { | |
37 NULL, | |
38 NULL, | |
39 FALSE | |
40 }; | |
41 | |
42 GList * | |
43 get_vis_list(void) | |
44 { | |
45 return vp_data.vis_list; | |
46 } | |
47 | |
48 GList * | |
49 get_vis_enabled_list(void) | |
50 { | |
51 return vp_data.enabled_list; | |
52 } | |
53 | |
54 void | |
55 vis_disable_plugin(VisPlugin * vp) | |
56 { | |
57 gint i = g_list_index(vp_data.vis_list, vp); | |
58 enable_vis_plugin(i, FALSE); | |
59 } | |
60 | |
61 void | |
62 vis_about(gint i) | |
63 { | |
64 GList *node = g_list_nth(vp_data.vis_list, i); | |
65 | |
66 if (node && node->data && VIS_PLUGIN(node->data)->about) | |
67 VIS_PLUGIN(node->data)->about(); | |
68 } | |
69 | |
70 void | |
71 vis_configure(gint i) | |
72 { | |
73 GList *node = g_list_nth(vp_data.vis_list, i); | |
74 | |
75 if (node && node->data && VIS_PLUGIN(node->data)->configure) | |
76 VIS_PLUGIN(node->data)->configure(); | |
77 } | |
78 | |
79 void | |
80 vis_playback_start(void) | |
81 { | |
82 GList *node; | |
83 VisPlugin *vp; | |
84 | |
85 if (vp_data.playback_started) | |
86 return; | |
87 | |
88 for (node = vp_data.enabled_list; node; node = g_list_next(node)) { | |
89 vp = node->data; | |
90 if (vp->playback_start) | |
91 vp->playback_start(); | |
92 } | |
93 vp_data.playback_started = TRUE; | |
94 } | |
95 | |
96 void | |
97 vis_playback_stop(void) | |
98 { | |
99 GList *node = vp_data.enabled_list; | |
100 VisPlugin *vp; | |
101 | |
102 if (!vp_data.playback_started) | |
103 return; | |
104 | |
105 for (node = vp_data.enabled_list; node; node = g_list_next(node)) { | |
106 vp = node->data; | |
107 if (vp->playback_stop) | |
108 vp->playback_stop(); | |
109 } | |
110 vp_data.playback_started = FALSE; | |
111 } | |
112 | |
113 void | |
114 enable_vis_plugin(gint i, gboolean enable) | |
115 { | |
116 GList *node = g_list_nth(vp_data.vis_list, i); | |
117 VisPlugin *vp; | |
118 | |
119 if (!node || !(node->data)) | |
120 return; | |
121 vp = node->data; | |
122 | |
123 if (enable && !g_list_find(vp_data.enabled_list, vp)) { | |
124 vp_data.enabled_list = g_list_append(vp_data.enabled_list, vp); | |
125 if (vp->init) | |
126 vp->init(); | |
127 if (bmp_playback_get_playing() && vp->playback_start) | |
128 vp->playback_start(); | |
129 } | |
130 else if (!enable && g_list_find(vp_data.enabled_list, vp)) { | |
131 vp_data.enabled_list = g_list_remove(vp_data.enabled_list, vp); | |
132 if (bmp_playback_get_playing() && vp->playback_stop) | |
133 vp->playback_stop(); | |
134 if (vp->cleanup) | |
135 vp->cleanup(); | |
136 } | |
137 } | |
138 | |
139 gboolean | |
140 vis_enabled(gint i) | |
141 { | |
142 return (g_list_find | |
143 (vp_data.enabled_list, | |
144 g_list_nth(vp_data.vis_list, i)->data) != NULL); | |
145 } | |
146 | |
147 gchar * | |
148 vis_stringify_enabled_list(void) | |
149 { | |
150 gchar *enalist = NULL, *tmp, *tmp2; | |
151 GList *node = vp_data.enabled_list; | |
152 | |
153 if (g_list_length(node)) { | |
154 enalist = g_path_get_basename(VIS_PLUGIN(node->data)->filename); | |
155 for (node = g_list_next(node); node != NULL; node = g_list_next(node)) { | |
156 tmp = enalist; | |
157 tmp2 = g_path_get_basename(VIS_PLUGIN(node->data)->filename); | |
158 enalist = g_strconcat(tmp, ",", tmp2, NULL); | |
159 g_free(tmp); | |
160 g_free(tmp2); | |
161 } | |
162 } | |
163 return enalist; | |
164 } | |
165 | |
166 void | |
167 vis_enable_from_stringified_list(gchar * list) | |
168 { | |
169 gchar **plugins, *base; | |
170 GList *node; | |
171 gint i; | |
172 VisPlugin *vp; | |
173 | |
174 if (!list || !strcmp(list, "")) | |
175 return; | |
176 plugins = g_strsplit(list, ",", 0); | |
177 for (i = 0; plugins[i]; i++) { | |
178 for (node = vp_data.vis_list; node != NULL; node = g_list_next(node)) { | |
179 base = g_path_get_basename(VIS_PLUGIN(node->data)->filename); | |
180 if (!strcmp(plugins[i], base)) { | |
181 vp = node->data; | |
182 vp_data.enabled_list = | |
183 g_list_append(vp_data.enabled_list, vp); | |
184 if (vp->init) | |
185 vp->init(); | |
186 if (bmp_playback_get_playing() && vp->playback_start) | |
187 vp->playback_start(); | |
188 } | |
189 g_free(base); | |
190 } | |
191 } | |
192 g_strfreev(plugins); | |
193 } | |
194 | |
195 static void | |
196 calc_stereo_pcm(gint16 dest[2][512], gint16 src[2][512], gint nch) | |
197 { | |
198 memcpy(dest[0], src[0], 512 * sizeof(gint16)); | |
199 if (nch == 1) | |
200 memcpy(dest[1], src[0], 512 * sizeof(gint16)); | |
201 else | |
202 memcpy(dest[1], src[1], 512 * sizeof(gint16)); | |
203 } | |
204 | |
205 static void | |
206 calc_mono_pcm(gint16 dest[2][512], gint16 src[2][512], gint nch) | |
207 { | |
208 gint i; | |
209 gint16 *d, *sl, *sr; | |
210 | |
211 if (nch == 1) | |
212 memcpy(dest[0], src[0], 512 * sizeof(gint16)); | |
213 else { | |
214 d = dest[0]; | |
215 sl = src[0]; | |
216 sr = src[1]; | |
217 for (i = 0; i < 512; i++) { | |
218 *(d++) = (*(sl++) + *(sr++)) >> 1; | |
219 } | |
220 } | |
221 } | |
222 | |
223 static void | |
224 calc_freq(gint16 * dest, gint16 * src) | |
225 { | |
226 static fft_state *state = NULL; | |
227 gfloat tmp_out[257]; | |
228 gint i; | |
229 | |
230 if (!state) | |
231 state = fft_init(); | |
232 | |
233 fft_perform(src, tmp_out, state); | |
234 | |
235 for (i = 0; i < 256; i++) | |
236 dest[i] = ((gint) sqrt(tmp_out[i + 1])) >> 8; | |
237 } | |
238 | |
239 static void | |
240 calc_mono_freq(gint16 dest[2][256], gint16 src[2][512], gint nch) | |
241 { | |
242 gint i; | |
243 gint16 *d, *sl, *sr, tmp[512]; | |
244 | |
245 if (nch == 1) | |
246 calc_freq(dest[0], src[0]); | |
247 else { | |
248 d = tmp; | |
249 sl = src[0]; | |
250 sr = src[1]; | |
251 for (i = 0; i < 512; i++) { | |
252 *(d++) = (*(sl++) + *(sr++)) >> 1; | |
253 } | |
254 calc_freq(dest[0], tmp); | |
255 } | |
256 } | |
257 | |
258 static void | |
259 calc_stereo_freq(gint16 dest[2][256], gint16 src[2][512], gint nch) | |
260 { | |
261 calc_freq(dest[0], src[0]); | |
262 | |
263 if (nch == 2) | |
264 calc_freq(dest[1], src[1]); | |
265 else | |
266 memcpy(dest[1], dest[0], 256 * sizeof(gint16)); | |
267 } | |
268 | |
269 void | |
270 vis_send_data(gint16 pcm_data[2][512], gint nch, gint length) | |
271 { | |
272 GList *node = vp_data.enabled_list; | |
273 VisPlugin *vp; | |
274 gint16 mono_freq[2][256], stereo_freq[2][256]; | |
275 gboolean mono_freq_calced = FALSE, stereo_freq_calced = FALSE; | |
276 gint16 mono_pcm[2][512], stereo_pcm[2][512]; | |
277 gboolean mono_pcm_calced = FALSE, stereo_pcm_calced = FALSE; | |
278 guint8 intern_vis_data[512]; | |
279 gint i; | |
280 | |
281 if (!pcm_data || nch < 1) { | |
282 if (cfg.vis_type != VIS_OFF) { | |
283 if (cfg.player_shaded && cfg.player_visible) | |
284 svis_timeout_func(mainwin_svis, NULL); | |
285 else | |
286 vis_timeout_func(active_vis, NULL); | |
287 } | |
288 return; | |
289 } | |
290 | |
291 while (node) { | |
292 vp = node->data; | |
293 if (vp->num_pcm_chs_wanted > 0 && vp->render_pcm) { | |
294 if (vp->num_pcm_chs_wanted == 1) { | |
295 if (!mono_pcm_calced) { | |
296 calc_mono_pcm(mono_pcm, pcm_data, nch); | |
297 mono_pcm_calced = TRUE; | |
298 } | |
299 vp->render_pcm(mono_pcm); | |
300 } | |
301 else { | |
302 if (!stereo_pcm_calced) { | |
303 calc_stereo_pcm(stereo_pcm, pcm_data, nch); | |
304 stereo_pcm_calced = TRUE; | |
305 } | |
306 vp->render_pcm(stereo_pcm); | |
307 } | |
308 } | |
309 if (vp->num_freq_chs_wanted > 0 && vp->render_freq) { | |
310 if (vp->num_freq_chs_wanted == 1) { | |
311 if (!mono_freq_calced) { | |
312 calc_mono_freq(mono_freq, pcm_data, nch); | |
313 mono_freq_calced = TRUE; | |
314 } | |
315 vp->render_freq(mono_freq); | |
316 } | |
317 else { | |
318 if (!stereo_freq_calced) { | |
319 calc_stereo_freq(stereo_freq, pcm_data, nch); | |
320 stereo_freq_calced = TRUE; | |
321 } | |
322 vp->render_freq(stereo_freq); | |
323 } | |
324 } | |
325 node = g_list_next(node); | |
326 } | |
327 | |
328 if (cfg.vis_type == VIS_OFF) | |
329 return; | |
330 | |
331 if (cfg.vis_type == VIS_ANALYZER) { | |
332 if (cfg.player_shaded && cfg.player_visible) { | |
333 /* VU */ | |
334 gint vu, val; | |
335 | |
336 if (!stereo_pcm_calced) | |
337 calc_stereo_pcm(stereo_pcm, pcm_data, nch); | |
338 vu = 0; | |
339 for (i = 0; i < 512; i++) { | |
340 val = abs(stereo_pcm[0][i]); | |
341 if (val > vu) | |
342 vu = val; | |
343 } | |
344 intern_vis_data[0] = (vu * 37) >> 15; | |
345 if (intern_vis_data[0] > 37) | |
346 intern_vis_data[0] = 37; | |
347 if (nch == 2) { | |
348 vu = 0; | |
349 for (i = 0; i < 512; i++) { | |
350 val = abs(stereo_pcm[1][i]); | |
351 if (val > vu) | |
352 vu = val; | |
353 } | |
354 intern_vis_data[1] = (vu * 37) >> 15; | |
355 if (intern_vis_data[1] > 37) | |
356 intern_vis_data[1] = 37; | |
357 } | |
358 else | |
359 intern_vis_data[1] = intern_vis_data[0]; | |
360 } | |
361 else { | |
362 /* Spectrum analyzer */ | |
363 /* 76 values */ | |
364 const gint long_xscale[] = | |
365 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, | |
366 17, 18, | |
367 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, | |
368 34, | |
369 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, | |
370 50, 51, | |
371 52, 53, 54, 55, 56, 57, 58, 61, 66, 71, 76, 81, 87, 93, | |
372 100, 107, | |
373 114, 122, 131, 140, 150, 161, 172, 184, 255 | |
374 }; | |
375 /* 20 values */ | |
376 const int short_xscale[] = | |
377 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 15, 20, 27, | |
378 36, 47, 62, 82, 107, 141, 184, 255 | |
379 }; | |
380 const double y_scale = 3.60673760222; /* 20.0 / log(256) */ | |
381 const int *xscale; | |
382 gint j, y, max; | |
383 | |
384 if (!mono_freq_calced) | |
385 calc_mono_freq(mono_freq, pcm_data, nch); | |
386 | |
387 memset(intern_vis_data, 0, 75); | |
388 | |
389 if (cfg.analyzer_type == ANALYZER_BARS) { | |
390 max = 19; | |
391 xscale = short_xscale; | |
392 } | |
393 else { | |
394 max = 75; | |
395 xscale = long_xscale; | |
396 } | |
397 | |
398 for (i = 0; i < max; i++) { | |
399 for (j = xscale[i], y = 0; j < xscale[i + 1]; j++) { | |
400 if (mono_freq[0][j] > y) | |
401 y = mono_freq[0][j]; | |
402 } | |
403 y >>= 7; | |
404 if (y != 0) { | |
405 intern_vis_data[i] = log(y) * y_scale; | |
406 if (intern_vis_data[i] > 15) | |
407 intern_vis_data[i] = 15; | |
408 } | |
409 else | |
410 intern_vis_data[i] = 0; | |
411 } | |
412 } | |
413 } | |
414 else { /* (cfg.vis_type == VIS_SCOPE) */ | |
415 | |
416 /* Osciloscope */ | |
417 gint pos, step; | |
418 | |
419 if (!mono_pcm_calced) | |
420 calc_mono_pcm(mono_pcm, pcm_data, nch); | |
421 | |
422 step = (length << 8) / 74; | |
423 for (i = 0, pos = 0; i < 75; i++, pos += step) { | |
424 intern_vis_data[i] = ((mono_pcm[0][pos >> 8]) >> 11) + 6; | |
425 if (intern_vis_data[i] > 12) | |
426 intern_vis_data[i] = 12; | |
427 /* Do not see the point of that? (comparison always false) -larne. | |
428 if (intern_vis_data[i] < 0) | |
429 intern_vis_data[i] = 0; */ | |
430 } | |
431 } | |
432 if (cfg.player_shaded && cfg.player_visible) | |
433 svis_timeout_func(mainwin_svis, intern_vis_data); | |
434 else | |
435 vis_timeout_func(active_vis, intern_vis_data); | |
436 } |