effects.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:35k
源码类别:

midi

开发平台:

Unix_Linux

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