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