]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/converter/dtstofloat32.c
Preferences update :
[vlc] / modules / audio_filter / converter / dtstofloat32.c
index ec608644e478175d3d6fff58dbb9808055950e21..a76a21c0ff816975b8e93dafb7f6797cebbcf2b8 100644 (file)
@@ -52,6 +52,15 @@ static int  OpenFilter ( vlc_object_t * );
 static void CloseFilter( vlc_object_t * );
 static block_t *Convert( filter_t *, block_t * );
 
+/* libdts channel order */
+static const uint32_t pi_channels_in[] =
+{ AOUT_CHAN_CENTER, AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
+  AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_LFE, 0 };
+/* our internal channel order (WG-4 order) */
+static const uint32_t pi_channels_out[] =
+{ AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
+  AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 };
+
 /*****************************************************************************
  * Local structures
  *****************************************************************************/
@@ -62,6 +71,8 @@ struct filter_sys_t
     int i_flags; /* libdts flags, see dtsdec/doc/libdts.txt */
     vlc_bool_t b_dontwarn;
     int i_nb_channels; /* number of float32 per sample */
+
+    int pi_chan_table[AOUT_CHAN_MAX]; /* channel reordering */
 };
 
 /*****************************************************************************
@@ -76,6 +87,9 @@ struct filter_sys_t
     "listening room.")
 
 vlc_module_begin();
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_ACODEC );
+    set_shortname( _("DTS" ) );
     set_description( _("DTS Coherent Acoustics audio decoder") );
     add_bool( "dts-dynrng", 1, NULL, DYNRNG_TEXT, DYNRNG_LONGTEXT, VLC_FALSE );
     set_capability( "audio filter", 100 );
@@ -88,7 +102,7 @@ vlc_module_begin();
 vlc_module_end();
 
 /*****************************************************************************
- * Create: 
+ * Create:
  *****************************************************************************/
 static int Create( vlc_object_t *p_this )
 {
@@ -209,52 +223,28 @@ static int Open( vlc_object_t *p_this, filter_sys_t *p_sys,
         return VLC_EGENERIC;
     }
 
+    aout_CheckChannelReorder( pi_channels_in, pi_channels_out,
+                              output.i_physical_channels & AOUT_CHAN_PHYSMASK,
+                              p_sys->i_nb_channels,
+                              p_sys->pi_chan_table );
+
     return VLC_SUCCESS;
 }
 
 /*****************************************************************************
  * Interleave: helper function to interleave channels
  *****************************************************************************/
-static void Interleave( float * p_out, const float * p_in, int i_nb_channels )
+static void Interleave( float * p_out, const float * p_in, int i_nb_channels,
+                        int *pi_chan_table )
 {
-    /* We do not only have to interleave, but also reorder the channels
-     * Channel reordering according to number of output channels of libdts
-     * The reordering needs to be different for different channel configurations
-     * (3F2R, 1F2R etc), so this is only temporary.
-     * The WG-4 order is appropriate for stereo, quadrophonia, and 5.1 surround.
-     *
-     * 6 channel mode
-     * channel  libdts order    WG-4 order
-     * 0        C               // L
-     * 1        L               // R
-     * 2        R               // LS
-     * 3        LS              // RS
-     * 4        RS              // C
-     * 5        LFE             // LFE
-     *
-     * The libdts moves channels to the front if there are unused spaces, so
-     * there is no gap between channels. The translation table says which
-     * channel of the new stream is taken from which original channel [use
-     * the new channel as the array index, use the number you get from the
-     * array to address the original channel].
-     */
-
-    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 */
-    { 0, 1, 2, 3, 0, 0 },       /* 4 */
-    { 1, 2, 3, 4, 0, 0 },       /* 5 */
-    { 1, 2, 3, 4, 0, 5 }};      /* 6 */
+    /* We do not only have to interleave, but also reorder the channels. */
 
     int i, j;
     for ( j = 0; j < i_nb_channels; j++ )
     {
         for ( i = 0; i < 256; i++ )
         {
-            p_out[i * i_nb_channels + j] = p_in[translation[i_nb_channels][j]
-                                                 * 256 + i];
+            p_out[i * i_nb_channels + pi_chan_table[j]] = p_in[j * 256 + i];
         }
     }
 }
@@ -367,7 +357,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
         {
             /* Interleave the *$£%ù samples. */
             Interleave( (float *)(p_out_buf->p_buffer + i * i_bytes_per_block),
-                        p_samples, p_sys->i_nb_channels );
+                        p_samples, p_sys->i_nb_channels, p_sys->pi_chan_table);
         }
     }
 
@@ -445,15 +435,23 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block )
     aout_filter_t aout_filter;
     aout_buffer_t in_buf, out_buf;
     block_t *p_out;
+    int i_out_size;
 
-    int i_out_size = p_block->i_samples *
+    if( !p_block || !p_block->i_samples )
+    {
+        if( p_block ) p_block->pf_release( p_block );
+        return NULL;
+    }
+
+    i_out_size = p_block->i_samples *
       p_filter->fmt_out.audio.i_bitspersample *
-        p_filter->fmt_out.audio.i_channels;
+        p_filter->fmt_out.audio.i_channels / 8;
 
     p_out = p_filter->pf_audio_buffer_new( p_filter, i_out_size );
     if( !p_out )
     {
         msg_Warn( p_filter, "can't get output buffer" );
+        p_block->pf_release( p_block );
         return NULL;
     }
 
@@ -480,5 +478,7 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block )
     p_out->i_buffer = out_buf.i_nb_bytes;
     p_out->i_samples = out_buf.i_nb_samples;
 
+    p_block->pf_release( p_block );
+
     return p_out;
 }