]> git.sesse.net Git - vlc/commitdiff
combine two channels into mono for the dowmix as last step.
authorJean-Paul Saman <jpsaman@videolan.org>
Tue, 29 Aug 2006 18:54:05 +0000 (18:54 +0000)
committerJean-Paul Saman <jpsaman@videolan.org>
Tue, 29 Aug 2006 18:54:05 +0000 (18:54 +0000)
modules/audio_filter/converter/mono.c

index 568fd081cdd5898d7a61718117324c7af1bcdd26..bc1918a6043a5e134d3d571e0b9cadfa5035ce80 100644 (file)
@@ -55,6 +55,8 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block );
 
 static unsigned int stereo_to_mono( aout_instance_t *, aout_filter_t *,
                                     aout_buffer_t *, aout_buffer_t * );
+static unsigned int mono( aout_instance_t *, aout_filter_t *,
+                                    aout_buffer_t *, aout_buffer_t * );
 static void stereo2mono_downmix( aout_instance_t *, aout_filter_t *,
                                  aout_buffer_t *, aout_buffer_t * );
 
@@ -349,7 +351,7 @@ static int Init( vlc_object_t *p_this, struct filter_sys_t * p_data,
         msg_Err( p_this, "out of memory" );
         return -1;
     }
-    memset( p_data->p_overflow_buffer, 0 , p_data->i_overflow_buffer_size );
+    memset( p_data->p_overflow_buffer, 0, p_data->i_overflow_buffer_size );
 
     /* end */
     return 0;
@@ -526,6 +528,8 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block )
     {
         stereo2mono_downmix( (aout_instance_t *)p_filter, &aout_filter,
                              &in_buf, &out_buf );
+        i_samples = mono( (aout_instance_t *)p_filter, &aout_filter,
+                           &out_buf, &in_buf );
     }
     else
     {
@@ -654,6 +658,26 @@ static void stereo2mono_downmix( aout_instance_t * p_aout, aout_filter_t * p_fil
     }
 }
 
+/* Simple stereo to mono mixing. */
+static unsigned int mono( aout_instance_t * p_aout, aout_filter_t *p_filter,
+                          aout_buffer_t *p_output, aout_buffer_t *p_input )
+{
+    filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
+    int16_t *p_in, *p_out;
+    unsigned int n = 0, r = 0;
+
+    p_in = (int16_t *) p_input->p_buffer;
+    p_out = (int16_t *) p_output->p_buffer;
+
+    while( n < (p_input->i_nb_samples * p_sys->i_nb_channels) )
+    {
+        p_out[r] = (p_in[n] + p_in[n+1]) >> 1;
+        r++;
+        n += 2;
+    }
+    return r;
+}
+
 /* Simple stereo to mono mixing. */
 static unsigned int stereo_to_mono( aout_instance_t * p_aout, aout_filter_t *p_filter,
                                     aout_buffer_t *p_output, aout_buffer_t *p_input )