1 /*****************************************************************************
2 * effects.c : Effects for the visualization system
3 *****************************************************************************
4 * Copyright (C) 2002 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>
43 #define GRAD_ANGLE_MIN 0.2
44 #define GRAD_ANGLE_MAX 0.5
45 #define GRAD_INCR 0.01
47 /*****************************************************************************
49 *****************************************************************************/
50 int dummy_Run( visual_effect_t * p_effect, aout_instance_t *p_aout,
51 aout_buffer_t * p_buffer , picture_t * p_picture)
53 VLC_UNUSED(p_effect); VLC_UNUSED(p_aout); VLC_UNUSED(p_buffer);
54 VLC_UNUSED(p_picture);
58 /*****************************************************************************
59 * spectrum_Run: spectrum analyser
60 *****************************************************************************/
61 int spectrum_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
62 aout_buffer_t * p_buffer , picture_t * p_picture)
64 float p_output[FFT_BUFFER_SIZE]; /* Raw FFT Result */
65 int *height; /* Bar heights */
66 int *peaks; /* Peaks */
67 int i_nb_bands; /* number of bands */
68 int i_band_width; /* width of bands */
69 int i_separ; /* Should we let blanks ? */
70 int i_amp; /* Vertical amplification */
71 int i_peak; /* Should we draw peaks ? */
73 /* Horizontal scale for 20-band equalizer */
74 const int xscale1[]={0,1,2,3,4,5,6,7,8,11,15,20,27,
75 36,47,62,82,107,141,184,255};
77 /* Horizontal scale for 80-band equalizer */
79 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
80 19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
81 35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
82 52,53,54,55,56,57,58,59,61,63,67,72,77,82,87,93,99,105,
83 110,115,121,130,141,152,163,174,185,200,255};
85 const double y_scale = 3.60673760222; /* (log 256) */
87 fft_state *p_state; /* internal FFT data */
91 int16_t p_dest[FFT_BUFFER_SIZE]; /* Adapted FFT result */
92 int16_t p_buffer1[FFT_BUFFER_SIZE]; /* Buffer on which we perform
93 the FFT (first channel) */
95 float *p_buffl = /* Original buffer */
96 (float*)p_buffer->p_buffer;
98 int16_t *p_buffs; /* int16_t converted buffer */
99 int16_t *p_s16_buff = NULL; /* int16_t converted buffer */
101 p_s16_buff = (int16_t*)malloc(
102 p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t));
106 msg_Err(p_aout,"out of memory");
110 p_buffs = p_s16_buff;
111 i_nb_bands = config_GetInt ( p_aout, "visual-nbbands" );
112 i_separ = config_GetInt( p_aout, "visual-separ" );
113 i_amp = config_GetInt ( p_aout, "visual-amp" );
114 i_peak = config_GetInt ( p_aout, "visual-peaks" );
116 if( i_nb_bands == 20)
126 if( !p_effect->p_data )
128 p_effect->p_data=(void *)malloc(i_nb_bands * sizeof(int) );
129 if( !p_effect->p_data)
131 msg_Err(p_aout,"out of memory");
134 peaks = (int *)p_effect->p_data;
135 for( i = 0 ; i < i_nb_bands ; i++)
143 peaks =(int *)p_effect->p_data;
147 height = (int *)malloc( i_nb_bands * sizeof(int) );
150 msg_Err(p_aout,"out of memory");
153 /* Convert the buffer to int16_t */
154 /* Pasted from float32tos16.c */
155 for (i = p_buffer->i_nb_samples * p_effect->i_nb_chans; i--; )
157 union { float f; int32_t i; } u;
158 u.f = *p_buffl + 384.0;
159 if(u.i > 0x43c07fff ) * p_buffs = 32767;
160 else if ( u.i < 0x43bf8000 ) *p_buffs = -32768;
161 else *p_buffs = u.i - 0x43c00000;
163 p_buffl++ ; p_buffs++ ;
165 p_state = visual_fft_init();
168 msg_Err(p_aout,"unable to initialize FFT transform");
171 p_buffs = p_s16_buff;
172 for ( i = 0 ; i < FFT_BUFFER_SIZE ; i++)
175 p_buffer1[i] = *p_buffs;
176 p_buffs = p_buffs + p_effect->i_nb_chans;
178 fft_perform( p_buffer1, p_output, p_state);
179 for(i= 0; i< FFT_BUFFER_SIZE ; i++ )
180 p_dest[i] = ( (int) sqrt( p_output [ i ] ) ) >> 8;
182 for ( i = 0 ; i< i_nb_bands ;i++)
184 /* We search the maximum on one scale */
185 for( j = xscale[i] , y=0 ; j< xscale[ i + 1 ] ; j++ )
190 /* Calculate the height of the bar */
191 y >>=7;/* remove some noise */
194 height[i] = (int)log(y)* y_scale;
203 /* Draw the bar now */
204 i_band_width = floor( p_effect->i_width / i_nb_bands) ;
206 if( i_amp * height[i] > peaks[i])
208 peaks[i] = i_amp * height[i];
210 else if (peaks[i] > 0 )
212 peaks[i] -= PEAK_SPEED;
213 if( peaks[i] < i_amp * height[i] )
215 peaks[i] = i_amp * height[i];
223 if( peaks[i] > 0 && i_peak )
225 if( peaks[i] >= p_effect->i_height )
226 peaks[i] = p_effect->i_height - 2;
229 for( j = 0 ; j< i_band_width - i_separ; j++)
231 for( k = 0 ; k< 3 ; k ++)
234 *(p_picture->p[0].p_pixels +
235 (p_picture->p[0].i_lines - i_line -1 -k ) *
236 p_picture->p[0].i_pitch + (i_band_width*i +j) )
239 *(p_picture->p[1].p_pixels +
240 (p_picture->p[1].i_lines - i_line /2 -1 -k/2 ) *
241 p_picture->p[1].i_pitch +
242 ( ( i_band_width * i + j ) /2 ) )
245 if( 0x04 * (i_line + k ) - 0x0f > 0 )
247 if ( 0x04 * (i_line + k ) -0x0f < 0xff)
248 *(p_picture->p[2].p_pixels +
249 (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
250 p_picture->p[2].i_pitch +
251 ( ( i_band_width * i + j ) /2 ) )
252 = ( 0x04 * ( i_line + k ) ) -0x0f ;
254 *(p_picture->p[2].p_pixels +
255 (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
256 p_picture->p[2].i_pitch +
257 ( ( i_band_width * i + j ) /2 ) )
262 *(p_picture->p[2].p_pixels +
263 (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
264 p_picture->p[2].i_pitch +
265 ( ( i_band_width * i + j ) /2 ) )
272 if(height[i] * i_amp > p_effect->i_height)
273 height[i] = floor(p_effect->i_height / i_amp );
275 for(i_line = 0 ; i_line < i_amp * height[i]; i_line ++ )
277 for( j = 0 ; j< i_band_width - i_separ ; j++)
279 *(p_picture->p[0].p_pixels +
280 (p_picture->p[0].i_lines - i_line -1) *
281 p_picture->p[0].i_pitch + (i_band_width*i +j) ) = 0xff;
283 *(p_picture->p[1].p_pixels +
284 (p_picture->p[1].i_lines - i_line /2 -1) *
285 p_picture->p[1].i_pitch +
286 ( ( i_band_width * i + j ) /2 ) ) = 0x00;
288 if( 0x04 * i_line - 0x0f > 0 )
290 if( 0x04 * i_line - 0x0f < 0xff )
291 *(p_picture->p[2].p_pixels +
292 (p_picture->p[2].i_lines - i_line /2 - 1) *
293 p_picture->p[2].i_pitch +
294 ( ( i_band_width * i + j ) /2 ) ) =
295 ( 0x04 * i_line) -0x0f ;
297 *(p_picture->p[2].p_pixels +
298 (p_picture->p[2].i_lines - i_line /2 - 1) *
299 p_picture->p[2].i_pitch +
300 ( ( i_band_width * i + j ) /2 ) ) =
305 *(p_picture->p[2].p_pixels +
306 (p_picture->p[2].i_lines - i_line /2 - 1) *
307 p_picture->p[2].i_pitch +
308 ( ( i_band_width * i + j ) /2 ) ) =
315 fft_close( p_state );
324 /*****************************************************************************
325 * spectrometer_Run: derivative spectrum analysis
326 *****************************************************************************/
327 int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
328 aout_buffer_t * p_buffer , picture_t * p_picture)
330 #define Y(R,G,B) ((uint8_t)( (R * .299) + (G * .587) + (B * .114) ))
331 #define U(R,G,B) ((uint8_t)( (R * -.169) + (G * -.332) + (B * .500) + 128 ))
332 #define V(R,G,B) ((uint8_t)( (R * .500) + (G * -.419) + (B * -.0813) + 128 ))
333 float p_output[FFT_BUFFER_SIZE]; /* Raw FFT Result */
334 int *height; /* Bar heights */
335 int *peaks; /* Peaks */
336 int i_nb_bands; /* number of bands */
337 int i_band_width; /* width of bands */
338 int i_separ; /* Should we let blanks ? */
339 int i_amp; /* Vertical amplification */
340 int i_peak; /* Should we draw peaks ? */
342 int i_original; /* original spectrum graphic routine */
343 int i_rad; /* radius of circle of base of bands */
344 int i_sections; /* sections of spectranalysis */
345 int i_extra_width; /* extra width on peak */
346 int i_peak_height; /* height of peak */
347 int c; /* sentinel container of total spectral sections */
348 double band_sep_angle; /* angled separation between beginning of each band */
349 double section_sep_angle;/* " " ' " ' " " spectrum section */
350 int max_band_length; /* try not to go out of screen */
351 int i_show_base; /* Should we draw base of circle ? */
352 int i_show_bands; /* Should we draw bands ? */
353 //int i_invert_bands; /* do the bands point inward ? */
354 double a; /* for various misc angle situations in radians */
355 int x,y,xx,yy; /* various misc x/y */
356 char color1; /* V slide on a YUV color cube */
357 //char color2; /* U slide.. ? color2 fade color ? */
359 /* Horizontal scale for 20-band equalizer */
360 const int xscale1[]={0,1,2,3,4,5,6,7,8,11,15,20,27,
361 36,47,62,82,107,141,184,255};
363 /* Horizontal scale for 80-band equalizer */
364 const int xscale2[] =
365 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
366 19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
367 35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
368 52,53,54,55,56,57,58,59,61,63,67,72,77,82,87,93,99,105,
369 110,115,121,130,141,152,163,174,185,200,255};
371 const double y_scale = 3.60673760222; /* (log 256) */
373 fft_state *p_state; /* internal FFT data */
377 int16_t p_dest[FFT_BUFFER_SIZE]; /* Adapted FFT result */
378 int16_t p_buffer1[FFT_BUFFER_SIZE]; /* Buffer on which we perform
379 the FFT (first channel) */
380 float *p_buffl = /* Original buffer */
381 (float*)p_buffer->p_buffer;
383 int16_t *p_buffs; /* int16_t converted buffer */
384 int16_t *p_s16_buff = NULL; /* int16_t converted buffer */
388 p_s16_buff = (int16_t*)malloc(
389 p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t));
394 p_buffs = p_s16_buff;
395 i_original = config_GetInt ( p_aout, "spect-show-original" );
396 i_nb_bands = config_GetInt ( p_aout, "spect-nbbands" );
397 i_separ = config_GetInt ( p_aout, "spect-separ" );
398 i_amp = config_GetInt ( p_aout, "spect-amp" );
399 i_peak = config_GetInt ( p_aout, "spect-show-peaks" );
400 i_show_base = config_GetInt ( p_aout, "spect-show-base" );
401 i_show_bands = config_GetInt ( p_aout, "spect-show-bands" );
402 i_rad = config_GetInt ( p_aout, "spect-radius" );
403 i_sections = config_GetInt ( p_aout, "spect-sections" );
404 i_extra_width = config_GetInt ( p_aout, "spect-peak-width" );
405 i_peak_height = config_GetInt ( p_aout, "spect-peak-height" );
406 color1 = config_GetInt ( p_aout, "spect-color" );
408 if( i_nb_bands == 20)
414 if( i_nb_bands > 80 )
419 if( !p_effect->p_data )
421 p_effect->p_data=(void *)malloc( i_nb_bands * sizeof(int) );
422 if( !p_effect->p_data )
427 peaks = (int *)p_effect->p_data;
428 for( i = 0 ; i < i_nb_bands ; i++ )
435 peaks =(int *)p_effect->p_data;
438 height = (int *)malloc( i_nb_bands * sizeof(int) );
441 free( p_effect->p_data );
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");
463 free( p_effect->p_data );
467 p_buffs = p_s16_buff;
468 for ( i = 0 ; i < FFT_BUFFER_SIZE ; i++)
471 p_buffer1[i] = *p_buffs;
472 p_buffs = p_buffs + p_effect->i_nb_chans;
474 fft_perform( p_buffer1, p_output, p_state);
475 for(i= 0; i< FFT_BUFFER_SIZE ; i++ )
476 p_dest[i] = ( (int) sqrt( p_output [ i ] ) ) >> 8;
478 i_nb_bands *= i_sections;
480 for ( i = 0 ; i< i_nb_bands/i_sections ;i++)
482 /* We search the maximum on one scale */
483 for( j = xscale[i] , y=0 ; j< xscale[ i + 1 ] ; j++ )
488 /* Calculate the height of the bar */
489 y >>=7;/* remove some noise */
492 height[i] = (int)log(y)* y_scale;
501 /* Draw the bar now */
502 i_band_width = floor( p_effect->i_width / (i_nb_bands/i_sections)) ;
504 if( i_amp * height[i] > peaks[i])
506 peaks[i] = i_amp * height[i];
508 else if (peaks[i] > 0 )
510 peaks[i] -= PEAK_SPEED;
511 if( peaks[i] < i_amp * height[i] )
513 peaks[i] = i_amp * height[i];
521 if( i_original != 0 )
523 if( peaks[i] > 0 && i_peak )
525 if( peaks[i] >= p_effect->i_height )
526 peaks[i] = p_effect->i_height - 2;
529 for( j = 0 ; j< i_band_width - i_separ; j++)
531 for( k = 0 ; k< 3 ; k ++)
534 *(p_picture->p[0].p_pixels +
535 (p_picture->p[0].i_lines - i_line -1 -k ) *
536 p_picture->p[0].i_pitch + (i_band_width*i +j) )
539 *(p_picture->p[1].p_pixels +
540 (p_picture->p[1].i_lines - i_line /2 -1 -k/2 ) *
541 p_picture->p[1].i_pitch +
542 ( ( i_band_width * i + j ) /2 ) )
545 if( 0x04 * (i_line + k ) - 0x0f > 0 )
547 if ( 0x04 * (i_line + k ) -0x0f < 0xff)
548 *(p_picture->p[2].p_pixels +
549 (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
550 p_picture->p[2].i_pitch +
551 ( ( i_band_width * i + j ) /2 ) )
552 = ( 0x04 * ( i_line + k ) ) -0x0f ;
554 *(p_picture->p[2].p_pixels +
555 (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
556 p_picture->p[2].i_pitch +
557 ( ( i_band_width * i + j ) /2 ) )
562 *(p_picture->p[2].p_pixels +
563 (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
564 p_picture->p[2].i_pitch +
565 ( ( i_band_width * i + j ) /2 ) )
571 if(height[i] * i_amp > p_effect->i_height)
572 height[i] = floor(p_effect->i_height / i_amp );
574 for(i_line = 0 ; i_line < i_amp * height[i]; i_line ++ )
576 for( j = 0 ; j< i_band_width - i_separ ; j++)
578 *(p_picture->p[0].p_pixels +
579 (p_picture->p[0].i_lines - i_line -1) *
580 p_picture->p[0].i_pitch + (i_band_width*i +j) ) = 0xff;
582 *(p_picture->p[1].p_pixels +
583 (p_picture->p[1].i_lines - i_line /2 -1) *
584 p_picture->p[1].i_pitch +
585 ( ( i_band_width * i + j ) /2 ) ) = 0x00;
587 if( 0x04 * i_line - 0x0f > 0 )
589 if( 0x04 * i_line - 0x0f < 0xff )
590 *(p_picture->p[2].p_pixels +
591 (p_picture->p[2].i_lines - i_line /2 - 1) *
592 p_picture->p[2].i_pitch +
593 ( ( i_band_width * i + j ) /2 ) ) =
594 ( 0x04 * i_line) -0x0f ;
596 *(p_picture->p[2].p_pixels +
597 (p_picture->p[2].i_lines - i_line /2 - 1) *
598 p_picture->p[2].i_pitch +
599 ( ( i_band_width * i + j ) /2 ) ) =
604 *(p_picture->p[2].p_pixels +
605 (p_picture->p[2].i_lines - i_line /2 - 1) *
606 p_picture->p[2].i_pitch +
607 ( ( i_band_width * i + j ) /2 ) ) =
615 band_sep_angle = 360.0 / i_nb_bands;
616 section_sep_angle = 360.0 / i_sections;
617 if( i_peak_height < 1 )
619 max_band_length = p_picture->p[0].i_lines / 2 - ( i_rad + i_peak_height + 1 );
621 i_band_width = floor( 360 / i_nb_bands - i_separ );
622 if( i_band_width < 1 )
625 for( c = 0 ; c < i_sections ; c++ )
626 for( i = 0 ; i < (i_nb_bands / i_sections) ; i++ )
629 if( peaks[i] > 0 && i_peak )
631 if( peaks[i] >= p_effect->i_height )
632 peaks[i] = p_effect->i_height - 2;
635 /* circular line pattern(so color blend is more visible) */
636 for( j = 0 ; j < i_peak_height ; j++ )
638 x = p_picture->p[0].i_pitch / 2;
639 y = p_picture->p[0].i_lines / 2;
642 for( k = 0 ; k < (i_band_width + i_extra_width) ; k++ )
646 a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) + k )
648 x += (double)( cos(a) * (double)( i_line + j + i_rad ) );
649 y += (double)( -sin(a) * (double)( i_line + j + i_rad ) );
651 *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
652 ) = 255;/* Y(R,G,B); */
657 *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
658 ) = 0;/* U(R,G,B); */
660 if( 0x04 * (i_line + k ) - 0x0f > 0 )
662 if ( 0x04 * (i_line + k ) -0x0f < 0xff)
663 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
664 ) = ( 0x04 * ( i_line + k ) ) -(color1-1);/* -V(R,G,B); */
666 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
667 ) = 255;/* V(R,G,B); */
671 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
672 ) = color1;/* V(R,G,B); */
678 if( (height[i] * i_amp) > p_effect->i_height )
679 height[i] = floor( p_effect->i_height / i_amp );
681 /* DO BASE OF BAND (mostly makes a circle) */
682 if( i_show_base != 0 )
684 x = p_picture->p[0].i_pitch / 2;
685 y = p_picture->p[0].i_lines / 2;
687 a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) )
689 x += (double)( cos(a) * (double)i_rad );/* newb-forceful casting */
690 y += (double)( -sin(a) * (double)i_rad );
692 *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
693 ) = 255;/* Y(R,G,B); */
698 *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
699 ) = 0;/* U(R,G,B); */
701 if( 0x04 * i_line - 0x0f > 0 )
703 if( 0x04 * i_line -0x0f < 0xff)
704 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
705 ) = ( 0x04 * i_line) -(color1-1);/* -V(R,G,B); */
707 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
708 ) = 255;/* V(R,G,B); */
712 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
713 ) = color1;/* V(R,G,B); */
718 if( i_show_bands != 0 )
719 for( j = 0 ; j < i_band_width ; j++ )
721 x = p_picture->p[0].i_pitch / 2;
722 y = p_picture->p[0].i_lines / 2;
725 a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) + j )
728 for( k = (i_rad+1) ; k < max_band_length ; k++ )
730 if( (k-i_rad) > height[i] )
735 x += (double)( cos(a) * (double)k );/* newbed! */
736 y += (double)( -sin(a) * (double)k );
738 *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
744 *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
747 if( 0x04 * i_line - 0x0f > 0 )
749 if ( 0x04 * i_line -0x0f < 0xff)
750 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
751 ) = ( 0x04 * i_line) -(color1-1);
753 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
758 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
765 fft_close( p_state );
774 /*****************************************************************************
775 * scope_Run: scope effect
776 *****************************************************************************/
777 int scope_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
778 aout_buffer_t * p_buffer , picture_t * p_picture)
783 uint8_t *ppp_area[2][3];
786 for( i_index = 0 ; i_index < 2 ; i_index++ )
789 for( j = 0 ; j < 3 ; j++ )
791 ppp_area[i_index][j] =
792 p_picture->p[j].p_pixels + i_index * p_picture->p[j].i_lines
793 / 2 * p_picture->p[j].i_pitch;
797 for( i_index = 0, p_sample = (float *)p_buffer->p_buffer;
798 i_index < p_effect->i_width;
804 i_value = (*p_sample++ +1) * 127;
806 + p_picture->p[0].i_pitch * i_index / p_effect->i_width
807 + p_picture->p[0].i_lines * i_value / 512
808 * p_picture->p[0].i_pitch) = 0xbf;
810 + p_picture->p[1].i_pitch * i_index / p_effect->i_width
811 + p_picture->p[1].i_lines * i_value / 512
812 * p_picture->p[1].i_pitch) = 0xff;
816 i_value = ( *p_sample++ +1 ) * 127;
818 + p_picture->p[0].i_pitch * i_index / p_effect->i_width
819 + p_picture->p[0].i_lines * i_value / 512
820 * p_picture->p[0].i_pitch) = 0x9f;
822 + p_picture->p[2].i_pitch * i_index / p_effect->i_width
823 + p_picture->p[2].i_lines * i_value / 512
824 * p_picture->p[2].i_pitch) = 0xdd;
830 /*****************************************************************************
831 * vuMeter_Run: vu meter effect
832 *****************************************************************************/
833 int vuMeter_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
834 aout_buffer_t * p_buffer , picture_t * p_picture)
838 float *p_sample = (float *)p_buffer->p_buffer;
843 /* Compute the peack values */
844 for ( i = 0 ; i < 1024; i++ )
846 ch = (*p_sample++) * 256;
850 ch = (*p_sample++) * 256;
855 i_value_l = abs(i_value_l);
856 i_value_r = abs(i_value_r);
858 /* Stay under maximum value admited */
859 if ( i_value_l > 200 * M_PI_2 )
860 i_value_l = 200 * M_PI_2;
861 if ( i_value_r > 200 * M_PI_2 )
862 i_value_r = 200 * M_PI_2;
866 if( !p_effect->p_data )
868 /* Allocate memory to save hand positions */
869 p_effect->p_data = (void *)malloc( 2 * sizeof(float) );
870 i_value = p_effect->p_data;
871 i_value[0] = i_value_l;
872 i_value[1] = i_value_r;
876 /* Make the hands go down slowly if the current values are slower
878 i_value = p_effect->p_data;
880 if ( i_value_l > i_value[0] - 6 )
881 i_value[0] = i_value_l;
883 i_value[0] = i_value[0] - 6;
885 if ( i_value_r > i_value[1] - 6 )
886 i_value[1] = i_value_r;
888 i_value[1] = i_value[1] - 6;
895 for ( j = 0; j < 2; j++ )
897 /* Draw the two scales */
899 teta_grad = GRAD_ANGLE_MIN;
900 for ( teta = -M_PI_4; teta <= M_PI_4; teta = teta + 0.003 )
902 for ( i = 140; i <= 150; i++ )
904 y = i * cos(teta) + 20;
905 x = i * sin(teta) + 150 + 240 * j;
906 /* Compute the last color for the gradation */
907 if (teta >= teta_grad + GRAD_INCR && teta_grad <= GRAD_ANGLE_MAX)
909 teta_grad = teta_grad + GRAD_INCR;
912 *(p_picture->p[0].p_pixels +
913 (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
915 *(p_picture->p[1].p_pixels +
916 (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
918 *(p_picture->p[2].p_pixels +
919 (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch
920 + x / 2 ) = 0x4D + k;
924 /* Draw the two hands */
925 teta = (float)i_value[j] / 200 - M_PI_4;
926 for ( i = 0; i <= 150; i++ )
928 y = i * cos(teta) + 20;
929 x = i * sin(teta) + 150 + 240 * j;
930 *(p_picture->p[0].p_pixels +
931 (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
933 *(p_picture->p[1].p_pixels +
934 (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
936 *(p_picture->p[2].p_pixels +
937 (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch
941 /* Draw the hand bases */
942 for ( teta = -M_PI_2; teta <= M_PI_2 + 0.01; teta = teta + 0.003 )
944 for ( i = 0; i < 10; i++ )
946 y = i * cos(teta) + 20;
947 x = i * sin(teta) + 150 + 240 * j;
948 *(p_picture->p[0].p_pixels +
949 (p_picture->p[0].i_lines - y - 1 ) * p_picture->p[0].i_pitch
951 *(p_picture->p[1].p_pixels +
952 (p_picture->p[1].i_lines - y / 2 - 1 ) * p_picture->p[1].i_pitch
954 *(p_picture->p[2].p_pixels +
955 (p_picture->p[2].i_lines - y / 2 - 1 ) * p_picture->p[2].i_pitch