+
+ /* Convert the buffer to int16_t */
+ /* Pasted from float32tos16.c */
+ for (i = p_buffer->i_nb_samples * p_effect->i_nb_chans; i--; )
+ {
+ union { float f; int32_t i; } u;
+ u.f = *p_buffl + 384.0;
+ if(u.i > 0x43c07fff ) * p_buffs = 32767;
+ else if ( u.i < 0x43bf8000 ) *p_buffs = -32768;
+ else *p_buffs = u.i - 0x43c00000;
+
+ p_buffl++ ; p_buffs++ ;
+ }
+ p_state = visual_fft_init();
+ if( !p_state)
+ {
+ msg_Err(p_aout,"unable to initialize FFT transform");
+ free( height );
+ free( p_effect->p_data );
+ free( p_s16_buff );
+ return -1;
+ }
+ p_buffs = p_s16_buff;
+ for ( i = 0 ; i < FFT_BUFFER_SIZE ; i++)
+ {
+ p_output[i] = 0;
+ p_buffer1[i] = *p_buffs;
+ p_buffs = p_buffs + p_effect->i_nb_chans;
+ }
+ fft_perform( p_buffer1, p_output, p_state);
+ for(i= 0; i< FFT_BUFFER_SIZE ; i++ )
+ p_dest[i] = ( (int) sqrt( p_output [ i ] ) ) >> 8;
+
+ i_nb_bands *= i_sections;
+
+ for ( i = 0 ; i< i_nb_bands/i_sections ;i++)
+ {
+ /* We search the maximum on one scale */
+ for( j = xscale[i] , y=0 ; j< xscale[ i + 1 ] ; j++ )
+ {
+ if ( p_dest[j] > y )
+ y = p_dest[j];
+ }
+ /* Calculate the height of the bar */
+ y >>=7;/* remove some noise */
+ if( y != 0)
+ {
+ height[i] = (int)log(y)* y_scale;
+ if(height[i] > 150)
+ height[i] = 150;
+ }
+ else
+ {
+ height[i] = 0 ;
+ }
+
+ /* Draw the bar now */
+ i_band_width = floor( p_effect->i_width / (i_nb_bands/i_sections)) ;
+
+ if( i_amp * height[i] > peaks[i])
+ {
+ peaks[i] = i_amp * height[i];
+ }
+ else if (peaks[i] > 0 )
+ {
+ peaks[i] -= PEAK_SPEED;
+ if( peaks[i] < i_amp * height[i] )
+ {
+ peaks[i] = i_amp * height[i];
+ }
+ if( peaks[i] < 0 )
+ {
+ peaks[i] = 0;
+ }
+ }
+
+ if( i_original != 0 )
+ {
+ if( peaks[i] > 0 && i_peak )
+ {
+ if( peaks[i] >= p_effect->i_height )
+ peaks[i] = p_effect->i_height - 2;
+ i_line = peaks[i];
+
+ for( j = 0 ; j< i_band_width - i_separ; j++)
+ {
+ for( k = 0 ; k< 3 ; k ++)
+ {
+ //* Draw the peak
+ *(p_picture->p[0].p_pixels +
+ (p_picture->p[0].i_lines - i_line -1 -k ) *
+ p_picture->p[0].i_pitch + (i_band_width*i +j) )
+ = 0xff;
+
+ *(p_picture->p[1].p_pixels +
+ (p_picture->p[1].i_lines - i_line /2 -1 -k/2 ) *
+ p_picture->p[1].i_pitch +
+ ( ( i_band_width * i + j ) /2 ) )
+ = 0x00;
+
+ if( 0x04 * (i_line + k ) - 0x0f > 0 )
+ {
+ if ( 0x04 * (i_line + k ) -0x0f < 0xff)
+ *(p_picture->p[2].p_pixels +
+ (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
+ p_picture->p[2].i_pitch +
+ ( ( i_band_width * i + j ) /2 ) )
+ = ( 0x04 * ( i_line + k ) ) -0x0f ;
+ else
+ *(p_picture->p[2].p_pixels +
+ (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
+ p_picture->p[2].i_pitch +
+ ( ( i_band_width * i + j ) /2 ) )
+ = 0xff;
+ }
+ else
+ {
+ *(p_picture->p[2].p_pixels +
+ (p_picture->p[2].i_lines - i_line /2 - 1 -k/2 ) *
+ p_picture->p[2].i_pitch +
+ ( ( i_band_width * i + j ) /2 ) )
+ = 0x10 ;
+ }
+ }
+ }
+ }
+ if(height[i] * i_amp > p_effect->i_height)
+ height[i] = floor(p_effect->i_height / i_amp );
+
+ for(i_line = 0 ; i_line < i_amp * height[i]; i_line ++ )
+ {
+ for( j = 0 ; j< i_band_width - i_separ ; j++)
+ {
+ *(p_picture->p[0].p_pixels +
+ (p_picture->p[0].i_lines - i_line -1) *
+ p_picture->p[0].i_pitch + (i_band_width*i +j) ) = 0xff;
+
+ *(p_picture->p[1].p_pixels +
+ (p_picture->p[1].i_lines - i_line /2 -1) *
+ p_picture->p[1].i_pitch +
+ ( ( i_band_width * i + j ) /2 ) ) = 0x00;
+
+ if( 0x04 * i_line - 0x0f > 0 )
+ {
+ if( 0x04 * i_line - 0x0f < 0xff )
+ *(p_picture->p[2].p_pixels +
+ (p_picture->p[2].i_lines - i_line /2 - 1) *
+ p_picture->p[2].i_pitch +
+ ( ( i_band_width * i + j ) /2 ) ) =
+ ( 0x04 * i_line) -0x0f ;
+ else
+ *(p_picture->p[2].p_pixels +
+ (p_picture->p[2].i_lines - i_line /2 - 1) *
+ p_picture->p[2].i_pitch +
+ ( ( i_band_width * i + j ) /2 ) ) =
+ 0xff;
+ }
+ else
+ {
+ *(p_picture->p[2].p_pixels +
+ (p_picture->p[2].i_lines - i_line /2 - 1) *
+ p_picture->p[2].i_pitch +
+ ( ( i_band_width * i + j ) /2 ) ) =
+ 0x10 ;
+ }
+ }
+ }
+ }
+ }
+
+ band_sep_angle = 360.0 / i_nb_bands;
+ section_sep_angle = 360.0 / i_sections;
+ if( i_peak_height < 1 )
+ i_peak_height = 1;
+ max_band_length = p_picture->p[0].i_lines / 2 - ( i_rad + i_peak_height + 1 );
+
+ i_band_width = floor( 360 / i_nb_bands - i_separ );
+ if( i_band_width < 1 )
+ i_band_width = 1;
+
+ for( c = 0 ; c < i_sections ; c++ )
+ for( i = 0 ; i < (i_nb_bands / i_sections) ; i++ )
+ {
+ /* DO A PEAK */
+ if( peaks[i] > 0 && i_peak )
+ {
+ if( peaks[i] >= p_effect->i_height )
+ peaks[i] = p_effect->i_height - 2;
+ i_line = peaks[i];
+
+ /* circular line pattern(so color blend is more visible) */
+ for( j = 0 ; j < i_peak_height ; j++ )
+ {
+ x = p_picture->p[0].i_pitch / 2;
+ y = p_picture->p[0].i_lines / 2;
+ xx = x;
+ yy = y;
+ for( k = 0 ; k < (i_band_width + i_extra_width) ; k++ )
+ {
+ x = xx;
+ y = yy;
+ a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) + k )
+ * 3.141592 / 180.0;
+ x += (double)( cos(a) * (double)( i_line + j + i_rad ) );
+ y += (double)( -sin(a) * (double)( i_line + j + i_rad ) );
+
+ *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
+ ) = 255;/* Y(R,G,B); */
+
+ x /= 2;
+ y /= 2;
+
+ *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
+ ) = 0;/* U(R,G,B); */
+
+ if( 0x04 * (i_line + k ) - 0x0f > 0 )
+ {
+ if ( 0x04 * (i_line + k ) -0x0f < 0xff)
+ *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
+ ) = ( 0x04 * ( i_line + k ) ) -(color1-1);/* -V(R,G,B); */
+ else
+ *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
+ ) = 255;/* V(R,G,B); */
+ }
+ else
+ {
+ *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
+ ) = color1;/* V(R,G,B); */
+ }
+ }
+ }
+ }
+
+ if( (height[i] * i_amp) > p_effect->i_height )
+ height[i] = floor( p_effect->i_height / i_amp );
+
+ /* DO BASE OF BAND (mostly makes a circle) */
+ if( i_show_base != 0 )
+ {
+ x = p_picture->p[0].i_pitch / 2;
+ y = p_picture->p[0].i_lines / 2;
+
+ a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) )
+ * 3.141592 / 180.0;
+ x += (double)( cos(a) * (double)i_rad );/* newb-forceful casting */
+ y += (double)( -sin(a) * (double)i_rad );
+
+ *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
+ ) = 255;/* Y(R,G,B); */
+
+ x /= 2;
+ y /= 2;
+
+ *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
+ ) = 0;/* U(R,G,B); */
+
+ if( 0x04 * i_line - 0x0f > 0 )
+ {
+ if( 0x04 * i_line -0x0f < 0xff)
+ *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
+ ) = ( 0x04 * i_line) -(color1-1);/* -V(R,G,B); */
+ else
+ *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
+ ) = 255;/* V(R,G,B); */
+ }
+ else
+ {
+ *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
+ ) = color1;/* V(R,G,B); */
+ }
+ }
+
+ /* DO A BAND */
+ if( i_show_bands != 0 )
+ for( j = 0 ; j < i_band_width ; j++ )
+ {
+ x = p_picture->p[0].i_pitch / 2;
+ y = p_picture->p[0].i_lines / 2;
+ xx = x;
+ yy = y;
+ a = ( (i+1) * band_sep_angle + section_sep_angle * (c+1) + j )
+ * 3.141592/180.0;
+
+ for( k = (i_rad+1) ; k < max_band_length ; k++ )
+ {
+ if( (k-i_rad) > height[i] )
+ break;/* uhh.. */
+
+ x = xx;
+ y = yy;
+ x += (double)( cos(a) * (double)k );/* newbed! */
+ y += (double)( -sin(a) * (double)k );
+
+ *(p_picture->p[0].p_pixels + x + y * p_picture->p[0].i_pitch
+ ) = 255;
+
+ x /= 2;
+ y /= 2;
+
+ *(p_picture->p[1].p_pixels + x + y * p_picture->p[1].i_pitch
+ ) = 0;
+
+ if( 0x04 * i_line - 0x0f > 0 )
+ {
+ if ( 0x04 * i_line -0x0f < 0xff)
+ *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
+ ) = ( 0x04 * i_line) -(color1-1);
+ else
+ *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
+ ) = 255;
+ }
+ else
+ {
+ *(p_picture->p[2].p_pixels + x + y * p_picture->p[2].i_pitch
+ ) = color1;
+ }
+ }
+ }
+ }
+
+ fft_close( p_state );
+
+ free( p_s16_buff );
+ free( height );
+