Mercurial > audlegacy
annotate src/audacious/visualization.c @ 4266:2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
| author | stefano@zanga |
|---|---|
| date | Sun, 10 Feb 2008 12:31:44 +0100 |
| parents | 0898b8139af8 |
| children | 6a87d1c1da32 |
| rev | line source |
|---|---|
| 2313 | 1 /* Audacious - Cross-platform multimedia player |
| 2 * Copyright (C) 2005-2007 Audacious development team | |
| 3 * | |
| 4 * Based on BMP: | |
| 5 * Copyright (C) 2003-2004 BMP development team | |
| 6 * | |
| 7 * Based on XMMS: | |
| 8 * Copyright (C) 1998-2003 XMMS development team | |
| 9 * | |
| 10 * This program is free software; you can redistribute it and/or modify | |
| 11 * it under the terms of the GNU General Public License as published by | |
|
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3054
diff
changeset
|
12 * the Free Software Foundation; under version 3 of the License. |
| 2313 | 13 * |
| 14 * This program is distributed in the hope that it will be useful, | |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 * GNU General Public License for more details. | |
| 18 * | |
| 19 * You should have received a copy of the GNU General Public License | |
|
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3054
diff
changeset
|
20 * along with this program. If not, see <http://www.gnu.org/licenses>. |
|
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
21 * |
|
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
22 * The Audacious team does not consider modular code linking to |
|
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
23 * Audacious or using our public API to be a derived work. |
| 2313 | 24 */ |
| 25 | |
| 26 #include "visualization.h" | |
| 27 | |
| 28 #include <glib.h> | |
| 29 #include <stdlib.h> | |
| 30 #include <math.h> | |
| 31 #include <string.h> | |
| 32 | |
| 33 #include "fft.h" | |
| 34 #include "input.h" | |
| 35 #include "main.h" | |
| 36 #include "playback.h" | |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
37 #include "pluginenum.h" |
| 2313 | 38 #include "plugin.h" |
| 39 #include "ui_preferences.h" | |
| 40 | |
| 41 VisPluginData vp_data = { | |
| 42 NULL, | |
| 43 NULL, | |
| 44 FALSE | |
| 45 }; | |
| 46 | |
| 47 GList * | |
| 48 get_vis_list(void) | |
| 49 { | |
| 50 return vp_data.vis_list; | |
| 51 } | |
| 52 | |
| 53 GList * | |
| 54 get_vis_enabled_list(void) | |
| 55 { | |
| 56 return vp_data.enabled_list; | |
| 57 } | |
| 58 | |
| 59 void | |
| 60 vis_disable_plugin(VisPlugin * vp) | |
| 61 { | |
| 62 gint i = g_list_index(vp_data.vis_list, vp); | |
| 63 enable_vis_plugin(i, FALSE); | |
| 64 } | |
| 65 | |
| 66 void | |
| 67 vis_playback_start(void) | |
| 68 { | |
| 69 GList *node; | |
| 70 VisPlugin *vp; | |
| 71 | |
| 72 if (vp_data.playback_started) | |
| 73 return; | |
| 74 | |
| 75 for (node = vp_data.enabled_list; node; node = g_list_next(node)) { | |
| 76 vp = node->data; | |
| 77 if (vp->playback_start) | |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
78 { |
|
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
79 plugin_set_current((Plugin *)vp); |
| 2313 | 80 vp->playback_start(); |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
81 } |
| 2313 | 82 } |
| 83 vp_data.playback_started = TRUE; | |
| 84 } | |
| 85 | |
| 86 void | |
| 87 vis_playback_stop(void) | |
| 88 { | |
| 89 GList *node = vp_data.enabled_list; | |
| 90 VisPlugin *vp; | |
| 91 | |
| 92 if (!vp_data.playback_started) | |
| 93 return; | |
| 94 | |
| 95 for (node = vp_data.enabled_list; node; node = g_list_next(node)) { | |
| 96 vp = node->data; | |
| 97 if (vp->playback_stop) | |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
98 { |
|
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
99 plugin_set_current((Plugin *)vp); |
| 2313 | 100 vp->playback_stop(); |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
101 } |
| 2313 | 102 } |
| 103 vp_data.playback_started = FALSE; | |
| 104 } | |
| 105 | |
| 106 void | |
| 107 enable_vis_plugin(gint i, gboolean enable) | |
| 108 { | |
| 109 GList *node = g_list_nth(vp_data.vis_list, i); | |
| 110 VisPlugin *vp; | |
| 111 | |
| 112 if (!node || !(node->data)) | |
| 113 return; | |
| 114 vp = node->data; | |
| 115 | |
|
3437
3092a8b3fe34
Big plugin system changes (part 1 of who knows, it's still a big mess):
William Pitcock <nenolod@atheme.org>
parents:
3251
diff
changeset
|
116 if (enable && !vp->enabled) { |
| 2313 | 117 vp_data.enabled_list = g_list_append(vp_data.enabled_list, vp); |
| 118 if (vp->init) | |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
119 { |
|
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
120 plugin_set_current((Plugin *)vp); |
| 2313 | 121 vp->init(); |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
122 } |
| 2313 | 123 if (playback_get_playing() && vp->playback_start) |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
124 { |
|
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
125 plugin_set_current((Plugin *)vp); |
| 2313 | 126 vp->playback_start(); |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
127 } |
| 2313 | 128 } |
|
3437
3092a8b3fe34
Big plugin system changes (part 1 of who knows, it's still a big mess):
William Pitcock <nenolod@atheme.org>
parents:
3251
diff
changeset
|
129 else if (!enable && vp->enabled) { |
| 2313 | 130 vp_data.enabled_list = g_list_remove(vp_data.enabled_list, vp); |
| 131 if (playback_get_playing() && vp->playback_stop) | |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
132 { |
|
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
133 plugin_set_current((Plugin *)vp); |
| 2313 | 134 vp->playback_stop(); |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
135 } |
| 2313 | 136 if (vp->cleanup) |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
137 { |
|
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
138 plugin_set_current((Plugin *)vp); |
| 2313 | 139 vp->cleanup(); |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
140 } |
| 2313 | 141 } |
|
3437
3092a8b3fe34
Big plugin system changes (part 1 of who knows, it's still a big mess):
William Pitcock <nenolod@atheme.org>
parents:
3251
diff
changeset
|
142 |
|
3092a8b3fe34
Big plugin system changes (part 1 of who knows, it's still a big mess):
William Pitcock <nenolod@atheme.org>
parents:
3251
diff
changeset
|
143 vp->enabled = enable; |
| 2313 | 144 } |
| 145 | |
| 146 gchar * | |
| 147 vis_stringify_enabled_list(void) | |
| 148 { | |
| 149 gchar *enalist = NULL, *tmp, *tmp2; | |
| 150 GList *node = vp_data.enabled_list; | |
| 151 | |
| 152 if (g_list_length(node)) { | |
| 153 enalist = g_path_get_basename(VIS_PLUGIN(node->data)->filename); | |
| 154 for (node = g_list_next(node); node != NULL; node = g_list_next(node)) { | |
| 155 tmp = enalist; | |
| 156 tmp2 = g_path_get_basename(VIS_PLUGIN(node->data)->filename); | |
| 157 enalist = g_strconcat(tmp, ",", tmp2, NULL); | |
| 158 g_free(tmp); | |
| 159 g_free(tmp2); | |
| 160 } | |
| 161 } | |
| 162 return enalist; | |
| 163 } | |
| 164 | |
| 165 void | |
| 166 vis_enable_from_stringified_list(gchar * list) | |
| 167 { | |
| 168 gchar **plugins, *base; | |
| 169 GList *node; | |
| 170 gint i; | |
| 171 VisPlugin *vp; | |
| 172 | |
| 173 if (!list || !strcmp(list, "")) | |
| 174 return; | |
| 175 plugins = g_strsplit(list, ",", 0); | |
| 176 for (i = 0; plugins[i]; i++) { | |
| 177 for (node = vp_data.vis_list; node != NULL; node = g_list_next(node)) { | |
| 178 base = g_path_get_basename(VIS_PLUGIN(node->data)->filename); | |
| 179 if (!strcmp(plugins[i], base)) { | |
| 180 vp = node->data; | |
| 181 vp_data.enabled_list = | |
| 182 g_list_append(vp_data.enabled_list, vp); | |
| 183 if (vp->init) | |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
184 { |
|
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
185 plugin_set_current((Plugin *)vp); |
| 2313 | 186 vp->init(); |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
187 } |
| 2313 | 188 if (playback_get_playing() && vp->playback_start) |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
189 { |
|
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
190 plugin_set_current((Plugin *)vp); |
| 2313 | 191 vp->playback_start(); |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
192 } |
|
3437
3092a8b3fe34
Big plugin system changes (part 1 of who knows, it's still a big mess):
William Pitcock <nenolod@atheme.org>
parents:
3251
diff
changeset
|
193 vp->enabled = TRUE; |
| 2313 | 194 } |
| 195 g_free(base); | |
| 196 } | |
| 197 } | |
| 198 g_strfreev(plugins); | |
| 199 } | |
| 200 | |
| 201 static void | |
| 202 calc_stereo_pcm(gint16 dest[2][512], gint16 src[2][512], gint nch) | |
| 203 { | |
| 204 memcpy(dest[0], src[0], 512 * sizeof(gint16)); | |
| 205 if (nch == 1) | |
| 206 memcpy(dest[1], src[0], 512 * sizeof(gint16)); | |
| 207 else | |
| 208 memcpy(dest[1], src[1], 512 * sizeof(gint16)); | |
| 209 } | |
| 210 | |
| 211 static void | |
| 212 calc_mono_pcm(gint16 dest[2][512], gint16 src[2][512], gint nch) | |
| 213 { | |
| 214 gint i; | |
| 215 gint16 *d, *sl, *sr; | |
| 216 | |
| 217 if (nch == 1) | |
| 218 memcpy(dest[0], src[0], 512 * sizeof(gint16)); | |
| 219 else { | |
| 220 d = dest[0]; | |
| 221 sl = src[0]; | |
| 222 sr = src[1]; | |
| 223 for (i = 0; i < 512; i++) { | |
| 224 *(d++) = (*(sl++) + *(sr++)) >> 1; | |
| 225 } | |
| 226 } | |
| 227 } | |
| 228 | |
| 229 static void | |
| 230 calc_freq(gint16 * dest, gint16 * src) | |
| 231 { | |
| 232 static fft_state *state = NULL; | |
| 233 gfloat tmp_out[257]; | |
| 234 gint i; | |
| 235 | |
| 236 if (!state) | |
| 237 state = fft_init(); | |
| 238 | |
| 239 fft_perform(src, tmp_out, state); | |
| 240 | |
| 241 for (i = 0; i < 256; i++) | |
| 242 dest[i] = ((gint) sqrt(tmp_out[i + 1])) >> 8; | |
| 243 } | |
| 244 | |
| 245 static void | |
| 246 calc_mono_freq(gint16 dest[2][256], gint16 src[2][512], gint nch) | |
| 247 { | |
| 248 gint i; | |
| 249 gint16 *d, *sl, *sr, tmp[512]; | |
| 250 | |
| 251 if (nch == 1) | |
| 252 calc_freq(dest[0], src[0]); | |
| 253 else { | |
| 254 d = tmp; | |
| 255 sl = src[0]; | |
| 256 sr = src[1]; | |
| 257 for (i = 0; i < 512; i++) { | |
| 258 *(d++) = (*(sl++) + *(sr++)) >> 1; | |
| 259 } | |
| 260 calc_freq(dest[0], tmp); | |
| 261 } | |
| 262 } | |
| 263 | |
| 264 static void | |
| 265 calc_stereo_freq(gint16 dest[2][256], gint16 src[2][512], gint nch) | |
| 266 { | |
| 267 calc_freq(dest[0], src[0]); | |
| 268 | |
| 269 if (nch == 2) | |
| 270 calc_freq(dest[1], src[1]); | |
| 271 else | |
| 272 memcpy(dest[1], dest[0], 256 * sizeof(gint16)); | |
| 273 } | |
| 274 | |
| 275 void | |
| 276 vis_send_data(gint16 pcm_data[2][512], gint nch, gint length) | |
| 277 { | |
| 278 GList *node = vp_data.enabled_list; | |
| 279 VisPlugin *vp; | |
| 280 gint16 mono_freq[2][256], stereo_freq[2][256]; | |
| 281 gboolean mono_freq_calced = FALSE, stereo_freq_calced = FALSE; | |
| 282 gint16 mono_pcm[2][512], stereo_pcm[2][512]; | |
| 283 gboolean mono_pcm_calced = FALSE, stereo_pcm_calced = FALSE; | |
| 284 guint8 intern_vis_data[512]; | |
| 285 gint i; | |
| 286 | |
| 287 if (!pcm_data || nch < 1) { | |
| 288 if (cfg.vis_type != VIS_OFF) { | |
| 289 if (cfg.player_shaded && cfg.player_visible) | |
| 3054 | 290 ui_svis_timeout_func(mainwin_svis, NULL); |
| 2313 | 291 else |
| 3020 | 292 ui_vis_timeout_func(mainwin_vis, NULL); |
| 2313 | 293 } |
| 294 return; | |
| 295 } | |
| 296 | |
| 297 while (node) { | |
| 298 vp = node->data; | |
| 299 if (vp->num_pcm_chs_wanted > 0 && vp->render_pcm) { | |
| 300 if (vp->num_pcm_chs_wanted == 1) { | |
| 301 if (!mono_pcm_calced) { | |
| 302 calc_mono_pcm(mono_pcm, pcm_data, nch); | |
| 303 mono_pcm_calced = TRUE; | |
| 304 } | |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
305 plugin_set_current((Plugin *)vp); |
| 2313 | 306 vp->render_pcm(mono_pcm); |
| 307 } | |
| 308 else { | |
| 309 if (!stereo_pcm_calced) { | |
| 310 calc_stereo_pcm(stereo_pcm, pcm_data, nch); | |
| 311 stereo_pcm_calced = TRUE; | |
| 312 } | |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
313 plugin_set_current((Plugin *)vp); |
| 2313 | 314 vp->render_pcm(stereo_pcm); |
| 315 } | |
| 316 } | |
| 317 if (vp->num_freq_chs_wanted > 0 && vp->render_freq) { | |
| 318 if (vp->num_freq_chs_wanted == 1) { | |
| 319 if (!mono_freq_calced) { | |
| 320 calc_mono_freq(mono_freq, pcm_data, nch); | |
| 321 mono_freq_calced = TRUE; | |
| 322 } | |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
323 plugin_set_current((Plugin *)vp); |
| 2313 | 324 vp->render_freq(mono_freq); |
| 325 } | |
| 326 else { | |
| 327 if (!stereo_freq_calced) { | |
| 328 calc_stereo_freq(stereo_freq, pcm_data, nch); | |
| 329 stereo_freq_calced = TRUE; | |
| 330 } | |
|
4266
2b7a74fce100
Implemented support for multiple subplugins inside a plugin (see bug #148) and PluginHeader finalization
stefano@zanga
parents:
3559
diff
changeset
|
331 plugin_set_current((Plugin *)vp); |
| 2313 | 332 vp->render_freq(stereo_freq); |
| 333 } | |
| 334 } | |
| 335 node = g_list_next(node); | |
| 336 } | |
| 337 | |
| 338 if (cfg.vis_type == VIS_OFF) | |
| 339 return; | |
| 340 | |
| 341 if (cfg.vis_type == VIS_ANALYZER) { | |
| 342 /* Spectrum analyzer */ | |
| 343 /* 76 values */ | |
| 344 const gint long_xscale[] = | |
| 345 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, | |
| 346 17, 18, | |
| 347 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, | |
| 348 34, | |
| 349 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, | |
| 350 50, 51, | |
| 351 52, 53, 54, 55, 56, 57, 58, 61, 66, 71, 76, 81, 87, 93, | |
| 352 100, 107, | |
| 353 114, 122, 131, 140, 150, 161, 172, 184, 255 | |
| 354 }; | |
| 355 /* 20 values */ | |
| 356 const int short_xscale[] = | |
| 357 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 15, 20, 27, | |
| 358 36, 47, 62, 82, 107, 141, 184, 255 | |
| 359 }; | |
| 360 const double y_scale = 3.60673760222; /* 20.0 / log(256) */ | |
| 361 const int *xscale; | |
| 362 gint j, y, max; | |
| 363 | |
| 364 if (!mono_freq_calced) | |
| 365 calc_mono_freq(mono_freq, pcm_data, nch); | |
| 366 | |
| 367 memset(intern_vis_data, 0, 75); | |
| 368 | |
| 369 if (cfg.analyzer_type == ANALYZER_BARS) { | |
| 370 if (cfg.player_shaded) { | |
| 371 max = 13; | |
| 372 } | |
| 373 else { | |
| 374 max = 19; | |
| 375 } | |
| 376 xscale = short_xscale; | |
| 377 } | |
| 378 else { | |
| 379 if (cfg.player_shaded) { | |
| 380 max = 37; | |
| 381 } | |
| 382 else { | |
| 383 max = 75; | |
| 384 } | |
| 385 xscale = long_xscale; | |
| 386 } | |
| 387 | |
| 388 for (i = 0; i < max; i++) { | |
| 389 for (j = xscale[i], y = 0; j < xscale[i + 1]; j++) { | |
| 390 if (mono_freq[0][j] > y) | |
| 391 y = mono_freq[0][j]; | |
| 392 } | |
| 393 y >>= 7; | |
| 394 if (y != 0) { | |
| 395 intern_vis_data[i] = log(y) * y_scale; | |
| 396 if (intern_vis_data[i] > 15) | |
| 397 intern_vis_data[i] = 15; | |
| 398 } | |
| 399 else | |
| 400 intern_vis_data[i] = 0; | |
| 401 } | |
| 402 | |
| 403 } | |
| 404 else if(cfg.vis_type == VIS_VOICEPRINT){ | |
| 405 if (cfg.player_shaded && cfg.player_visible) { | |
| 406 /* VU */ | |
| 407 gint vu, val; | |
| 408 | |
| 409 if (!stereo_pcm_calced) | |
| 410 calc_stereo_pcm(stereo_pcm, pcm_data, nch); | |
| 411 vu = 0; | |
| 412 for (i = 0; i < 512; i++) { | |
| 413 val = abs(stereo_pcm[0][i]); | |
| 414 if (val > vu) | |
| 415 vu = val; | |
| 416 } | |
| 417 intern_vis_data[0] = (vu * 37) >> 15; | |
| 418 if (intern_vis_data[0] > 37) | |
| 419 intern_vis_data[0] = 37; | |
| 420 if (nch == 2) { | |
| 421 vu = 0; | |
| 422 for (i = 0; i < 512; i++) { | |
| 423 val = abs(stereo_pcm[1][i]); | |
| 424 if (val > vu) | |
| 425 vu = val; | |
| 426 } | |
| 427 intern_vis_data[1] = (vu * 37) >> 15; | |
| 428 if (intern_vis_data[1] > 37) | |
| 429 intern_vis_data[1] = 37; | |
| 430 } | |
| 431 else | |
| 432 intern_vis_data[1] = intern_vis_data[0]; | |
| 433 } | |
| 434 else{ /*Voiceprint*/ | |
| 435 if (!mono_freq_calced) | |
| 436 calc_mono_freq(mono_freq, pcm_data, nch); | |
| 437 memset(intern_vis_data, 0, 256); | |
| 438 /* For the values [0-16] we use the frequency that's 3/2 as much. | |
| 439 If we assume the 512 values calculated by calc_mono_freq to cover 0-22kHz linearly | |
| 440 we get a range of [0-16] * 3/2 * 22000/512 = [0-1,031] Hz. | |
| 441 Most stuff above that is harmonics and we want to utilize the 16 samples we have | |
| 442 to the max[tm] | |
| 443 */ | |
| 444 for(i = 0; i < 50 ; i+=3){ | |
| 445 intern_vis_data[i/3] += (mono_freq[0][i/2] >> 5); | |
| 446 | |
| 447 /*Boost frequencies above 257Hz a little*/ | |
| 448 //if(i > 4 * 3) | |
| 449 // intern_vis_data[i/3] += 8; | |
| 450 } | |
| 451 } | |
| 452 } | |
| 453 else { /* (cfg.vis_type == VIS_SCOPE) */ | |
| 454 | |
| 455 /* Oscilloscope */ | |
| 456 gint pos, step; | |
| 457 | |
| 458 if (!mono_pcm_calced) | |
| 459 calc_mono_pcm(mono_pcm, pcm_data, nch); | |
| 460 | |
| 461 step = (length << 8) / 74; | |
| 462 for (i = 0, pos = 0; i < 75; i++, pos += step) { | |
| 463 intern_vis_data[i] = ((mono_pcm[0][pos >> 8]) >> 12) + 7; | |
| 464 if (intern_vis_data[i] == 255) | |
| 465 intern_vis_data[i] = 0; | |
| 466 else if (intern_vis_data[i] > 12) | |
| 467 intern_vis_data[i] = 12; | |
| 468 /* Do not see the point of that? (comparison always false) -larne. | |
| 469 if (intern_vis_data[i] < 0) | |
| 470 intern_vis_data[i] = 0; */ | |
| 471 } | |
| 472 } | |
| 473 if (cfg.player_shaded && cfg.player_visible) | |
| 3054 | 474 ui_svis_timeout_func(mainwin_svis, intern_vis_data); |
| 2313 | 475 else |
| 3020 | 476 ui_vis_timeout_func(mainwin_vis, intern_vis_data); |
| 2313 | 477 } |
| 3559 | 478 |
| 479 void | |
| 480 vis_flow(FlowContext *context) | |
| 481 { | |
| 482 input_add_vis_pcm(context->time, context->fmt, context->channels, | |
| 483 context->len, context->data); | |
| 484 } |
