[vlc-commits] trivial: fix upmixing case and handle dualmono

Ilkka Ollakka git at videolan.org
Fri Mar 14 13:51:21 CET 2014


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Thu Mar 13 11:49:44 2014 +0200| [af147ca1552414cd57aa5acf194fa1093df5dd94] | committer: Ilkka Ollakka

trivial: fix upmixing case and handle dualmono

Earlier commit for dualmono (from 2003) seemed to miss some cases
and reordering the if cases as I assume dualmono isn't most common
case in filter.

Ref #7261

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=af147ca1552414cd57aa5acf194fa1093df5dd94
---

 modules/audio_filter/channel_mixer/trivial.c |   29 ++++++++++++++------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/modules/audio_filter/channel_mixer/trivial.c b/modules/audio_filter/channel_mixer/trivial.c
index 86b9de0..b5d8457 100644
--- a/modules/audio_filter/channel_mixer/trivial.c
+++ b/modules/audio_filter/channel_mixer/trivial.c
@@ -105,14 +105,16 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
     if( i_input_nb >= i_output_nb )
     {
         p_out_buf = p_in_buf; /* mix in place */
-        p_out_buf->i_buffer = p_in_buf->i_buffer / i_input_nb * i_output_nb;
+        p_out_buf->i_buffer = p_in_buf->i_buffer * i_output_nb / i_input_nb;
     }
     else
     {
         p_out_buf = block_Alloc(
-                              p_in_buf->i_buffer / i_input_nb * i_output_nb );
+                              p_in_buf->i_buffer * i_output_nb / i_input_nb );
         if( !p_out_buf )
             goto out;
+        /* on upmixing case, zero out buffer */
+        memset( p_out_buf->p_buffer, 0, p_out_buf->i_buffer );
         p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
         p_out_buf->i_dts        = p_in_buf->i_dts;
         p_out_buf->i_pts        = p_in_buf->i_pts;
@@ -121,11 +123,18 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
 
     float * p_dest = (float *)p_out_buf->p_buffer;
     const float * p_src = (float *)p_in_buf->p_buffer;
+    const bool b_reverse_stereo = p_filter->fmt_out.audio.i_original_channels & AOUT_CHAN_REVERSESTEREO;
+    bool b_dualmono2stereo = (p_filter->fmt_in.audio.i_original_channels & AOUT_CHAN_DUALMONO );
+    b_dualmono2stereo &= (p_filter->fmt_out.audio.i_physical_channels & ( AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT ));
+    b_dualmono2stereo &= ((p_filter->fmt_out.audio.i_physical_channels & AOUT_CHAN_PHYSMASK) != (p_filter->fmt_in.audio.i_physical_channels & AOUT_CHAN_PHYSMASK));
 
-    if ( (p_filter->fmt_out.audio.i_original_channels & AOUT_CHAN_PHYSMASK)
-                != (p_filter->fmt_in.audio.i_original_channels & AOUT_CHAN_PHYSMASK)
-           && (p_filter->fmt_in.audio.i_original_channels & AOUT_CHAN_PHYSMASK)
-                == (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT) )
+    if( likely( !b_reverse_stereo && ! b_dualmono2stereo ) )
+    {
+        SparseCopy( p_dest, p_src, p_in_buf->i_nb_samples, i_output_nb,
+                    i_input_nb );
+    }
+    /* Special case from dual mono to stereo */
+    else if ( b_dualmono2stereo )
     {
         int i;
         /* This is a bit special. */
@@ -156,8 +165,7 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
             }
         }
     }
-    else if ( p_filter->fmt_out.audio.i_original_channels
-                                    & AOUT_CHAN_REVERSESTEREO )
+    else if ( b_reverse_stereo )
     {
         /* Reverse-stereo mode */
         int i;
@@ -171,11 +179,6 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
             p_src += 2;
         }
     }
-    else
-    {
-        SparseCopy( p_dest, p_src, p_in_buf->i_nb_samples, i_output_nb,
-                    i_input_nb );
-    }
 out:
     if( p_in_buf != p_out_buf )
         block_Release( p_in_buf );



More information about the vlc-commits mailing list