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