1 /*****************************************************************************
2 * effects.c : Effects for the visualization system
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@via.ecp.fr>
8 * Adrien Maglo <magsoft@videolan.org>
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
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
42 #define BAR_DECREASE_SPEED 5
44 #define GRAD_ANGLE_MIN 0.2
45 #define GRAD_ANGLE_MAX 0.5
46 #define GRAD_INCR 0.01
48 /*****************************************************************************
50 *****************************************************************************/
51 int dummy_Run( visual_effect_t * p_effect, vlc_object_t *p_aout,
52 const block_t * p_buffer , picture_t * p_picture)
54 VLC_UNUSED(p_effect); VLC_UNUSED(p_aout); VLC_UNUSED(p_buffer);
55 VLC_UNUSED(p_picture);
59 /*****************************************************************************
60 * spectrum_Run: spectrum analyser
61 *****************************************************************************/
62 int spectrum_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
63 const block_t * p_buffer , picture_t * p_picture)
65 spectrum_data *p_data = p_effect->p_data;
66 float p_output[FFT_BUFFER_SIZE]; /* Raw FFT Result */
67 int *height; /* Bar heights */
68 int *peaks; /* Peaks */
69 int *prev_heights; /* Previous bar heights */
70 int i_80_bands; /* number of bands : 80 if true else 20 */
71 int i_nb_bands; /* number of bands : 80 or 20 */
72 int i_band_width; /* width of bands */
73 int i_start; /* first band horizontal position */
74 int i_peak; /* Should we draw peaks ? */
76 /* Horizontal scale for 20-band equalizer */
77 const int xscale1[]={0,1,2,3,4,5,6,7,8,11,15,20,27,
78 36,47,62,82,107,141,184,255};
80 /* Horizontal scale for 80-band equalizer */
82 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
83 19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
84 35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
85 52,53,54,55,56,57,58,59,61,63,67,72,77,82,87,93,99,105,
86 110,115,121,130,141,152,163,174,185,200,255};
89 fft_state *p_state; /* internal FFT data */
93 int16_t p_dest[FFT_BUFFER_SIZE]; /* Adapted FFT result */
94 int16_t p_buffer1[FFT_BUFFER_SIZE]; /* Buffer on which we perform
95 the FFT (first channel) */
97 float *p_buffl = /* Original buffer */
98 (float*)p_buffer->p_buffer;
100 int16_t *p_buffs; /* int16_t converted buffer */
101 int16_t *p_s16_buff; /* int16_t converted buffer */
103 /* Create p_data if needed */
106 p_effect->p_data = p_data = malloc( sizeof( spectrum_data ) );
110 p_data->peaks = calloc( 80, sizeof(int) );
111 p_data->prev_heights = calloc( 80, sizeof(int) );
113 p_data->i_prev_nb_samples = 0;
114 p_data->p_prev_s16_buff = NULL;
116 peaks = (int *)p_data->peaks;
117 prev_heights = (int *)p_data->prev_heights;
119 /* Allocate the buffer only if the number of samples change */
120 if( p_buffer->i_nb_samples != p_data->i_prev_nb_samples )
122 free( p_data->p_prev_s16_buff );
123 p_data->p_prev_s16_buff = malloc( p_buffer->i_nb_samples *
124 p_effect->i_nb_chans *
126 p_data->i_prev_nb_samples = p_buffer->i_nb_samples;
127 if( !p_data->p_prev_s16_buff )
130 p_buffs = p_s16_buff = p_data->p_prev_s16_buff;
132 i_80_bands = config_GetInt ( p_aout, "visual-80-bands" );
133 i_peak = config_GetInt ( p_aout, "visual-peaks" );
146 height = malloc( i_nb_bands * sizeof(int) );
151 /* Convert the buffer to int16_t */
152 /* Pasted from float32tos16.c */
153 for (i = p_buffer->i_nb_samples * p_effect->i_nb_chans; i--; )
155 union { float f; int32_t i; } u;
156 u.f = *p_buffl + 384.0;
157 if(u.i > 0x43c07fff ) * p_buffs = 32767;
158 else if ( u.i < 0x43bf8000 ) *p_buffs = -32768;
159 else *p_buffs = u.i - 0x43c00000;
161 p_buffl++ ; p_buffs++ ;
163 p_state = visual_fft_init();
167 msg_Err(p_aout,"unable to initialize FFT transform");
170 p_buffs = p_s16_buff;
171 for ( i = 0 ; i < FFT_BUFFER_SIZE ; i++)
174 p_buffer1[i] = *p_buffs;
176 p_buffs += p_effect->i_nb_chans;
177 if( p_buffs >= &p_s16_buff[p_buffer->i_nb_samples * p_effect->i_nb_chans] )
178 p_buffs = p_s16_buff;
181 fft_perform( p_buffer1, p_output, p_state);
182 for( i = 0; i< FFT_BUFFER_SIZE ; i++ )
183 p_dest[i] = p_output[i] * ( 2 ^ 16 ) / ( ( FFT_BUFFER_SIZE / 2 * 32768 ) ^ 2 );
185 /* Compute the horizontal position of the first band */
186 i_band_width = floor( p_effect->i_width / i_nb_bands);
187 i_start = ( p_effect->i_width - i_band_width * i_nb_bands ) / 2;
189 for ( i = 0 ; i < i_nb_bands ;i++)
191 /* We search the maximum on one scale */
192 for( j = xscale[i], y = 0; j< xscale[ i + 1 ]; j++ )
197 /* Calculate the height of the bar */
200 height[i] = log( y ) * 30;
201 if( height[i] > 380 )
207 /* Draw the bar now */
209 if( height[i] > peaks[i] )
211 peaks[i] = height[i];
213 else if( peaks[i] > 0 )
215 peaks[i] -= PEAK_SPEED;
216 if( peaks[i] < height[i] )
218 peaks[i] = height[i];
226 /* Decrease the bars if needed */
227 if( height[i] <= prev_heights[i] - BAR_DECREASE_SPEED )
229 height[i] = prev_heights[i];
230 height[i] -= BAR_DECREASE_SPEED;
232 prev_heights[i] = height[i];
234 if( peaks[i] > 0 && i_peak )
236 if( peaks[i] >= p_effect->i_height )
237 peaks[i] = p_effect->i_height - 2;
240 for( j = 0; j < i_band_width - 1; j++ )
242 for( k = 0; k < 3; k ++ )
245 *(p_picture->p[0].p_pixels +
246 ( p_effect->i_height - i_line -1 -k ) *
247 p_picture->p[0].i_pitch +
248 ( i_start + i_band_width*i + j ) )
251 *(p_picture->p[1].p_pixels +
252 ( ( p_effect->i_height - i_line ) / 2 - 1 -k/2 ) *
253 p_picture->p[1].i_pitch +
254 ( ( i_start + i_band_width * i + j ) /2 ) )
257 if( i_line + k - 0x0f > 0 )
259 if ( i_line + k - 0x0f < 0xff )
260 *(p_picture->p[2].p_pixels +
261 ( ( p_effect->i_height - i_line ) / 2 - 1 -k/2 ) *
262 p_picture->p[2].i_pitch +
263 ( ( i_start + i_band_width * i + j ) /2 ) )
264 = ( i_line + k ) - 0x0f;
266 *(p_picture->p[2].p_pixels +
267 ( ( p_effect->i_height - i_line ) / 2 - 1 -k/2 ) *
268 p_picture->p[2].i_pitch +
269 ( ( i_start + i_band_width * i + j ) /2 ) )
274 *(p_picture->p[2].p_pixels +
275 ( ( p_effect->i_height - i_line ) / 2 - 1 -k/2 ) *
276 p_picture->p[2].i_pitch +
277 ( ( i_start + i_band_width * i + j ) /2 ) )
284 if(height[i] > p_effect->i_height)
285 height[i] = floor(p_effect->i_height );
287 for( i_line = 0; i_line < height[i]; i_line++ )
289 for( j = 0 ; j < i_band_width - 1; j++)
291 *(p_picture->p[0].p_pixels +
292 (p_effect->i_height - i_line - 1) *
293 p_picture->p[0].i_pitch +
294 ( i_start + i_band_width*i + j ) ) = 0xff;
296 *(p_picture->p[1].p_pixels +
297 ( ( p_effect->i_height - i_line ) / 2 - 1) *
298 p_picture->p[1].i_pitch +
299 ( ( i_start + i_band_width * i + j ) /2 ) ) = 0x00;
301 if( i_line - 0x0f > 0 )
303 if( i_line - 0x0f < 0xff )
304 *(p_picture->p[2].p_pixels +
305 ( ( p_effect->i_height - i_line ) / 2 - 1) *
306 p_picture->p[2].i_pitch +
307 ( ( i_start + i_band_width * i + j ) /2 ) ) =
310 *(p_picture->p[2].p_pixels +
311 ( ( p_effect->i_height - i_line ) / 2 - 1) *
312 p_picture->p[2].i_pitch +
313 ( ( i_start + i_band_width * i + j ) /2 ) ) =
318 *(p_picture->p[2].p_pixels +
319 ( ( p_effect->i_height - i_line ) / 2 - 1) *
320 p_picture->p[2].i_pitch +
321 ( ( i_start + i_band_width * i + j ) /2 ) ) =
328 fft_close( p_state );
336 /*****************************************************************************
337 * spectrometer_Run: derivative spectrum analysis
338 *****************************************************************************/
339 int spectrometer_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
340 const block_t * p_buffer , picture_t * p_picture)
342 #define Y(R,G,B) ((uint8_t)( (R * .299) + (G * .587) + (B * .114) ))
343 #define U(R,G,B) ((uint8_t)( (R * -.169) + (G * -.332) + (B * .500) + 128 ))
344 #define V(R,G,B) ((uint8_t)( (R * .500) + (G * -.419) + (B * -.0813) + 128 ))
345 float p_output[FFT_BUFFER_SIZE]; /* Raw FFT Result */
346 int *height; /* Bar heights */
347 int *peaks; /* Peaks */
348 int i_80_bands; /* number of bands : 80 if true else 20 */
349 int i_nb_bands; /* number of bands : 80 or 20 */
350 int i_band_width; /* width of bands */
351 int i_separ; /* Should we let blanks ? */
352 int i_amp; /* Vertical amplification */
353 int i_peak; /* Should we draw peaks ? */
355 int i_original; /* original spectrum graphic routine */
356 int i_rad; /* radius of circle of base of bands */
357 int i_sections; /* sections of spectranalysis */
358 int i_extra_width; /* extra width on peak */
359 int i_peak_height; /* height of peak */
360 int c; /* sentinel container of total spectral sections */
361 double band_sep_angle; /* angled separation between beginning of each band */
362 double section_sep_angle;/* " " ' " ' " " spectrum section */
363 int max_band_length; /* try not to go out of screen */
364 int i_show_base; /* Should we draw base of circle ? */
365 int i_show_bands; /* Should we draw bands ? */
366 //int i_invert_bands; /* do the bands point inward ? */
367 double a; /* for various misc angle situations in radians */
368 int x,y,xx,yy; /* various misc x/y */
369 char color1; /* V slide on a YUV color cube */
370 //char color2; /* U slide.. ? color2 fade color ? */
372 /* Horizontal scale for 20-band equalizer */
373 const int xscale1[]={0,1,2,3,4,5,6,7,8,11,15,20,27,
374 36,47,62,82,107,141,184,255};
376 /* Horizontal scale for 80-band equalizer */
377 const int xscale2[] =
378 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
379 19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
380 35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
381 52,53,54,55,56,57,58,59,61,63,67,72,77,82,87,93,99,105,
382 110,115,121,130,141,152,163,174,185,200,255};
384 const double y_scale = 3.60673760222; /* (log 256) */
386 fft_state *p_state; /* internal FFT data */
390 int16_t p_dest[FFT_BUFFER_SIZE]; /* Adapted FFT result */
391 int16_t p_buffer1[FFT_BUFFER_SIZE]; /* Buffer on which we perform
392 the FFT (first channel) */
393 float *p_buffl = /* Original buffer */
394 (float*)p_buffer->p_buffer;
396 int16_t *p_buffs; /* int16_t converted buffer */
397 int16_t *p_s16_buff; /* int16_t converted buffer */
399 p_s16_buff = malloc( p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t) );
403 p_buffs = p_s16_buff;
404 i_original = config_GetInt ( p_aout, "spect-show-original" );
405 i_80_bands = config_GetInt ( p_aout, "spect-80-bands" );
406 i_separ = config_GetInt ( p_aout, "spect-separ" );
407 i_amp = config_GetInt ( p_aout, "spect-amp" );
408 i_peak = config_GetInt ( p_aout, "spect-show-peaks" );
409 i_show_base = config_GetInt ( p_aout, "spect-show-base" );
410 i_show_bands = config_GetInt ( p_aout, "spect-show-bands" );
411 i_rad = config_GetInt ( p_aout, "spect-radius" );
412 i_sections = config_GetInt ( p_aout, "spect-sections" );
413 i_extra_width = config_GetInt ( p_aout, "spect-peak-width" );
414 i_peak_height = config_GetInt ( p_aout, "spect-peak-height" );
415 color1 = config_GetInt ( p_aout, "spect-color" );
428 if( !p_effect->p_data )
430 p_effect->p_data = calloc( 80, sizeof(int) );
431 if( !p_effect->p_data )
437 peaks =(int *)p_effect->p_data;
439 height = malloc( i_nb_bands * sizeof(int) );
446 /* Convert the buffer to int16_t */
447 /* Pasted from float32tos16.c */
448 for (i = p_buffer->i_nb_samples * p_effect->i_nb_chans; i--; )
450 union { float f; int32_t i; } u;
451 u.f = *p_buffl + 384.0;
452 if(u.i > 0x43c07fff ) * p_buffs = 32767;
453 else if ( u.i < 0x43bf8000 ) *p_buffs = -32768;
454 else *p_buffs = u.i - 0x43c00000;
456 p_buffl++ ; p_buffs++ ;
458 p_state = visual_fft_init();
461 msg_Err(p_aout,"unable to initialize FFT transform");
466 p_buffs = p_s16_buff;
467 for ( i = 0 ; i < FFT_BUFFER_SIZE; i++)
470 p_buffer1[i] = *p_buffs;
472 p_buffs += p_effect->i_nb_chans;
473 if( p_buffs >= &p_s16_buff[p_buffer->i_nb_samples * p_effect->i_nb_chans] )
474 p_buffs = p_s16_buff;
476 fft_perform( p_buffer1, p_output, p_state);
477 for(i = 0; i < FFT_BUFFER_SIZE; i++)
479 int sqrti = sqrt(p_output[i]);
480 p_dest[i] = sqrti >> 8;
483 i_nb_bands *= i_sections;
485 for ( i = 0 ; i< i_nb_bands/i_sections ;i++)
487 /* We search the maximum on one scale */
488 for( j = xscale[i] , y=0 ; j< xscale[ i + 1 ] ; j++ )
493 /* Calculate the height of the bar */
494 y >>=7;/* remove some noise */
498 height[i] = logy * y_scale;
507 /* Draw the bar now */
508 i_band_width = floor( p_effect->i_width / (i_nb_bands/i_sections)) ;
510 if( i_amp * height[i] > peaks[i])
512 peaks[i] = i_amp * height[i];
514 else if (peaks[i] > 0 )
516 peaks[i] -= PEAK_SPEED;
517 if( peaks[i] < i_amp * height[i] )
519 peaks[i] = i_amp * height[i];
527 if( i_original != 0 )
529 if( peaks[i] > 0 && i_peak )
531 if( peaks[i] >= p_effect->i_height )
532 peaks[i] = p_effect->i_height - 2;
535 for( j = 0 ; j< i_band_width - i_separ; j++)
537 for( k = 0 ; k< 3 ; k ++)
540 *(p_picture->p[0].p_pixels +
541 (p_effect->i_height - i_line -1 -k ) *
542 p_picture->p[0].i_pitch + (i_band_width*i +j) )
545 *(p_picture->p[1].p_pixels +
546 ( ( p_effect->i_height - i_line ) / 2 -1 -k/2 ) *
547 p_picture->p[1].i_pitch +
548 ( ( i_band_width * i + j ) /2 ) )
551 if( 0x04 * (i_line + k ) - 0x0f > 0 )
553 if ( 0x04 * (i_line + k ) -0x0f < 0xff)
554 *(p_picture->p[2].p_pixels +
555 ( ( p_effect->i_height - i_line ) / 2 - 1 -k/2 ) *
556 p_picture->p[2].i_pitch +
557 ( ( i_band_width * i + j ) /2 ) )
558 = ( 0x04 * ( i_line + k ) ) -0x0f ;
560 *(p_picture->p[2].p_pixels +
561 ( ( p_effect->i_height - i_line ) / 2 - 1 -k/2 ) *
562 p_picture->p[2].i_pitch +
563 ( ( i_band_width * i + j ) /2 ) )
568 *(p_picture->p[2].p_pixels +
569 ( ( p_effect->i_height - i_line ) / 2 - 1 -k/2 ) *
570 p_picture->p[2].i_pitch +
571 ( ( i_band_width * i + j ) /2 ) )
577 if(height[i] * i_amp > p_effect->i_height)
578 height[i] = floor(p_effect->i_height / i_amp );
580 for(i_line = 0 ; i_line < i_amp * height[i]; i_line ++ )
582 for( j = 0 ; j< i_band_width - i_separ ; j++)
584 *(p_picture->p[0].p_pixels +
585 (p_effect->i_height - i_line -1) *
586 p_picture->p[0].i_pitch + (i_band_width*i +j) ) = 0xff;
588 *(p_picture->p[1].p_pixels +
589 ( ( p_effect->i_height - i_line ) / 2 -1) *
590 p_picture->p[1].i_pitch +
591 ( ( i_band_width * i + j ) /2 ) ) = 0x00;
593 if( 0x04 * i_line - 0x0f > 0 )
595 if( 0x04 * i_line - 0x0f < 0xff )
596 *(p_picture->p[2].p_pixels +
597 ( ( p_effect->i_height - i_line ) / 2 - 1) *
598 p_picture->p[2].i_pitch +
599 ( ( i_band_width * i + j ) /2 ) ) =
600 ( 0x04 * i_line) -0x0f ;
602 *(p_picture->p[2].p_pixels +
603 ( ( p_effect->i_height - i_line ) / 2 - 1) *
604 p_picture->p[2].i_pitch +
605 ( ( i_band_width * i + j ) /2 ) ) =
610 *(p_picture->p[2].p_pixels +
611 ( ( p_effect->i_height - i_line ) / 2 - 1) *
612 p_picture->p[2].i_pitch +
613 ( ( i_band_width * i + j ) /2 ) ) =
621 band_sep_angle = 360.0 / i_nb_bands;
622 section_sep_angle = 360.0 / i_sections;
623 if( i_peak_height < 1 )
625 max_band_length = p_effect->i_height / 2 - ( i_rad + i_peak_height + 1 );
627 i_band_width = floor( 360 / i_nb_bands - i_separ );
628 if( i_band_width < 1 )
631 for( c = 0 ; c < i_sections ; c++ )
632 for( i = 0 ; i < (i_nb_bands / i_sections) ; i++ )
635 if( peaks[i] > 0 && i_peak )
637 if( peaks[i] >= p_effect->i_height )
638 peaks[i] = p_effect->i_height - 2;
641 /* circular line pattern(so color blend is more visible) */
642 for( j = 0 ; j < i_peak_height ; j++ )
644 //x = p_picture->p[0].i_pitch / 2;
645 x = p_effect->i_width / 2;
646 y = p_effect->i_height / 2;
649 for( k = 0 ; k < (i_band_width + i_extra_width) ; k++ )
653 a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) + k )
655 x += (double)( cos(a) * (double)( i_line + j + i_rad ) );
656 y += (double)( -sin(a) * (double)( i_line + j + i_rad ) );
658 *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
659 ) = 255;/* Y(R,G,B); */
664 *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
665 ) = 0;/* U(R,G,B); */
667 if( 0x04 * (i_line + k ) - 0x0f > 0 )
669 if ( 0x04 * (i_line + k ) -0x0f < 0xff)
670 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
671 ) = ( 0x04 * ( i_line + k ) ) -(color1-1);/* -V(R,G,B); */
673 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
674 ) = 255;/* V(R,G,B); */
678 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
679 ) = color1;/* V(R,G,B); */
685 if( (height[i] * i_amp) > p_effect->i_height )
686 height[i] = floor( p_effect->i_height / i_amp );
688 /* DO BASE OF BAND (mostly makes a circle) */
689 if( i_show_base != 0 )
691 //x = p_picture->p[0].i_pitch / 2;
692 x = p_effect->i_width / 2;
693 y = p_effect->i_height / 2;
695 a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) )
697 x += (double)( cos(a) * (double)i_rad );/* newb-forceful casting */
698 y += (double)( -sin(a) * (double)i_rad );
700 *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
701 ) = 255;/* Y(R,G,B); */
706 *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
707 ) = 0;/* U(R,G,B); */
709 if( 0x04 * i_line - 0x0f > 0 )
711 if( 0x04 * i_line -0x0f < 0xff)
712 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
713 ) = ( 0x04 * i_line) -(color1-1);/* -V(R,G,B); */
715 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
716 ) = 255;/* V(R,G,B); */
720 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
721 ) = color1;/* V(R,G,B); */
726 if( i_show_bands != 0 )
727 for( j = 0 ; j < i_band_width ; j++ )
729 x = p_effect->i_width / 2;
730 y = p_effect->i_height / 2;
733 a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) + j )
736 for( k = (i_rad+1) ; k < max_band_length ; k++ )
738 if( (k-i_rad) > height[i] )
743 x += (double)( cos(a) * (double)k );/* newbed! */
744 y += (double)( -sin(a) * (double)k );
746 *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
752 *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
755 if( 0x04 * i_line - 0x0f > 0 )
757 if ( 0x04 * i_line -0x0f < 0xff)
758 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
759 ) = ( 0x04 * i_line) -(color1-1);
761 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
766 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
773 fft_close( p_state );
782 /*****************************************************************************
783 * scope_Run: scope effect
784 *****************************************************************************/
785 int scope_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
786 const block_t * p_buffer , picture_t * p_picture)
792 uint8_t *ppp_area[2][3];
794 for( i_index = 0 ; i_index < 2 ; i_index++ )
796 for( int j = 0 ; j < 3 ; j++ )
798 ppp_area[i_index][j] =
799 p_picture->p[j].p_pixels + i_index * p_picture->p[j].i_lines
800 / 2 * p_picture->p[j].i_pitch;
804 for( i_index = 0, p_sample = (float *)p_buffer->p_buffer;
805 i_index < __MIN( p_effect->i_width, (int)p_buffer->i_nb_samples );
811 i_value = p_sample[p_effect->i_idx_left] * 127;
813 + p_picture->p[0].i_pitch * i_index / p_effect->i_width
814 + p_picture->p[0].i_lines * i_value / 512
815 * p_picture->p[0].i_pitch) = 0xbf;
817 + p_picture->p[1].i_pitch * i_index / p_effect->i_width
818 + p_picture->p[1].i_lines * i_value / 512
819 * p_picture->p[1].i_pitch) = 0xff;
823 i_value = p_sample[p_effect->i_idx_right] * 127;
825 + p_picture->p[0].i_pitch * i_index / p_effect->i_width
826 + p_picture->p[0].i_lines * i_value / 512
827 * p_picture->p[0].i_pitch) = 0x9f;
829 + p_picture->p[2].i_pitch * i_index / p_effect->i_width
830 + p_picture->p[2].i_lines * i_value / 512
831 * p_picture->p[2].i_pitch) = 0xdd;
833 p_sample += p_effect->i_nb_chans;
839 /*****************************************************************************
840 * vuMeter_Run: vu meter effect
841 *****************************************************************************/
842 int vuMeter_Run(visual_effect_t * p_effect, vlc_object_t *p_aout,
843 const block_t * p_buffer , picture_t * p_picture)
850 /* Compute the peack values */
851 for ( unsigned i = 0 ; i < p_buffer->i_nb_samples; i++ )
853 const float *p_sample = (float *)p_buffer->p_buffer;
856 ch = p_sample[p_effect->i_idx_left] * 256;
860 ch = p_sample[p_effect->i_idx_right] * 256;
864 p_sample += p_effect->i_nb_chans;
867 i_value_l = abs(i_value_l);
868 i_value_r = abs(i_value_r);
870 /* Stay under maximum value admited */
871 if ( i_value_l > 200 * M_PI_2 )
872 i_value_l = 200 * M_PI_2;
873 if ( i_value_r > 200 * M_PI_2 )
874 i_value_r = 200 * M_PI_2;
878 if( !p_effect->p_data )
880 /* Allocate memory to save hand positions */
881 p_effect->p_data = malloc( 2 * sizeof(float) );
882 i_value = p_effect->p_data;
883 i_value[0] = i_value_l;
884 i_value[1] = i_value_r;
888 /* Make the hands go down slowly if the current values are slower
890 i_value = p_effect->p_data;
892 if ( i_value_l > i_value[0] - 6 )
893 i_value[0] = i_value_l;
895 i_value[0] = i_value[0] - 6;
897 if ( i_value_r > i_value[1] - 6 )
898 i_value[1] = i_value_r;
900 i_value[1] = i_value[1] - 6;
907 for ( j = 0; j < 2; j++ )
909 /* Draw the two scales */
911 teta_grad = GRAD_ANGLE_MIN;
912 for ( teta = -M_PI_4; teta <= M_PI_4; teta = teta + 0.003 )
914 for ( unsigned i = 140; i <= 150; i++ )
916 y = i * cos(teta) + 20;
917 x = i * sin(teta) + 150 + 240 * j;
918 /* Compute the last color for the gradation */
919 if (teta >= teta_grad + GRAD_INCR && teta_grad <= GRAD_ANGLE_MAX)
921 teta_grad = teta_grad + GRAD_INCR;
924 *(p_picture->p[0].p_pixels +
925 (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
927 *(p_picture->p[1].p_pixels +
928 (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
930 *(p_picture->p[2].p_pixels +
931 (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch
932 + x / 2 ) = 0x4D + k;
936 /* Draw the two hands */
937 teta = (float)i_value[j] / 200 - M_PI_4;
938 for ( int i = 0; i <= 150; i++ )
940 y = i * cos(teta) + 20;
941 x = i * sin(teta) + 150 + 240 * j;
942 *(p_picture->p[0].p_pixels +
943 (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
945 *(p_picture->p[1].p_pixels +
946 (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
948 *(p_picture->p[2].p_pixels +
949 (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch
953 /* Draw the hand bases */
954 for ( teta = -M_PI_2; teta <= M_PI_2 + 0.01; teta = teta + 0.003 )
956 for ( int i = 0; i < 10; i++ )
958 y = i * cos(teta) + 20;
959 x = i * sin(teta) + 150 + 240 * j;
960 *(p_picture->p[0].p_pixels +
961 (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
963 *(p_picture->p[1].p_pixels +
964 (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
966 *(p_picture->p[2].p_pixels +
967 (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch