]> git.sesse.net Git - vlc/blobdiff - modules/visualization/visual/effects.c
Visual: kill signedness warnings
[vlc] / modules / visualization / visual / effects.c
index 7eae6c95c59d8068e0dd421c81ee09daff31709d..d457baabed650dac0871905645577a7e97635ef4 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * effects.c : Effects for the visualization system
  *****************************************************************************
- * Copyright (C) 2002 the VideoLAN team
+ * Copyright (C) 2002-2009 the VideoLAN team
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@via.ecp.fr>
@@ -100,9 +100,7 @@ int spectrum_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
     int16_t  *p_buffs;                    /* int16_t converted buffer */
     int16_t  *p_s16_buff;                 /* int16_t converted buffer */
 
-    p_s16_buff = malloc(
-              p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t));
-
+    p_s16_buff = malloc( p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t));
     if( !p_s16_buff )
         return -1;
 
@@ -124,15 +122,15 @@ int spectrum_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
     if( !p_data )
     {
         p_effect->p_data = p_data = malloc( sizeof( spectrum_data ) );
-
-        p_data->peaks = calloc( 80, sizeof(int) );
-        p_data->prev_heights = calloc( 80, sizeof(int) );
-
-        if( !p_data)
+        if( !p_data )
         {
             free( p_s16_buff );
             return -1;
         }
+
+        p_data->peaks = calloc( 80, sizeof(int) );
+        p_data->prev_heights = calloc( 80, sizeof(int) );
+
         peaks = ( int * )p_data->peaks;
         prev_heights = ( int * )p_data->prev_heights;
     }
@@ -174,7 +172,11 @@ int spectrum_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
     {
         p_output[i]  = 0;
         p_buffer1[i] = *p_buffs;
-        p_buffs      = p_buffs + p_effect->i_nb_chans;
+
+        p_buffs += p_effect->i_nb_chans;
+        if( p_buffs >= &p_s16_buff[p_buffer->i_nb_samples * p_effect->i_nb_chans] )
+            p_buffs = p_s16_buff;
+
     }
     fft_perform( p_buffer1, p_output, p_state);
     for( i = 0; i< FFT_BUFFER_SIZE ; i++ )
@@ -393,13 +395,11 @@ int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
             (float*)p_buffer->p_buffer;
 
     int16_t  *p_buffs;                    /* int16_t converted buffer */
-    int16_t  *p_s16_buff = NULL;                /* int16_t converted buffer */
+    int16_t  *p_s16_buff;                /* int16_t converted buffer */
 
     i_line = 0;
 
-    p_s16_buff = (int16_t*)malloc(
-              p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t));
-
+    p_s16_buff = malloc( p_buffer->i_nb_samples * p_effect->i_nb_chans * sizeof(int16_t) );
     if( !p_s16_buff )
         return -1;
 
@@ -477,15 +477,21 @@ int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
         return -1;
     }
     p_buffs = p_s16_buff;
-    for ( i = 0 ; i < FFT_BUFFER_SIZE ; i++)
+    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;
+
+        p_buffs += p_effect->i_nb_chans;
+        if( p_buffs >= &p_s16_buff[p_buffer->i_nb_samples * p_effect->i_nb_chans] )
+            p_buffs = p_s16_buff;
     }
     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;
+    for(i = 0; i < FFT_BUFFER_SIZE; i++)
+    {
+        int sqrti = sqrt(p_output[i]);
+        p_dest[i] = sqrti >> 8;
+    }
 
     i_nb_bands *= i_sections;
 
@@ -501,9 +507,10 @@ int spectrometer_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
         y >>=7;/* remove some noise */
         if( y != 0)
         {
-            height[i] = (int)log(y)* y_scale;
-               if(height[i] > 150)
-                  height[i] = 150;
+            int logy = log(y);
+            height[i] = logy * y_scale;
+            if(height[i] > 150)
+                height[i] = 150;
         }
         else
         {
@@ -792,52 +799,53 @@ int scope_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
               aout_buffer_t * p_buffer , picture_t * p_picture)
 {
     VLC_UNUSED(p_aout);
+
     int i_index;
     float *p_sample ;
     uint8_t *ppp_area[2][3];
 
-
-        for( i_index = 0 ; i_index < 2 ; i_index++ )
+    for( i_index = 0 ; i_index < 2 ; i_index++ )
+    {
+        for( int j = 0 ; j < 3 ; j++ )
         {
-            int j;
-            for( j = 0 ; j < 3 ; j++ )
-            {
-                ppp_area[i_index][j] =
-                    p_picture->p[j].p_pixels + i_index * p_picture->p[j].i_lines
-                                / 2 * p_picture->p[j].i_pitch;
-            }
+            ppp_area[i_index][j] =
+                p_picture->p[j].p_pixels + i_index * p_picture->p[j].i_lines
+                / 2 * p_picture->p[j].i_pitch;
         }
+    }
 
-        for( i_index = 0, p_sample = (float *)p_buffer->p_buffer;
-             i_index < p_effect->i_width;
-             i_index++ )
-        {
-            uint8_t i_value;
-
-            /* Left channel */
-            i_value =  (*p_sample++ +1) * 127;
-            *(ppp_area[0][0]
-               + p_picture->p[0].i_pitch * i_index / p_effect->i_width
-               + p_picture->p[0].i_lines * i_value / 512
-                   * p_picture->p[0].i_pitch) = 0xbf;
-            *(ppp_area[0][1]
+    for( i_index = 0, p_sample = (float *)p_buffer->p_buffer;
+            i_index < __MIN( p_effect->i_width, (int)p_buffer->i_nb_samples );
+            i_index++ )
+    {
+        uint8_t i_value;
+
+        /* Left channel */
+        i_value =  p_sample[p_effect->i_idx_left] * 127;
+        *(ppp_area[0][0]
+                + p_picture->p[0].i_pitch * i_index / p_effect->i_width
+                + p_picture->p[0].i_lines * i_value / 512
+                * p_picture->p[0].i_pitch) = 0xbf;
+        *(ppp_area[0][1]
                 + p_picture->p[1].i_pitch * i_index / p_effect->i_width
                 + p_picture->p[1].i_lines * i_value / 512
-                   * p_picture->p[1].i_pitch) = 0xff;
-
-
-           /* Right channel */
-           i_value = ( *p_sample++ +1 ) * 127;
-           *(ppp_area[1][0]
-              + p_picture->p[0].i_pitch * i_index / p_effect->i_width
-              + p_picture->p[0].i_lines * i_value / 512
-                 * p_picture->p[0].i_pitch) = 0x9f;
-           *(ppp_area[1][2]
-              + p_picture->p[2].i_pitch * i_index / p_effect->i_width
-              + p_picture->p[2].i_lines * i_value / 512
+                * p_picture->p[1].i_pitch) = 0xff;
+
+
+        /* Right channel */
+        i_value = p_sample[p_effect->i_idx_right] * 127;
+        *(ppp_area[1][0]
+                + p_picture->p[0].i_pitch * i_index / p_effect->i_width
+                + p_picture->p[0].i_lines * i_value / 512
+                * p_picture->p[0].i_pitch) = 0x9f;
+        *(ppp_area[1][2]
+                + p_picture->p[2].i_pitch * i_index / p_effect->i_width
+                + p_picture->p[2].i_lines * i_value / 512
                 * p_picture->p[2].i_pitch) = 0xdd;
-        }
-        return 0;
+
+        p_sample += p_effect->i_nb_chans;
+    }
+    return 0;
 }
 
 
@@ -848,22 +856,25 @@ int vuMeter_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
               aout_buffer_t * p_buffer , picture_t * p_picture)
 {
         VLC_UNUSED(p_aout);
-        int i, j;
-        float *p_sample = (float *)p_buffer->p_buffer;
+        int j;
         float i_value_l = 0;
         float i_value_r = 0;
-        float ch;
 
         /* Compute the peack values */
-        for ( i = 0 ; i < 1024; i++ )
+        for ( unsigned i = 0 ; i < p_buffer->i_nb_samples; i++ )
         {
-                ch = (*p_sample++) * 256;
+                const float *p_sample = (float *)p_buffer->p_buffer;
+                float ch;
+
+                ch = p_sample[p_effect->i_idx_left] * 256;
                 if (ch > i_value_l)
                         i_value_l = ch;
 
-                ch = (*p_sample++) * 256;
+                ch = p_sample[p_effect->i_idx_right] * 256;
                 if (ch > i_value_r)
                         i_value_r = ch;
+
+                p_sample += p_effect->i_nb_chans;
         }
 
         i_value_l = abs(i_value_l);
@@ -913,7 +924,7 @@ int vuMeter_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
                 teta_grad = GRAD_ANGLE_MIN;
                 for ( teta = -M_PI_4; teta <= M_PI_4; teta = teta + 0.003 )
                 {
-                        for ( i = 140; i <= 150; i++ )
+                        for ( unsigned i = 140; i <= 150; i++ )
                         {
                                 y = i * cos(teta) + 20;
                                 x = i * sin(teta) + 150 + 240 * j;
@@ -937,7 +948,7 @@ int vuMeter_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
 
                 /* Draw the two hands */
                 teta = (float)i_value[j] / 200 - M_PI_4;
-                for ( i = 0; i <= 150; i++ )
+                for ( int i = 0; i <= 150; i++ )
                 {
                         y = i * cos(teta) + 20;
                         x = i * sin(teta) + 150 + 240 * j;
@@ -955,7 +966,7 @@ int vuMeter_Run(visual_effect_t * p_effect, aout_instance_t *p_aout,
                 /* Draw the hand bases */
                 for ( teta = -M_PI_2; teta <= M_PI_2 + 0.01; teta = teta + 0.003 )
                 {
-                        for ( i = 0; i < 10; i++ )
+                        for ( int i = 0; i < 10; i++ )
                         {
                                 y = i * cos(teta) + 20;
                                 x = i * sin(teta) + 150 + 240 * j;