]> git.sesse.net Git - vlc/blob - modules/visualization/visual/effects.c
Another bunch of useless test.
[vlc] / modules / visualization / visual / effects.c
1 /*****************************************************************************
2  * effects.c : Effects for the visualization system
3  *****************************************************************************
4  * Copyright (C) 2002 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
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
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc/vlc.h>
32 #include <vlc_vout.h>
33 #include <vlc_aout.h>
34
35 #include "visual.h"
36 #include <math.h>
37
38 #include "fft.h"
39
40 #define PEAK_SPEED 1
41
42 /*****************************************************************************
43  * dummy_Run
44  *****************************************************************************/
45 int dummy_Run( visual_effect_t * p_effect, aout_instance_t *p_aout,
46                aout_buffer_t * p_buffer , picture_t * p_picture)
47 {
48     VLC_UNUSED(p_effect); VLC_UNUSED(p_aout); VLC_UNUSED(p_buffer);
49     VLC_UNUSED(p_picture);
50     return 0;
51 }
52
53 /*****************************************************************************
54  * spectrum_Run: spectrum analyser
55  *****************************************************************************/
56 int spectrum_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
57                  aout_buffer_t * p_buffer , picture_t * p_picture)
58 {
59     float p_output[FFT_BUFFER_SIZE];  /* Raw FFT Result  */
60     int *height;                      /* Bar heights */
61     int *peaks;                       /* Peaks */
62     int i_nb_bands;                   /* number of bands */
63     int i_band_width;                 /* width of bands */
64     int i_separ;                      /* Should we let blanks ? */
65     int i_amp;                        /* Vertical amplification */
66     int i_peak;                       /* Should we draw peaks ? */
67     char *psz_parse = NULL;           /* Args line */
68
69     /* Horizontal scale for 20-band equalizer */
70     const int xscale1[]={0,1,2,3,4,5,6,7,8,11,15,20,27,
71                         36,47,62,82,107,141,184,255};
72
73     /* Horizontal scale for 80-band equalizer */
74     const int xscale2[] =
75     {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
76      19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
77      35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
78      52,53,54,55,56,57,58,59,61,63,67,72,77,82,87,93,99,105,
79      110,115,121,130,141,152,163,174,185,200,255};
80     const int *xscale;
81     const double y_scale =  3.60673760222;  /* (log 256) */
82
83     fft_state *p_state;                 /* internal FFT data */
84
85     int i , j , y , k;
86     int i_line;
87     int16_t p_dest[FFT_BUFFER_SIZE];      /* Adapted FFT result */
88     int16_t p_buffer1[FFT_BUFFER_SIZE];   /* Buffer on which we perform
89                                              the FFT (first channel) */
90
91     float *p_buffl =                     /* Original buffer */
92             (float*)p_buffer->p_buffer;
93
94     int16_t  *p_buffs;                    /* int16_t converted buffer */
95     int16_t  *p_s16_buff = NULL;                /* int16_t converted buffer */
96
97     p_s16_buff = (int16_t*)malloc(
98               p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t));
99
100     if( !p_s16_buff )
101     {
102         msg_Err(p_aout,"out of memory");
103         return -1;
104     }
105
106     p_buffs = p_s16_buff;
107     i_nb_bands = config_GetInt ( p_aout, "visual-nbbands" );
108     i_separ    = config_GetInt( p_aout, "visual-separ" );
109     i_amp     = config_GetInt ( p_aout, "visual-amp" );
110     i_peak     = config_GetInt ( p_aout, "visual-peaks" );
111
112     if( i_nb_bands == 20)
113     {
114         xscale = xscale1;
115     }
116     else
117     {
118         i_nb_bands = 80;
119         xscale = xscale2;
120     }
121
122     if( !p_effect->p_data )
123     {
124         p_effect->p_data=(void *)malloc(i_nb_bands * sizeof(int) );
125         if( !p_effect->p_data)
126         {
127             msg_Err(p_aout,"out of memory");
128             return -1;
129         }
130         peaks = (int *)p_effect->p_data;
131         for( i = 0 ; i < i_nb_bands ; i++)
132         {
133            peaks[i] = 0;
134         }
135
136     }
137     else
138     {
139         peaks =(int *)p_effect->p_data;
140     }
141
142
143     height = (int *)malloc( i_nb_bands * sizeof(int) );
144     if( !height)
145     {
146         msg_Err(p_aout,"out of memory");
147         return -1;
148     }
149     /* Convert the buffer to int16_t  */
150     /* Pasted from float32tos16.c */
151     for (i = p_buffer->i_nb_samples * p_effect->i_nb_chans; i--; )
152     {
153         union { float f; int32_t i; } u;
154         u.f = *p_buffl + 384.0;
155         if(u.i >  0x43c07fff ) * p_buffs = 32767;
156         else if ( u.i < 0x43bf8000 ) *p_buffs = -32768;
157         else *p_buffs = u.i - 0x43c00000;
158
159         p_buffl++ ; p_buffs++ ;
160     }
161     p_state  = visual_fft_init();
162     if( !p_state)
163     {
164         msg_Err(p_aout,"unable to initialize FFT transform");
165         return -1;
166     }
167     p_buffs = p_s16_buff;
168     for ( i = 0 ; i < FFT_BUFFER_SIZE ; i++)
169     {
170         p_output[i]    = 0;
171         p_buffer1[i] = *p_buffs;
172         p_buffs      = p_buffs + p_effect->i_nb_chans;
173     }
174     fft_perform( p_buffer1, p_output, p_state);
175     for(i= 0; i< FFT_BUFFER_SIZE ; i++ )
176         p_dest[i] = ( (int) sqrt( p_output [ i + 1 ] ) ) >> 8;
177
178     for ( i = 0 ; i< i_nb_bands ;i++)
179     {
180         /* We search the maximum on one scale */
181         for( j = xscale[i] , y=0 ; j< xscale[ i + 1 ] ; j++ )
182         {
183             if ( p_dest[j] > y )
184                  y = p_dest[j];
185         }
186         /* Calculate the height of the bar */
187         y >>=7;/* remove some noise */
188         if( y != 0)
189         {
190             height[i] = (int)log(y)* y_scale;
191                if(height[i] > 150)
192                   height[i] = 150;
193         }
194         else
195         {
196             height[i] = 0 ;
197         }
198
199         /* Draw the bar now */
200         i_band_width = floor( p_effect->i_width / i_nb_bands) ;
201
202         if( i_amp * height[i] > peaks[i])
203         {
204             peaks[i] = i_amp * height[i];
205         }
206         else if (peaks[i] > 0 )
207         {
208             peaks[i] -= PEAK_SPEED;
209             if( peaks[i] < i_amp * height[i] )
210             {
211                 peaks[i] = i_amp * height[i];
212             }
213             if( peaks[i] < 0 )
214             {
215                 peaks[i] = 0;
216             }
217         }
218
219         if( peaks[i] > 0 && i_peak )
220         {
221             if( peaks[i] >= p_effect->i_height )
222                 peaks[i] = p_effect->i_height - 2;
223             i_line = peaks[i];
224
225             for( j = 0 ; j< i_band_width - i_separ; j++)
226             {
227                for( k = 0 ; k< 3 ; k ++)
228                {
229                    /* Draw the peak */
230                      *(p_picture->p[0].p_pixels +
231                     (p_picture->p[0].i_lines - i_line -1 -k ) *
232                      p_picture->p[0].i_pitch + (i_band_width*i +j) )
233                                     = 0xff;
234
235                     *(p_picture->p[1].p_pixels +
236                      (p_picture->p[1].i_lines - i_line /2 -1 -k/2 ) *
237                      p_picture->p[1].i_pitch +
238                     ( ( i_band_width * i + j ) /2  ) )
239                                     = 0x00;
240
241                    if( 0x04 * (i_line + k ) - 0x0f > 0 )
242                    {
243                        if ( 0x04 * (i_line + k ) -0x0f < 0xff)
244                            *(p_picture->p[2].p_pixels  +
245                             (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
246                              p_picture->p[2].i_pitch +
247                              ( ( i_band_width * i + j ) /2  ) )
248                                     = ( 0x04 * ( i_line + k ) ) -0x0f ;
249                        else
250                            *(p_picture->p[2].p_pixels  +
251                             (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
252                              p_picture->p[2].i_pitch +
253                              ( ( i_band_width * i + j ) /2  ) )
254                                     = 0xff;
255                    }
256                    else
257                    {
258                         *(p_picture->p[2].p_pixels  +
259                          (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
260                          p_picture->p[2].i_pitch +
261                          ( ( i_band_width * i + j ) /2  ) )
262                                = 0x10 ;
263                    }
264                }
265             }
266         }
267
268         if(height[i] * i_amp > p_effect->i_height)
269             height[i] = floor(p_effect->i_height / i_amp );
270
271         for(i_line = 0 ; i_line < i_amp * height[i]; i_line ++ )
272         {
273             for( j = 0 ; j< i_band_width - i_separ ; j++)
274             {
275                *(p_picture->p[0].p_pixels +
276                  (p_picture->p[0].i_lines - i_line -1) *
277                   p_picture->p[0].i_pitch + (i_band_width*i +j) ) = 0xff;
278
279                 *(p_picture->p[1].p_pixels +
280                  (p_picture->p[1].i_lines - i_line /2 -1) *
281                  p_picture->p[1].i_pitch +
282                  ( ( i_band_width * i + j ) /2  ) ) = 0x00;
283
284                if( 0x04 * i_line - 0x0f > 0 )
285                {
286                     if( 0x04 * i_line - 0x0f < 0xff )
287                          *(p_picture->p[2].p_pixels  +
288                           (p_picture->p[2].i_lines - i_line /2 - 1) *
289                            p_picture->p[2].i_pitch +
290                            ( ( i_band_width * i + j ) /2  ) ) =
291                                ( 0x04 * i_line) -0x0f ;
292                     else
293                          *(p_picture->p[2].p_pixels  +
294                           (p_picture->p[2].i_lines - i_line /2 - 1) *
295                            p_picture->p[2].i_pitch +
296                            ( ( i_band_width * i + j ) /2  ) ) =
297                                        0xff;
298                }
299                else
300                {
301                     *(p_picture->p[2].p_pixels  +
302                      (p_picture->p[2].i_lines - i_line /2 - 1) *
303                      p_picture->p[2].i_pitch +
304                      ( ( i_band_width * i + j ) /2  ) ) =
305                             0x10 ;
306                }
307             }
308         }
309     }
310
311     fft_close( p_state );
312
313     free( p_s16_buff );
314     p_s16_buff = NULL;
315
316     free( height );
317     free( psz_parse );
318
319     return 0;
320 }
321
322
323 /*****************************************************************************
324  * spectrometer_Run: derivative spectrum analysis
325  *****************************************************************************/
326 int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
327                  aout_buffer_t * p_buffer , picture_t * p_picture)
328 {
329 #define Y(R,G,B) ((uint8_t)( (R * .299) + (G * .587) + (B * .114) ))
330 #define U(R,G,B) ((uint8_t)( (R * -.169) + (G * -.332) + (B * .500) + 128 ))
331 #define V(R,G,B) ((uint8_t)( (R * .500) + (G * -.419) + (B * -.0813) + 128 ))
332     float p_output[FFT_BUFFER_SIZE];  /* Raw FFT Result  */
333     int *height;                      /* Bar heights */
334     int *peaks;                       /* Peaks */
335     int i_nb_bands;                   /* number of bands */
336     int i_band_width;                 /* width of bands */
337     int i_separ;                      /* Should we let blanks ? */
338     int i_amp;                        /* Vertical amplification */
339     int i_peak;                       /* Should we draw peaks ? */
340
341     int i_original;          /* original spectrum graphic routine */
342     int i_rad;               /* radius of circle of base of bands */
343     int i_sections;          /* sections of spectranalysis */
344     int i_extra_width;       /* extra width on peak */
345     int i_peak_height;       /* height of peak */
346     int c;                   /* sentinel container of total spectral sections */
347     double band_sep_angle;   /* angled separation between beginning of each band */
348     double section_sep_angle;/* "   "    '     "    '    "     "    spectrum section */
349     int max_band_length;     /* try not to go out of screen */
350     int i_show_base;         /* Should we draw base of circle ? */
351     int i_show_bands;        /* Should we draw bands ? */
352     //int i_invert_bands;      /* do the bands point inward ? */
353     double a;                /* for various misc angle situations in radians */
354     int x,y,xx,yy;           /* various misc x/y */
355     char color1;             /* V slide on a YUV color cube */
356     //char color2;             /* U slide.. ?  color2 fade color ? */
357
358     char *psz_parse = NULL;           /* Args line */
359
360     /* Horizontal scale for 20-band equalizer */
361     const int xscale1[]={0,1,2,3,4,5,6,7,8,11,15,20,27,
362                         36,47,62,82,107,141,184,255};
363
364     /* Horizontal scale for 80-band equalizer */
365     const int xscale2[] =
366     {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,
367      19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,
368      35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
369      52,53,54,55,56,57,58,59,61,63,67,72,77,82,87,93,99,105,
370      110,115,121,130,141,152,163,174,185,200,255};
371     const int *xscale;
372     const double y_scale =  3.60673760222;  /* (log 256) */
373
374     fft_state *p_state;                 /* internal FFT data */
375
376     int i , j , k;
377     int i_line;
378     int16_t p_dest[FFT_BUFFER_SIZE];      /* Adapted FFT result */
379     int16_t p_buffer1[FFT_BUFFER_SIZE];   /* Buffer on which we perform
380                                              the FFT (first channel) */
381     float *p_buffl =                     /* Original buffer */
382             (float*)p_buffer->p_buffer;
383
384     int16_t  *p_buffs;                    /* int16_t converted buffer */
385     int16_t  *p_s16_buff = NULL;                /* int16_t converted buffer */
386
387     i_line = 0;
388
389     p_s16_buff = (int16_t*)malloc(
390               p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t));
391
392     if( !p_s16_buff )
393     {
394         msg_Err(p_aout,"out of memory");
395         return -1;
396     }
397
398     p_buffs = p_s16_buff;
399     i_original     = config_GetInt ( p_aout, "spect-show-original" );
400     i_nb_bands     = config_GetInt ( p_aout, "spect-nbbands" );
401     i_separ        = config_GetInt ( p_aout, "spect-separ" );
402     i_amp          = config_GetInt ( p_aout, "spect-amp" );
403     i_peak         = config_GetInt ( p_aout, "spect-show-peaks" );
404     i_show_base    = config_GetInt ( p_aout, "spect-show-base" );
405     i_show_bands   = config_GetInt ( p_aout, "spect-show-bands" );
406     i_rad          = config_GetInt ( p_aout, "spect-radius" );
407     i_sections     = config_GetInt ( p_aout, "spect-sections" );
408     i_extra_width  = config_GetInt ( p_aout, "spect-peak-width" );
409     i_peak_height  = config_GetInt ( p_aout, "spect-peak-height" );
410     color1         = config_GetInt ( p_aout, "spect-color" );
411
412     if( i_nb_bands == 20)
413     {
414         xscale = xscale1;
415     }
416     else
417     {
418         if( i_nb_bands > 80 )
419             i_nb_bands = 80;
420         xscale = xscale2;
421     }
422
423     if( !p_effect->p_data )
424     {
425         p_effect->p_data=(void *)malloc(i_nb_bands * sizeof(int) );
426         if( !p_effect->p_data)
427         {
428             msg_Err(p_aout,"out of memory");
429             return -1;
430         }
431         peaks = (int *)p_effect->p_data;
432         for( i = 0 ; i < i_nb_bands ; i++)
433         {
434            peaks[i] = 0;
435         }
436     }
437     else
438     {
439         peaks =(int *)p_effect->p_data;
440     }
441
442     height = (int *)malloc( i_nb_bands * sizeof(int) );
443     if( !height)
444     {
445         msg_Err(p_aout,"out of memory");
446         return -1;
447     }
448
449     /* Convert the buffer to int16_t  */
450     /* Pasted from float32tos16.c */
451     for (i = p_buffer->i_nb_samples * p_effect->i_nb_chans; i--; )
452     {
453         union { float f; int32_t i; } u;
454         u.f = *p_buffl + 384.0;
455         if(u.i >  0x43c07fff ) * p_buffs = 32767;
456         else if ( u.i < 0x43bf8000 ) *p_buffs = -32768;
457         else *p_buffs = u.i - 0x43c00000;
458
459         p_buffl++ ; p_buffs++ ;
460     }
461     p_state  = visual_fft_init();
462     if( !p_state)
463     {
464         msg_Err(p_aout,"unable to initialize FFT transform");
465         return -1;
466     }
467     p_buffs = p_s16_buff;
468     for ( i = 0 ; i < FFT_BUFFER_SIZE ; i++)
469     {
470         p_output[i]    = 0;
471         p_buffer1[i] = *p_buffs;
472         p_buffs      = p_buffs + p_effect->i_nb_chans;
473     }
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 + 1 ] ) ) >> 8;
477
478     i_nb_bands *= i_sections;
479
480     for ( i = 0 ; i< i_nb_bands/i_sections ;i++)
481     {
482         /* We search the maximum on one scale */
483         for( j = xscale[i] , y=0 ; j< xscale[ i + 1 ] ; j++ )
484         {
485             if ( p_dest[j] > y )
486                  y = p_dest[j];
487         }
488         /* Calculate the height of the bar */
489         y >>=7;/* remove some noise */
490         if( y != 0)
491         {
492             height[i] = (int)log(y)* y_scale;
493                if(height[i] > 150)
494                   height[i] = 150;
495         }
496         else
497         {
498             height[i] = 0 ;
499         }
500
501         /* Draw the bar now */
502         i_band_width = floor( p_effect->i_width / (i_nb_bands/i_sections)) ;
503
504         if( i_amp * height[i] > peaks[i])
505         {
506             peaks[i] = i_amp * height[i];
507         }
508         else if (peaks[i] > 0 )
509         {
510             peaks[i] -= PEAK_SPEED;
511             if( peaks[i] < i_amp * height[i] )
512             {
513                 peaks[i] = i_amp * height[i];
514             }
515             if( peaks[i] < 0 )
516             {
517                 peaks[i] = 0;
518             }
519         }
520
521         if( i_original != 0 )
522         {
523         if( peaks[i] > 0 && i_peak )
524         {
525             if( peaks[i] >= p_effect->i_height )
526                 peaks[i] = p_effect->i_height - 2;
527             i_line = peaks[i];
528
529             for( j = 0 ; j< i_band_width - i_separ; j++)
530             {
531                for( k = 0 ; k< 3 ; k ++)
532                {
533                    //* Draw the peak
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) )
537                                     = 0xff;
538
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  ) )
543                                     = 0x00;
544
545                    if( 0x04 * (i_line + k ) - 0x0f > 0 )
546                    {
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 ;
553                        else
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  ) )
558                                     = 0xff;
559                    }
560                    else
561                    {
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  ) )
566                                = 0x10 ;
567                    }
568                }
569             }
570         }
571         if(height[i] * i_amp > p_effect->i_height)
572             height[i] = floor(p_effect->i_height / i_amp );
573
574         for(i_line = 0 ; i_line < i_amp * height[i]; i_line ++ )
575         {
576             for( j = 0 ; j< i_band_width - i_separ ; j++)
577             {
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;
581
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;
586
587                if( 0x04 * i_line - 0x0f > 0 )
588                {
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 ;
595                     else
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  ) ) =
600                                        0xff;
601                }
602                else
603                {
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  ) ) =
608                             0x10 ;
609                }
610             }
611         }
612         }
613     }
614
615     band_sep_angle = 360.0 / i_nb_bands;
616     section_sep_angle = 360.0 / i_sections;
617     if( i_peak_height < 1 )
618         i_peak_height = 1;
619     max_band_length = p_picture->p[0].i_lines / 2 - ( i_rad + i_peak_height + 1 );
620
621     i_band_width = floor( 360 / i_nb_bands - i_separ );
622     if( i_band_width < 1 )
623         i_band_width = 1;
624
625     for( c = 0 ; c < i_sections ; c++ )
626     for( i = 0 ; i < (i_nb_bands / i_sections) ; i++ )
627     {
628         /* DO A PEAK */
629         if( peaks[i] > 0 && i_peak )
630         {
631             if( peaks[i] >= p_effect->i_height )
632                 peaks[i] = p_effect->i_height - 2;
633             i_line = peaks[i];
634
635             /* circular line pattern(so color blend is more visible) */
636             for( j = 0 ; j < i_peak_height ; j++ )
637             {
638                 x = p_picture->p[0].i_pitch / 2;
639                 y = p_picture->p[0].i_lines / 2;
640                 xx = x;
641                 yy = y;
642                 for( k = 0 ; k < (i_band_width + i_extra_width) ; k++ )
643                 {
644                     x = xx;
645                     y = yy;
646                     a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) + k )
647                         * 3.141592 / 180.0;
648                     x += (double)( cos(a) * (double)( i_line + j + i_rad ) );
649                     y += (double)( -sin(a) * (double)( i_line + j + i_rad ) );
650
651                     *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
652                     ) = 255;/* Y(R,G,B); */
653
654                     x /= 2;
655                     y /= 2;
656
657                     *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
658                     ) = 0;/* U(R,G,B); */
659
660                     if( 0x04 * (i_line + k ) - 0x0f > 0 )
661                     {
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); */
665                         else
666                             *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
667                             ) = 255;/* V(R,G,B); */
668                     }
669                     else
670                     {
671                         *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
672                         ) = color1;/* V(R,G,B); */
673                     }
674                 }
675             }
676         }
677
678         if( (height[i] * i_amp) > p_effect->i_height )
679             height[i] = floor( p_effect->i_height / i_amp );
680
681         /* DO BASE OF BAND (mostly makes a circle) */
682         if( i_show_base != 0 )
683         {
684             x = p_picture->p[0].i_pitch / 2;
685             y = p_picture->p[0].i_lines / 2;
686
687             a =  ( (i+1) * band_sep_angle + section_sep_angle * (c+1) )
688                 * 3.141592 / 180.0;
689             x += (double)( cos(a) * (double)i_rad );/* newb-forceful casting */
690             y += (double)( -sin(a) * (double)i_rad );
691
692             *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
693             ) = 255;/* Y(R,G,B); */
694
695             x /= 2;
696             y /= 2;
697
698             *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
699             ) = 0;/* U(R,G,B); */
700
701             if( 0x04 * i_line - 0x0f > 0 )
702             {
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); */
706                 else
707                     *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
708                     ) = 255;/* V(R,G,B); */
709             }
710             else
711             {
712                 *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
713                 ) = color1;/* V(R,G,B); */
714             }
715         }
716
717         /* DO A BAND */
718         if( i_show_bands != 0 )
719         for( j = 0 ; j < i_band_width ; j++ )
720         {
721             x = p_picture->p[0].i_pitch / 2;
722             y = p_picture->p[0].i_lines / 2;
723             xx = x;
724             yy = y;
725             a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) + j )
726                 * 3.141592/180.0;
727
728             for( k = (i_rad+1) ; k < max_band_length ; k++ )
729             {
730                 if( (k-i_rad) > height[i] )
731                     break;/* uhh.. */
732
733                 x = xx;
734                 y = yy;
735                 x += (double)( cos(a) * (double)k );/* newbed! */
736                 y += (double)( -sin(a) * (double)k );
737
738                 *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
739                 ) = 255;
740
741                 x /= 2;
742                 y /= 2;
743
744                 *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
745                 ) = 0;
746
747                 if( 0x04 * i_line - 0x0f > 0 )
748                 {
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);
752                     else
753                         *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
754                         ) = 255;
755                 }
756                 else
757                 {
758                     *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
759                     ) = color1;
760                 }
761             }
762         }
763     }
764
765     fft_close( p_state );
766
767     free( p_s16_buff );
768     p_s16_buff = NULL;
769
770     free( height );
771     free( psz_parse );
772
773     return 0;
774 }
775
776
777 /*****************************************************************************
778  * scope_Run: scope effect
779  *****************************************************************************/
780 int scope_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
781               aout_buffer_t * p_buffer , picture_t * p_picture)
782 {
783     VLC_UNUSED(p_aout);
784     int i_index;
785     float *p_sample ;
786     uint8_t *ppp_area[2][3];
787
788
789         for( i_index = 0 ; i_index < 2 ; i_index++ )
790         {
791             int j;
792             for( j = 0 ; j < 3 ; j++ )
793             {
794                 ppp_area[i_index][j] =
795                     p_picture->p[j].p_pixels + i_index * p_picture->p[j].i_lines
796                                 / 2 * p_picture->p[j].i_pitch;
797             }
798         }
799
800         for( i_index = 0, p_sample = (float *)p_buffer->p_buffer;
801              i_index < p_effect->i_width;
802              i_index++ )
803         {
804             uint8_t i_value;
805
806             /* Left channel */
807             i_value =  (*p_sample++ +1) * 127;
808             *(ppp_area[0][0]
809                + p_picture->p[0].i_pitch * i_index / p_effect->i_width
810                + p_picture->p[0].i_lines * i_value / 512
811                    * p_picture->p[0].i_pitch) = 0xbf;
812             *(ppp_area[0][1]
813                 + p_picture->p[1].i_pitch * i_index / p_effect->i_width
814                 + p_picture->p[1].i_lines * i_value / 512
815                    * p_picture->p[1].i_pitch) = 0xff;
816
817
818            /* Right channel */
819            i_value = ( *p_sample++ +1 ) * 127;
820            *(ppp_area[1][0]
821               + p_picture->p[0].i_pitch * i_index / p_effect->i_width
822               + p_picture->p[0].i_lines * i_value / 512
823                  * p_picture->p[0].i_pitch) = 0x9f;
824            *(ppp_area[1][2]
825               + p_picture->p[2].i_pitch * i_index / p_effect->i_width
826               + p_picture->p[2].i_lines * i_value / 512
827                 * p_picture->p[2].i_pitch) = 0xdd;
828         }
829         return 0;
830 }