[vlc-devel] Patch to a52tofloat32.c : enhanced multi channel support

Jean-Alexis Montignies ja at sente.ch
Sun Jul 4 15:50:21 CEST 2004


Hi,

This patch allows a52tofloat32.c to correctly interleave the buffers in  
different speaker configurations.
This is required for HALOutputUnit support on MacOSX.

The same patch should be applied to dtstofloat32.c or factorize  
somewhere else.

Regards,

Jean-Alexis
http://www.sente.ch/

Index: a52tofloat32.c
===================================================================
--- a52tofloat32.c      (revision 8113)
+++ a52tofloat32.c      (working copy)
@@ -218,8 +218,6 @@
   
/ 
************************************************************************ 
*****
   * Interleave: helper function to interleave channels
    
************************************************************************ 
*****/
-static void Interleave( float * p_out, const float * p_in, int  
i_nb_channels )
-{
      /* We do not only have to interleave, but also reorder the channels
       * Channel reordering according to number of output channels of  
libA52
       * The reordering needs to be different for different channel  
configurations
@@ -241,25 +239,104 @@
       * the new channel as the array index, use the number you get from  
the
       * array to address the original channel].
       */
+static void Interleave( aout_instance_t * p_aout, aout_filter_t *  
p_filter, float * p_out, const float * p_in )
+{
+    struct aout_filter_sys_t * p_sys = p_filter->p_sys;
+    int i_nb_channels = p_sys->i_nb_channels;
+    static const int *translation;
+//    static int debugCount = 0;
+
+    static const int translationMono[1] = { 0 };
+    static const int translationMonoLFE[2] = { 1, 0 };
+    static const int translationStereo[2] = { 0, 1 };
+    static const int translationStereoLFE[3] = { 1, 2, 0 };
+    static const int translation3F[3] = { 0, 2, 1 };
+    static const int translation3FLFE[4] = { 1, 3, 2, 0 };
+    static const int translation2F1R[3] = { 0, 1, 2 };
+    static const int translation2F1RLFE[4] = { 1, 2, 3, 0 };
+    static const int translation3F1R[4] = { 0, 2, 3, 1 };
+    static const int translation3F1RLFE[5] = { 1, 3, 4, 2, 0 };
+    static const int translation2F2R[4] = { 0, 1, 2, 3 };
+    static const int translation2F2RLFE[5] = { 1, 2, 3, 4, 0 };
+    static const int translation3F2R[5] = { 0, 2, 3, 4, 1 };
+    static const int translation3F2RLFE[6] = { 1, 3, 4, 5, 2 , 0};
+    static const int translationDefault[8] = { 0, 1, 2, 3, 4, 5, 6, 7};

-    static const int translation[7][6] =
-    {{ 0, 0, 0, 0, 0, 0 },      /* 0 channels (rarely used) */
-    { 0, 0, 0, 0, 0, 0 },       /* 1 ch */
-    { 0, 1, 0, 0, 0, 0 },       /* 2 */
-    { 1, 2, 0, 0, 0, 0 },       /* 3 */
-    { 1, 3, 2, 0, 0, 0 },       /* 4 */
-    { 1, 3, 4, 2, 0, 0 },       /* 5 */
-    { 1, 3, 4, 5, 2, 0 }};      /* 6 */
+//    debugCount ++;

-    int i, j;
-    for ( j = 0; j < i_nb_channels; j++ )
+    vlc_bool_t hasLFE = ( ( p_sys->i_flags & A52_LFE ) != 0 );
+
+/*
+    if ( ( debugCount & 255 ) == 0 ) {
+        msg_Dbg( p_aout, "hasLFE [%d] p_sys->i_flags [%d] nb_channels  
[%d]", hasLFE,p_sys->i_flags,i_nb_channels);
+    } */
+
+    switch ( p_sys->i_flags & A52_CHANNEL_MASK ) {
+        case A52_MONO:
+        case A52_CHANNEL1:
+        case A52_CHANNEL2:
+        case A52_DOLBY:
+        case A52_CHANNEL:
+        case A52_STEREO:
+
+        if ( hasLFE ) {
+            translation = (i_nb_channels == 3) ? translationStereoLFE  
: translationMonoLFE;
+        } else {
+            translation = (i_nb_channels == 2) ? translationStereo :  
translationMono;
+        }
+
+        break;
+
+        case A52_3F:
+
+        translation = hasLFE ? translation3FLFE : translation3F;
+
+        break;
+
+        case A52_2F1R:
+
+        translation = hasLFE ? translation2F1RLFE : translation2F1R;
+
+        break;
+
+        case A52_3F1R:
+
+        translation = hasLFE ? translation3F1RLFE : translation3F1R;
+
+        break;
+
+        case A52_2F2R:
+
+        translation = hasLFE ? translation2F2RLFE : translation2F2R;
+
+        break;
+
+        case A52_3F2R:
+
+        translation = hasLFE ? translation3F2RLFE : translation3F2R;
+
+        break;
+
+        default:
+        // we should never be in this case, but we should be idiot  
proof.
+        translation = translationDefault;
+    }
+
      {
-        for ( i = 0; i < 256; i++ )
+        int i, j;
+        for ( j = 0; j < i_nb_channels; j++ )
          {
-            p_out[i * i_nb_channels + j] =  
p_in[translation[i_nb_channels][j]
-                                                 * 256 + i];
+/*            if ( ( debugCount & 255 ) == 0 ) {
+                msg_Dbg( p_aout, "output [%d] <- [%d]",  
j,translation[j]);
+            } */
+
+            for ( i = 0; i < 256; i++ )
+            {
+                p_out[i * i_nb_channels + j] = p_in[translation[j] *  
256 + i];
+            }
          }
      }
+
  }

   
/ 
************************************************************************ 
*****
@@ -355,8 +432,8 @@
          else
          {
              /* Interleave the *$?%? samples. */
-            Interleave( (float *)(p_out_buf->p_buffer + i *  
i_bytes_per_block),
-                        p_samples, p_sys->i_nb_channels );
+            Interleave( p_aout, p_filter, (float  
*)(p_out_buf->p_buffer + i * i_bytes_per_block),
+                        p_samples );
          }
      }
  

-- 
This is the vlc-devel mailing-list, see http://www.videolan.org/vlc/
To unsubscribe, please read http://developers.videolan.org/lists.html
If you are in trouble, please contact <postmaster at videolan.org>



More information about the vlc-devel mailing list