]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/channel_mixer/mono.c
No need to test for p_sys != NULL as it's already tested in the constructor.
[vlc] / modules / audio_filter / channel_mixer / mono.c
index 7e4af3d792bfe3ea1ac0efbba3383d93aac8c9a5..56d047e696ac34648c3b50f72fdaf034d0c7a83b 100644 (file)
@@ -37,7 +37,6 @@
 
 #include <vlc_common.h>
 #include <vlc_plugin.h>
-#include <vlc_es.h>
 #include <vlc_block.h>
 #include <vlc_filter.h>
 #include <vlc_aout.h>
@@ -108,6 +107,10 @@ static const uint32_t pi_channels_out[] =
 vlc_module_begin ()
     set_description( N_("Audio filter for stereo to mono conversion") )
     set_capability( "audio filter2", 2 )
+    set_category( CAT_AUDIO )
+    set_subcategory( SUBCAT_AUDIO_MISC )
+    set_callbacks( OpenFilter, CloseFilter )
+    set_shortname( "Mono" )
 
     add_bool( MONO_CFG "downmix", true, NULL, MONO_DOWNMIX_TEXT,
               MONO_DOWNMIX_LONGTEXT, false )
@@ -115,10 +118,6 @@ vlc_module_begin ()
         MONO_CHANNEL_LONGTEXT, false )
         change_integer_list( pi_pos_values, ppsz_pos_descriptions, NULL )
 
-    set_category( CAT_AUDIO )
-    set_subcategory( SUBCAT_AUDIO_MISC )
-    set_callbacks( OpenFilter, CloseFilter )
-    set_shortname( "Mono" )
 vlc_module_end ()
 
 /* Init() and ComputeChannelOperations() -
@@ -381,14 +380,9 @@ static int OpenFilter( vlc_object_t *p_this )
     if( p_sys == NULL )
         return VLC_EGENERIC;
 
-    var_Create( p_this, MONO_CFG "downmix",
-                VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    p_sys->b_downmix = var_GetBool( p_this, MONO_CFG "downmix" );
-
-    var_Create( p_this, MONO_CFG "channel",
-                VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    p_sys->b_downmix = var_CreateGetBool( p_this, MONO_CFG "downmix" );
     p_sys->i_channel_selected =
-            (unsigned int) var_GetInteger( p_this, MONO_CFG "channel" );
+            (unsigned int) var_CreateGetInteger( p_this, MONO_CFG "channel" );
 
     if( p_sys->b_downmix )
     {
@@ -564,84 +558,77 @@ static void stereo2mono_downmix( aout_filter_t * p_filter,
     p_out = p_out_buf->p_buffer;
     i_out_size = p_out_buf->i_nb_bytes;
 
-    if( p_sys != NULL )
-    {
-        /* Slide the overflow buffer */
-        p_overflow = p_sys->p_overflow_buffer;
-        i_overflow_size = p_sys->i_overflow_buffer_size;
+    /* Slide the overflow buffer */
+    p_overflow = p_sys->p_overflow_buffer;
+    i_overflow_size = p_sys->i_overflow_buffer_size;
+
+    if ( i_out_size > i_overflow_size )
+        memcpy( p_out, p_overflow, i_overflow_size );
+    else
+        memcpy( p_out, p_overflow, i_out_size );
 
-        if ( i_out_size > i_overflow_size )
-            memcpy( p_out, p_overflow, i_overflow_size );
+    p_slide = p_sys->p_overflow_buffer;
+    while( p_slide < p_overflow + i_overflow_size )
+    {
+        if( p_slide + i_out_size < p_overflow + i_overflow_size )
+        {
+            memset( p_slide, 0, i_out_size );
+            if( p_slide + 2 * i_out_size < p_overflow + i_overflow_size )
+                memcpy( p_slide, p_slide + i_out_size, i_out_size );
+            else
+                memcpy( p_slide, p_slide + i_out_size,
+                        p_overflow + i_overflow_size - ( p_slide + i_out_size ) );
+        }
         else
-            memcpy( p_out, p_overflow, i_out_size );
+        {
+            memset( p_slide, 0, p_overflow + i_overflow_size - p_slide );
+        }
+        p_slide += i_out_size;
+    }
+
+    /* apply the atomic operations */
+    for( i = 0; i < p_sys->i_nb_atomic_operations; i++ )
+    {
+        /* shorter variable names */
+        i_source_channel_offset
+            = p_sys->p_atomic_operations[i].i_source_channel_offset;
+        i_dest_channel_offset
+            = p_sys->p_atomic_operations[i].i_dest_channel_offset;
+        i_delay = p_sys->p_atomic_operations[i].i_delay;
+        d_amplitude_factor
+            = p_sys->p_atomic_operations[i].d_amplitude_factor;
 
-        p_slide = p_sys->p_overflow_buffer;
-        while( p_slide < p_overflow + i_overflow_size )
+        if( p_out_buf->i_nb_samples > i_delay )
         {
-            if( p_slide + i_out_size < p_overflow + i_overflow_size )
+            /* current buffer coefficients */
+            for( j = 0; j < p_out_buf->i_nb_samples - i_delay; j++ )
             {
-                memset( p_slide, 0, i_out_size );
-                if( p_slide + 2 * i_out_size < p_overflow + i_overflow_size )
-                    memcpy( p_slide, p_slide + i_out_size, i_out_size );
-                else
-                    memcpy( p_slide, p_slide + i_out_size,
-                            p_overflow + i_overflow_size - ( p_slide + i_out_size ) );
+                ((int16_t*)p_out)[ (i_delay+j)*i_output_nb + i_dest_channel_offset ]
+                    += p_in[ j * i_input_nb + i_source_channel_offset ]
+                       * d_amplitude_factor;
             }
-            else
+
+            /* overflow buffer coefficients */
+            for( j = 0; j < i_delay; j++ )
             {
-                memset( p_slide, 0, p_overflow + i_overflow_size - p_slide );
+                ((int16_t*)p_overflow)[ j*i_output_nb + i_dest_channel_offset ]
+                    += p_in[ (p_out_buf->i_nb_samples - i_delay + j)
+                       * i_input_nb + i_source_channel_offset ]
+                       * d_amplitude_factor;
             }
-            p_slide += i_out_size;
         }
-
-        /* apply the atomic operations */
-        for( i = 0; i < p_sys->i_nb_atomic_operations; i++ )
+        else
         {
-            /* shorter variable names */
-            i_source_channel_offset
-                = p_sys->p_atomic_operations[i].i_source_channel_offset;
-            i_dest_channel_offset
-                = p_sys->p_atomic_operations[i].i_dest_channel_offset;
-            i_delay = p_sys->p_atomic_operations[i].i_delay;
-            d_amplitude_factor
-                = p_sys->p_atomic_operations[i].d_amplitude_factor;
-
-            if( p_out_buf->i_nb_samples > i_delay )
-            {
-                /* current buffer coefficients */
-                for( j = 0; j < p_out_buf->i_nb_samples - i_delay; j++ )
-                {
-                    ((int16_t*)p_out)[ (i_delay+j)*i_output_nb + i_dest_channel_offset ]
-                        += p_in[ j * i_input_nb + i_source_channel_offset ]
-                           * d_amplitude_factor;
-                }
-
-                /* overflow buffer coefficients */
-                for( j = 0; j < i_delay; j++ )
-                {
-                    ((int16_t*)p_overflow)[ j*i_output_nb + i_dest_channel_offset ]
-                        += p_in[ (p_out_buf->i_nb_samples - i_delay + j)
-                           * i_input_nb + i_source_channel_offset ]
-                           * d_amplitude_factor;
-                }
-            }
-            else
+            /* overflow buffer coefficients only */
+            for( j = 0; j < p_out_buf->i_nb_samples; j++ )
             {
-                /* overflow buffer coefficients only */
-                for( j = 0; j < p_out_buf->i_nb_samples; j++ )
-                {
-                    ((int16_t*)p_overflow)[ (i_delay - p_out_buf->i_nb_samples + j)
-                        * i_output_nb + i_dest_channel_offset ]
-                        += p_in[ j * i_input_nb + i_source_channel_offset ]
-                           * d_amplitude_factor;
-                }
+                ((int16_t*)p_overflow)[ (i_delay - p_out_buf->i_nb_samples + j)
+                                        * i_output_nb + i_dest_channel_offset ]
+                    += p_in[ j * i_input_nb + i_source_channel_offset ]
+                       * d_amplitude_factor;
             }
         }
     }
-    else
-    {
-        memset( p_out, 0, i_out_size );
-    }
 }
 
 /* Simple stereo to mono mixing. */