Mercurial > audlegacy
annotate audacious/visualization.c @ 2226:325a97334c11 trunk
[svn] - set the translation domain for UIManager owned objects. Closes #719, #720.
author | nenolod |
---|---|
date | Sun, 31 Dec 2006 11:32:05 -0800 |
parents | 60bd49189fde |
children | 894f7aa46f83 |
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 /* Spectrum analyzer */ | |
333 /* 76 values */ | |
334 const gint long_xscale[] = | |
335 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, | |
336 17, 18, | |
337 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, | |
338 34, | |
339 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, | |
340 50, 51, | |
341 52, 53, 54, 55, 56, 57, 58, 61, 66, 71, 76, 81, 87, 93, | |
342 100, 107, | |
343 114, 122, 131, 140, 150, 161, 172, 184, 255 | |
344 }; | |
345 /* 20 values */ | |
346 const int short_xscale[] = | |
347 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 15, 20, 27, | |
348 36, 47, 62, 82, 107, 141, 184, 255 | |
349 }; | |
350 const double y_scale = 3.60673760222; /* 20.0 / log(256) */ | |
351 const int *xscale; | |
352 gint j, y, max; | |
353 | |
354 if (!mono_freq_calced) | |
355 calc_mono_freq(mono_freq, pcm_data, nch); | |
356 | |
357 memset(intern_vis_data, 0, 75); | |
358 | |
359 if (cfg.analyzer_type == ANALYZER_BARS) { | |
2190
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
360 if (cfg.player_shaded) { |
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
361 max = 13; |
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
362 } |
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
363 else { |
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
364 max = 19; |
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
365 } |
0 | 366 xscale = short_xscale; |
367 } | |
368 else { | |
2190
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
369 if (cfg.player_shaded) { |
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
370 max = 37; |
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
371 } |
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
372 else { |
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
373 max = 75; |
d618044d35e4
[svn] - Fix the number of analyzer bars drawn in shaded mode.
nhjm449
parents:
2181
diff
changeset
|
374 } |
0 | 375 xscale = long_xscale; |
376 } | |
377 | |
378 for (i = 0; i < max; i++) { | |
379 for (j = xscale[i], y = 0; j < xscale[i + 1]; j++) { | |
380 if (mono_freq[0][j] > y) | |
381 y = mono_freq[0][j]; | |
382 } | |
383 y >>= 7; | |
384 if (y != 0) { | |
385 intern_vis_data[i] = log(y) * y_scale; | |
386 if (intern_vis_data[i] > 15) | |
387 intern_vis_data[i] = 15; | |
388 } | |
389 else | |
390 intern_vis_data[i] = 0; | |
391 } | |
2171 | 392 |
0 | 393 } |
2161
c12319817d7e
[svn] - patch to add a scrolling voiceprint to the mini visualizer.
nenolod
parents:
2105
diff
changeset
|
394 else if(cfg.vis_type == VIS_VOICEPRINT){ |
2171 | 395 if (cfg.player_shaded && cfg.player_visible) { |
396 /* VU */ | |
397 gint vu, val; | |
2169
0934eeabc0ed
[svn] Added subsampling and nonlinear transfer function to the voiceprint
marvin
parents:
2166
diff
changeset
|
398 |
2171 | 399 if (!stereo_pcm_calced) |
400 calc_stereo_pcm(stereo_pcm, pcm_data, nch); | |
401 vu = 0; | |
402 for (i = 0; i < 512; i++) { | |
403 val = abs(stereo_pcm[0][i]); | |
404 if (val > vu) | |
405 vu = val; | |
406 } | |
407 intern_vis_data[0] = (vu * 37) >> 15; | |
408 if (intern_vis_data[0] > 37) | |
409 intern_vis_data[0] = 37; | |
410 if (nch == 2) { | |
411 vu = 0; | |
412 for (i = 0; i < 512; i++) { | |
413 val = abs(stereo_pcm[1][i]); | |
414 if (val > vu) | |
415 vu = val; | |
416 } | |
417 intern_vis_data[1] = (vu * 37) >> 15; | |
418 if (intern_vis_data[1] > 37) | |
419 intern_vis_data[1] = 37; | |
420 } | |
421 else | |
422 intern_vis_data[1] = intern_vis_data[0]; | |
423 } | |
424 else{ /*Voiceprint*/ | |
425 if (!mono_freq_calced) | |
426 calc_mono_freq(mono_freq, pcm_data, nch); | |
2181
65ca93cd72bf
[svn] - Added vis gradient to Ivory skin. With any luck Aerdan won't break my legs :)
marvin
parents:
2179
diff
changeset
|
427 memset(intern_vis_data, 0, 256); |
2203
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
428 /* For the values [0-16] we use the frequency that's 3/2 as much. |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
429 If we assume the 512 values calculated by calc_mono_freq to cover 0-22kHz linearly |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
430 we get a range of [0-16] * 3/2 * 22000/512 = [0-1,031] Hz. |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
431 Most stuff above that is harmonics and we want to utilize the 16 samples we have |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
432 to the max[tm] |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
433 */ |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
434 for(i = 0; i < 50 ; i+=3){ |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
435 intern_vis_data[i/3] += (mono_freq[0][i/2] >> 5); |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
436 |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
437 /*Boost frequencies above 257Hz a little*/ |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
438 //if(i > 4 * 3) |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
439 // intern_vis_data[i/3] += 8; |
60bd49189fde
[svn] - two realcolour modes for voiceprint vis: Fire and Ice
marvin
parents:
2194
diff
changeset
|
440 } |
2171 | 441 } |
2161
c12319817d7e
[svn] - patch to add a scrolling voiceprint to the mini visualizer.
nenolod
parents:
2105
diff
changeset
|
442 } |
c12319817d7e
[svn] - patch to add a scrolling voiceprint to the mini visualizer.
nenolod
parents:
2105
diff
changeset
|
443 else { /* (cfg.vis_type == VIS_SCOPE) */ |
0 | 444 |
2161
c12319817d7e
[svn] - patch to add a scrolling voiceprint to the mini visualizer.
nenolod
parents:
2105
diff
changeset
|
445 /* Oscilloscope */ |
0 | 446 gint pos, step; |
447 | |
448 if (!mono_pcm_calced) | |
449 calc_mono_pcm(mono_pcm, pcm_data, nch); | |
450 | |
451 step = (length << 8) / 74; | |
452 for (i = 0, pos = 0; i < 75; i++, pos += step) { | |
2194 | 453 intern_vis_data[i] = ((mono_pcm[0][pos >> 8]) >> 12) + 7; |
454 if (intern_vis_data[i] == 255) | |
455 intern_vis_data[i] = 0; | |
456 else if (intern_vis_data[i] > 12) | |
0 | 457 intern_vis_data[i] = 12; |
458 /* Do not see the point of that? (comparison always false) -larne. | |
459 if (intern_vis_data[i] < 0) | |
460 intern_vis_data[i] = 0; */ | |
461 } | |
462 } | |
463 if (cfg.player_shaded && cfg.player_visible) | |
464 svis_timeout_func(mainwin_svis, intern_vis_data); | |
465 else | |
466 vis_timeout_func(active_vis, intern_vis_data); | |
467 } |