]> git.sesse.net Git - vlc/commitdiff
* modules/codec/lpcm.c: support for 20/24 bits LPCM.
authorGildas Bazin <gbazin@videolan.org>
Tue, 1 Mar 2005 16:26:21 +0000 (16:26 +0000)
committerGildas Bazin <gbazin@videolan.org>
Tue, 1 Mar 2005 16:26:21 +0000 (16:26 +0000)
* modules/audio_filter/converter/s16tofloat32*, modules/audio_filter/format.c: s24l/s24b conversion routines.

include/audio_output.h
modules/audio_filter/converter/s16tofloat32.c
modules/audio_filter/converter/s16tofloat32swab.c
modules/audio_filter/format.c
modules/codec/lpcm.c
src/audio_output/common.c

index 5c664d5990b55772b78c6ce649eb70dec004795f..ae509b2ad90446f400070cbd64266d667d85b0cb 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * audio_output.h : audio output interface
  *****************************************************************************
- * Copyright (C) 2002 VideoLAN
+ * Copyright (C) 2002-2005 VideoLAN
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
 #ifdef WORDS_BIGENDIAN
 #   define AOUT_FMT_S16_NE VLC_FOURCC('s','1','6','b')
 #   define AOUT_FMT_U16_NE VLC_FOURCC('u','1','6','b')
+#   define AOUT_FMT_S24_NE VLC_FOURCC('s','2','4','b')
 #else
 #   define AOUT_FMT_S16_NE VLC_FOURCC('s','1','6','l')
 #   define AOUT_FMT_U16_NE VLC_FOURCC('u','1','6','l')
+#   define AOUT_FMT_S24_NE VLC_FOURCC('s','2','4','l')
 #endif
 
 #define AOUT_FMT_NON_LINEAR( p_format )                                    \
index d5350a512744fc75f820f20e8cf65af24de7727d..5b99b7a4ef57303f701c41de26d15f08f6b8d3d3 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * s16tofloat32.c : converter from signed 16 bits integer to float32
  *****************************************************************************
- * Copyright (C) 2002 VideoLAN
+ * Copyright (C) 2002-2005 VideoLAN
  * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
@@ -38,6 +38,8 @@ static int  Create    ( vlc_object_t * );
 
 static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
                         aout_buffer_t * );
+static void DoWork24  ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
+                        aout_buffer_t * );
 
 /*****************************************************************************
  * Module descriptor
@@ -59,7 +61,8 @@ static int Create( vlc_object_t *p_this )
 {
     aout_filter_t * p_filter = (aout_filter_t *)p_this;
 
-    if ( p_filter->input.i_format != AOUT_FMT_S16_NE
+    if ( ( p_filter->input.i_format != AOUT_FMT_S16_NE &&
+           p_filter->input.i_format != AOUT_FMT_S24_NE )
           || p_filter->output.i_format != VLC_FOURCC('f','l','3','2') )
     {
         return -1;
@@ -70,7 +73,11 @@ static int Create( vlc_object_t *p_this )
         return -1;
     }
 
-    p_filter->pf_do_work = DoWork;
+    if( p_filter->input.i_format == AOUT_FMT_S24_NE )
+        p_filter->pf_do_work = DoWork24;
+    else
+        p_filter->pf_do_work = DoWork;
+
     p_filter->b_in_place = VLC_TRUE;
 
     return 0;
@@ -109,3 +116,27 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * 2;
 }
 
+static void DoWork24( aout_instance_t * p_aout, aout_filter_t * p_filter,
+                      aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
+{
+    int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->input );
+
+    /* We start from the end because b_in_place is true */
+    uint8_t * p_in = (uint8_t *)p_in_buf->p_buffer + (i - 1) * 3;
+    float * p_out = (float *)p_out_buf->p_buffer + i - 1;
+
+    while( i-- )
+    {
+#ifdef WORDS_BIGENDIAN
+        *p_out = ((float)( (((int32_t)*(int16_t *)(p_in)) << 8) + p_in[2]))
+#else
+        *p_out = ((float)( (((int32_t)*(int16_t *)(p_in+1)) << 8) + p_in[0]))
+#endif
+            / 8388608.0;
+
+        p_in -= 3; p_out--;
+    }
+
+    p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
+    p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * 4 / 3;
+}
index 1e2f5ee87e2e28063af0ca4e38a05b58bc5d54fd..a18ac036319ca962e8e2af3a9f63948cc8a1c319 100644 (file)
@@ -2,7 +2,7 @@
  * s16tofloat32swab.c : converter from signed 16 bits integer to float32
  *                      with endianness change
  *****************************************************************************
- * Copyright (C) 2002 VideoLAN
+ * Copyright (C) 2002-2005 VideoLAN
  * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
@@ -49,6 +49,8 @@ static int  Create    ( vlc_object_t * );
 
 static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
                         aout_buffer_t * );
+static void DoWork24  ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
+                        aout_buffer_t * );
 
 /*****************************************************************************
  * Module descriptor
@@ -87,6 +89,17 @@ static int Create( vlc_object_t *p_this )
         return 0;
     }
 
+    if ( (p_filter->input.i_format == VLC_FOURCC('s','2','4','l') ||
+         p_filter->input.i_format == VLC_FOURCC('s','2','4','b'))
+         && p_filter->output.i_format == VLC_FOURCC('f','l','3','2')
+         && p_filter->input.i_format != AOUT_FMT_S24_NE )
+    {
+        p_filter->pf_do_work = DoWork24;
+        p_filter->b_in_place = VLC_TRUE;
+
+        return 0;
+    }
+
     return -1;
 }
 
@@ -139,3 +152,33 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * 2;
 }
 
+static void DoWork24( aout_instance_t * p_aout, aout_filter_t * p_filter,
+                      aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
+{
+    int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->input );
+
+    /* We start from the end because b_in_place is true */
+    uint8_t * p_in = (uint8_t *)p_in_buf->p_buffer + (i - 1) * 3;
+    float * p_out = (float *)p_out_buf->p_buffer + i - 1;
+
+    byte_t p_tmp[3];
+
+    while( i-- )
+    {
+        p_tmp[0] = p_in[2];
+        p_tmp[1] = p_in[1];
+        p_tmp[2] = p_in[0];
+
+#ifdef WORDS_BIGENDIAN
+        *p_out = ((float)( (((int32_t)*(int16_t *)(p_tmp)) << 8) + p_tmp[2]))
+#else
+        *p_out = ((float)( (((int32_t)*(int16_t *)(p_tmp+1)) << 8) + p_tmp[0]))
+#endif
+            / 8388608.0;
+
+        p_in -= 3; p_out--;
+    }
+
+    p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
+    p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * 4 / 3;
+}
index e139492144ab75de1642386dbb8f0557a3506a09..109c64b8303315c6693f2fced88609454602e073 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * format.c : PCM format converter
  *****************************************************************************
- * Copyright (C) 2002 VideoLAN
+ * Copyright (C) 2002-2005 VideoLAN
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
 #include "vlc_filter.h"
 
 #ifdef WORDS_BIGENDIAN
+#   define AOUT_FMT_S24_IE VLC_FOURCC('s','2','4','l')
 #   define AOUT_FMT_S16_IE VLC_FOURCC('s','1','6','l')
 #   define AOUT_FMT_U16_IE VLC_FOURCC('u','1','6','l')
 #else
+#   define AOUT_FMT_S24_IE VLC_FOURCC('s','2','4','b')
 #   define AOUT_FMT_S16_IE VLC_FOURCC('s','1','6','b')
 #   define AOUT_FMT_U16_IE VLC_FOURCC('u','1','6','b')
 #endif
  *****************************************************************************/
 static int  Open ( vlc_object_t * );
 
+static block_t *Float32toS24( filter_t *, block_t * );
 static block_t *Float32toS16( filter_t *, block_t * );
 static block_t *Float32toU16( filter_t *, block_t * );
 static block_t *Float32toS8 ( filter_t *, block_t * );
 static block_t *Float32toU8 ( filter_t *, block_t * );
 
-static block_t *S16toFloat32( filter_t *, block_t * );
-static block_t *S16toS8     ( filter_t *p_filter, block_t *p_block );
-static block_t *S16toU8     ( filter_t *p_filter, block_t *p_block );
-static block_t *S16toU16    ( filter_t *p_filter, block_t *p_block );
+static block_t *S24toFloat32  ( filter_t *, block_t * );
+static block_t *S24toS16      ( filter_t *, block_t * );
+static block_t *S24toS16Invert( filter_t *, block_t * );
+
+static block_t *S16toFloat32  ( filter_t *, block_t * );
+static block_t *S16toS24      ( filter_t *, block_t * );
+static block_t *S16toS24Invert( filter_t *, block_t * );
+static block_t *S16toS8       ( filter_t *, block_t * );
+static block_t *S16toU8       ( filter_t *, block_t * );
+static block_t *S16toU16      ( filter_t *, block_t * );
 
 static block_t *U16toFloat32( filter_t *, block_t * );
-static block_t *U16toS8     ( filter_t *p_filter, block_t *p_block );
-static block_t *U16toU8     ( filter_t *p_filter, block_t *p_block );
-static block_t *U16toS16    ( filter_t *p_filter, block_t *p_block );
+static block_t *U16toS8     ( filter_t *, block_t * );
+static block_t *U16toU8     ( filter_t *, block_t * );
+static block_t *U16toS16    ( filter_t *, block_t * );
 
+static block_t *Float32toS24Invert( filter_t *, block_t * );
 static block_t *Float32toS16Invert( filter_t *, block_t * );
 static block_t *Float32toU16Invert( filter_t *, block_t * );
 
-static block_t *S16InverttoFloat32( filter_t *, block_t * );
-static block_t *S16InverttoS8( filter_t *p_filter, block_t *p_block );
-static block_t *S16InverttoU8( filter_t *p_filter, block_t *p_block );
-static block_t *S16InverttoU16( filter_t *p_filter, block_t *p_block );
+static block_t *S24InverttoFloat32  ( filter_t *, block_t * );
+static block_t *S24InverttoS16      ( filter_t *, block_t * );
+static block_t *S24InverttoS16Invert( filter_t *, block_t * );
 
-static block_t *U16InverttoFloat32( filter_t *, block_t * );
-static block_t *U16InverttoS8( filter_t *p_filter, block_t *p_block );
-static block_t *U16InverttoU8( filter_t *p_filter, block_t *p_block );
-static block_t *U16InverttoS16( filter_t *p_filter, block_t *p_block );
+static block_t *S16InverttoFloat32  ( filter_t *, block_t * );
+static block_t *S16InverttoS24      ( filter_t *, block_t * );
+static block_t *S16InverttoS24Invert( filter_t *, block_t * );
+static block_t *S16InverttoS8       ( filter_t *, block_t * );
+static block_t *S16InverttoU8       ( filter_t *, block_t * );
+static block_t *S16InverttoU16      ( filter_t *, block_t * );
 
-static block_t *S8toFloat32( filter_t *, block_t * );
-static block_t *S8toS16( filter_t *, block_t * );
-static block_t *S8toU16( filter_t *, block_t * );
-static block_t *S8toU8( filter_t *, block_t * );
+static block_t *U16InverttoFloat32( filter_t *, block_t * );
+static block_t *U16InverttoS8     ( filter_t *, block_t * );
+static block_t *U16InverttoU8     ( filter_t *, block_t * );
+static block_t *U16InverttoS16    ( filter_t *, block_t * );
+
+static block_t *S8toFloat32  ( filter_t *, block_t * );
+static block_t *S8toS16      ( filter_t *, block_t * );
+static block_t *S8toU16      ( filter_t *, block_t * );
+static block_t *S8toU8       ( filter_t *, block_t * );
 static block_t *S8toS16Invert( filter_t *, block_t * );
 static block_t *S8toU16Invert( filter_t *, block_t * );
 
-static block_t *U8toFloat32( filter_t *, block_t * );
-static block_t *U8toFloat32( filter_t *, block_t * );
-static block_t *U8toS16( filter_t *, block_t * );
-static block_t *U8toU16( filter_t *, block_t * );
-static block_t *U8toS8( filter_t *, block_t * );
+static block_t *U8toFloat32  ( filter_t *, block_t * );
+static block_t *U8toFloat32  ( filter_t *, block_t * );
+static block_t *U8toS16      ( filter_t *, block_t * );
+static block_t *U8toU16      ( filter_t *, block_t * );
+static block_t *U8toS8       ( filter_t *, block_t * );
 static block_t *U8toS16Invert( filter_t *, block_t * );
 static block_t *U8toU16Invert( filter_t *, block_t * );
 
@@ -94,7 +110,8 @@ static block_t *U8toS8( filter_t *, block_t * );
 static block_t *S8toU8( filter_t *, block_t * );
 
 
-static block_t *Swap16   ( filter_t *, block_t * );
+static block_t *Swap16( filter_t *, block_t * );
+static block_t *Swap24( filter_t *, block_t * );
 
 static struct
 {
@@ -104,24 +121,34 @@ static struct
 } ConvertTable[] =
 {
     /* From fl32 */
+    { VLC_FOURCC('f','l','3','2'), AOUT_FMT_S24_NE, Float32toS24 },
     { VLC_FOURCC('f','l','3','2'), AOUT_FMT_S16_NE, Float32toS16 },
     { VLC_FOURCC('f','l','3','2'), AOUT_FMT_U16_NE, Float32toU16 },
+    { VLC_FOURCC('f','l','3','2'), AOUT_FMT_S24_IE, Float32toS24Invert },
     { VLC_FOURCC('f','l','3','2'), AOUT_FMT_S16_IE, Float32toS16Invert },
     { VLC_FOURCC('f','l','3','2'), AOUT_FMT_U16_IE, Float32toU16Invert },
     { VLC_FOURCC('f','l','3','2'), VLC_FOURCC('s','8',' ',' '), Float32toS8 },
     { VLC_FOURCC('f','l','3','2'), VLC_FOURCC('u','8',' ',' '), Float32toU8 },
 
+    /* From s24 invert */
+    { AOUT_FMT_S24_NE, VLC_FOURCC('f','l','3','2'), S24toFloat32 },
+    { AOUT_FMT_S24_NE, AOUT_FMT_S24_IE,             Swap24 },
+    { AOUT_FMT_S24_NE, AOUT_FMT_S16_NE,             S24toS16 },
+    { AOUT_FMT_S24_NE, AOUT_FMT_S16_IE,             S24toS16Invert },
+
     /* From s16 */
     { AOUT_FMT_S16_NE, VLC_FOURCC('f','l','3','2'), S16toFloat32 },
-    { AOUT_FMT_S16_NE, AOUT_FMT_S16_IE,            Swap16 },
-    { AOUT_FMT_S16_NE, AOUT_FMT_U16_IE,            S16toU16 },
+    { AOUT_FMT_S16_NE, AOUT_FMT_S24_NE,             S16toS24 },
+    { AOUT_FMT_S16_NE, AOUT_FMT_S24_IE,             S16toS24Invert },
+    { AOUT_FMT_S16_NE, AOUT_FMT_S16_IE,             Swap16 },
+    { AOUT_FMT_S16_NE, AOUT_FMT_U16_IE,             S16toU16 },
     { AOUT_FMT_S16_NE, VLC_FOURCC('s','8',' ',' '), S16toS8 },
     { AOUT_FMT_S16_NE, VLC_FOURCC('u','8',' ',' '), S16toU8 },
 
     /* From u16 */
     { AOUT_FMT_U16_NE, VLC_FOURCC('f','l','3','2'), U16toFloat32 },
-    { AOUT_FMT_U16_NE, AOUT_FMT_U16_IE,            Swap16 },
-    { AOUT_FMT_U16_NE, AOUT_FMT_S16_IE,            U16toS16 },
+    { AOUT_FMT_U16_NE, AOUT_FMT_U16_IE,             Swap16 },
+    { AOUT_FMT_U16_NE, AOUT_FMT_S16_IE,             U16toS16 },
     { AOUT_FMT_U16_NE, VLC_FOURCC('s','8',' ',' '), U16toS8 },
     { AOUT_FMT_U16_NE, VLC_FOURCC('u','8',' ',' '), U16toU8 },
 
@@ -141,17 +168,25 @@ static struct
     { VLC_FOURCC('u','8',' ',' '), AOUT_FMT_U16_IE,             U8toU16Invert },
     { VLC_FOURCC('u','8',' ',' '), VLC_FOURCC('s','8',' ',' '), U8toS8 },
 
+    /* From s24 invert */
+    { AOUT_FMT_S24_IE, VLC_FOURCC('f','l','3','2'), S24InverttoFloat32 },
+    { AOUT_FMT_S24_IE, AOUT_FMT_S24_NE,             Swap24 },
+    { AOUT_FMT_S24_IE, AOUT_FMT_S16_NE,             S24InverttoS16 },
+    { AOUT_FMT_S24_IE, AOUT_FMT_S16_IE,             S24InverttoS16Invert },
+
     /* From s16 invert */
     { AOUT_FMT_S16_IE, VLC_FOURCC('f','l','3','2'), S16InverttoFloat32 },
-    { AOUT_FMT_S16_IE, AOUT_FMT_S16_NE,            Swap16 },
-    { AOUT_FMT_S16_IE, AOUT_FMT_U16_NE,            S16InverttoU16 },
+    { AOUT_FMT_S16_IE, AOUT_FMT_S24_NE,             S16InverttoS24 },
+    { AOUT_FMT_S16_IE, AOUT_FMT_S24_IE,             S16InverttoS24Invert },
+    { AOUT_FMT_S16_IE, AOUT_FMT_S16_NE,             Swap16 },
+    { AOUT_FMT_S16_IE, AOUT_FMT_U16_NE,             S16InverttoU16 },
     { AOUT_FMT_S16_IE, VLC_FOURCC('s','8',' ',' '), S16InverttoS8 },
     { AOUT_FMT_S16_IE, VLC_FOURCC('u','8',' ',' '), S16InverttoU8 },
 
     /* From u16 invert */
     { AOUT_FMT_U16_IE, VLC_FOURCC('f','l','3','2'), U16InverttoFloat32 },
-    { AOUT_FMT_U16_IE, AOUT_FMT_U16_NE,            Swap16 },
-    { AOUT_FMT_U16_IE, AOUT_FMT_S16_NE,            U16InverttoS16 },
+    { AOUT_FMT_U16_IE, AOUT_FMT_U16_NE,             Swap16 },
+    { AOUT_FMT_U16_IE, AOUT_FMT_S16_NE,             U16InverttoS16 },
     { AOUT_FMT_U16_IE, VLC_FOURCC('s','8',' ',' '), U16InverttoS8 },
     { AOUT_FMT_U16_IE, VLC_FOURCC('u','8',' ',' '), U16InverttoU8 },
 
@@ -199,6 +234,34 @@ static int Open( vlc_object_t *p_this )
 /*****************************************************************************
  * Convert a buffer
  *****************************************************************************/
+static block_t *Float32toS24( filter_t *p_filter, block_t *p_block )
+{
+    int i;
+    float *p_in = (float *)p_block->p_buffer;
+    uint8_t *p_out = (uint8_t *)p_in;
+    int32_t out;
+
+    for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; )
+    {
+        if ( *p_in >= 1.0 ) out = 8388607;
+        else if ( *p_in < -1.0 ) out = -8388608;
+        else out = *p_in * 8388608.0;
+
+#ifdef WORDS_BIGENDIAN
+       *((int16_t *)p_out) = out >> 8;
+       p_out[2] = out & 0xFF;
+#else
+       *((int16_t *)(p_out+1)) = out >> 8;
+       p_out[0] = out & 0xFF;
+#endif
+
+        p_in++; p_out += 3;
+    }
+
+    p_block->i_buffer = p_block->i_buffer * 3 / 4;
+    return p_block;
+}
+
 static block_t *Float32toS16( filter_t *p_filter, block_t *p_block )
 {
     int i;
@@ -245,6 +308,69 @@ static block_t *Float32toU16( filter_t *p_filter, block_t *p_block )
     return p_block;
 }
 
+static block_t *S24toFloat32( filter_t *p_filter, block_t *p_block )
+{
+    block_t *p_block_out;
+    uint8_t *p_in;
+    float *p_out;
+    int i;
+
+    p_block_out =
+        p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer*4/3 );
+    if( !p_block_out )
+    {
+        msg_Warn( p_filter, "can't get output buffer" );
+        return NULL;
+    }
+
+    p_in = p_block->p_buffer;
+    p_out = (float *)p_block_out->p_buffer;
+
+    for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; )
+    {
+#ifdef WORDS_BIGENDIAN
+        *p_out = ((float)( (((int32_t)*(int16_t *)(p_in)) << 8) + p_in[2]))
+#else
+        *p_out = ((float)( (((int32_t)*(int16_t *)(p_in+1)) << 8) + p_in[0]))
+#endif
+            / 8388608.0;
+
+        p_in += 3; p_out++;
+    }
+
+    p_block_out->i_samples = p_block->i_samples;
+    p_block_out->i_dts = p_block->i_dts;
+    p_block_out->i_pts = p_block->i_pts;
+    p_block_out->i_length = p_block->i_length;
+    p_block_out->i_rate = p_block->i_rate;
+
+    p_block->pf_release( p_block );
+    return p_block_out;
+}
+
+static block_t *S24toS16( filter_t *p_filter, block_t *p_block )
+{
+    int i;
+    uint8_t *p_in = (uint8_t *)p_block->p_buffer;
+    uint8_t *p_out = (uint8_t *)p_in;
+
+    for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; )
+    {
+#ifdef WORDS_BIGENDIAN
+        *p_out++ = *p_in++;
+        *p_out++ = *p_in++;
+        p_in++;
+#else
+        p_in++;
+        *p_out++ = *p_in++;
+        *p_out++ = *p_in++;
+#endif
+    }
+
+    p_block->i_buffer = p_block->i_buffer * 2 / 3;
+    return p_block;
+}
+
 static block_t *S16toFloat32( filter_t *p_filter, block_t *p_block )
 {
     block_t *p_block_out;
@@ -323,6 +449,46 @@ static block_t *U16toFloat32( filter_t *p_filter, block_t *p_block )
     return p_block_out;
 }
 
+static block_t *S16toS24( filter_t *p_filter, block_t *p_block )
+{
+    block_t *p_block_out;
+    uint8_t *p_in, *p_out;
+    int i;
+
+    p_block_out =
+        p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer*3/2 );
+    if( !p_block_out )
+    {
+        msg_Warn( p_filter, "can't get output buffer" );
+        return NULL;
+    }
+
+    p_in = (uint8_t *)p_block->p_buffer;
+    p_out = (uint8_t *)p_block_out->p_buffer;
+
+    for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; )
+    {
+#ifdef WORDS_BIGENDIAN
+        *p_out++ = *p_in++;
+        *p_out++ = *p_in++;
+        *p_out++ = 0;
+#else
+        *p_out++ = 0;
+        *p_out++ = *p_in++;
+        *p_out++ = *p_in++;
+#endif
+    }
+
+    p_block_out->i_samples = p_block->i_samples;
+    p_block_out->i_dts = p_block->i_dts;
+    p_block_out->i_pts = p_block->i_pts;
+    p_block_out->i_length = p_block->i_length;
+    p_block_out->i_rate = p_block->i_rate;
+
+    p_block->pf_release( p_block );
+    return p_block_out;
+}
+
 static block_t *S16toS8( filter_t *p_filter, block_t *p_block )
 {
     int i;
@@ -545,7 +711,7 @@ static block_t *U8toU16( filter_t *p_filter, block_t *p_block )
 }
 
 /*****************************************************************************
- * Swap a buffer of word
+ * Swap a buffer of words
  *****************************************************************************/
 static block_t *Swap16( filter_t *p_filter, block_t *p_block )
 {
@@ -564,32 +730,58 @@ static block_t *Swap16( filter_t *p_filter, block_t *p_block )
     return p_block;
 }
 
-#define CONVERT_NN( func, f_in, f_out, b_pre_invert, b_post_invert ) \
+static block_t *Swap24( filter_t *p_filter, block_t *p_block )
+{
+    int i;
+    uint8_t *p_in = (uint8_t *)p_block->p_buffer;
+    uint8_t tmp;
+
+    for( i = 0; i < p_block->i_buffer / 3; i++ )
+    {
+        tmp = p_in[0];
+        p_in[0] = p_in[2];
+        p_in[2] = tmp;
+        p_in += 3;
+    }
+
+    return p_block;
+}
+
+#define CONVERT_NN( func, f_in, f_out, b_pre_invert, b_post_invert, swapa, swapb ) \
 static block_t *func( filter_t *p_filter, block_t *p_block ) \
 {                                                   \
     if( b_pre_invert )                              \
-        Swap16( p_filter, p_block );                \
+        swapa( p_filter, p_block );                  \
                                                     \
     p_block = f_in##to##f_out( p_filter, p_block ); \
                                                     \
     if( b_post_invert )                             \
-        Swap16( p_filter, p_block );                \
+        swapb( p_filter, p_block );                  \
                                                     \
     return p_block;                                 \
 }
 
-CONVERT_NN( Float32toS16Invert, Float32, S16, 0, 1 )
-CONVERT_NN( Float32toU16Invert, Float32, U16, 0, 1 )
+CONVERT_NN( Float32toS24Invert, Float32, S24, 0, 1, Swap24, Swap24 )
+CONVERT_NN( Float32toS16Invert, Float32, S16, 0, 1, Swap16, Swap16 )
+CONVERT_NN( Float32toU16Invert, Float32, U16, 0, 1, Swap16, Swap16 )
+
+CONVERT_NN( S24InverttoFloat32, S24, Float32, 1, 0, Swap24, Swap24 )
+CONVERT_NN( S24InverttoS16,     S24, S16,     1, 0, Swap24, Swap16 )
+CONVERT_NN( S24InverttoS16Invert, S24, S16,   1, 1, Swap24, Swap16 )
+CONVERT_NN( S24toS16Invert,     S24, S16,     0, 1, Swap24, Swap16 )
 
-CONVERT_NN( S16InverttoFloat32, S16, Float32, 1, 0 )
-CONVERT_NN( S16InverttoS8,      S16, S8,      1, 0 )
-CONVERT_NN( S16InverttoU8,      S16, U8,      1, 0 )
-CONVERT_NN( S16InverttoU16,     S16, U16,     1, 0 )
+CONVERT_NN( S16InverttoFloat32, S16, Float32, 1, 0, Swap16, Swap16 )
+CONVERT_NN( S16InverttoS24,     S16, S24,     1, 0, Swap16, Swap24 )
+CONVERT_NN( S16toS24Invert,     S16, S24,     0, 1, Swap16, Swap24 )
+CONVERT_NN( S16InverttoS24Invert, S16, S24,   1, 1, Swap16, Swap24 )
+CONVERT_NN( S16InverttoS8,      S16, S8,      1, 0, Swap16, Swap16 )
+CONVERT_NN( S16InverttoU8,      S16, U8,      1, 0, Swap16, Swap16 )
+CONVERT_NN( S16InverttoU16,     S16, U16,     1, 0, Swap16, Swap16 )
 
-CONVERT_NN( U16InverttoFloat32, U16, Float32, 1, 0 )
-CONVERT_NN( U16InverttoS8,      U16, S8,      1, 0 )
-CONVERT_NN( U16InverttoU8,      U16, U8,      1, 0 )
-CONVERT_NN( U16InverttoS16,     U16, S16,     1, 0 )
+CONVERT_NN( U16InverttoFloat32, U16, Float32, 1, 0, Swap16, Swap16 )
+CONVERT_NN( U16InverttoS8,      U16, S8,      1, 0, Swap16, Swap16 )
+CONVERT_NN( U16InverttoU8,      U16, U8,      1, 0, Swap16, Swap16 )
+CONVERT_NN( U16InverttoS16,     U16, S16,     1, 0, Swap16, Swap16 )
 
 #undef CONVERT_NN
 
@@ -615,6 +807,3 @@ CONVERT_INDIRECT( U8toU16Invert, U8,      U16, U16Invert )
 CONVERT_INDIRECT( S8toS16Invert, S8,      S16, S16Invert )
 
 #undef CONVERT_INDIRECT
-
-
-
index 06e4b135dc459ef3b651246387308eeab01836c4..3b5b9ae9876eaae0a205756a478103853a8d7bc1 100644 (file)
@@ -1,13 +1,13 @@
 /*****************************************************************************
  * lpcm.c: lpcm decoder/packetizer module
  *****************************************************************************
- * Copyright (C) 1999-2003 VideoLAN
+ * Copyright (C) 1999-2005 VideoLAN
  * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Henri Fallon <henri@videolan.org>
  *          Christophe Massiot <massiot@via.ecp.fr>
- *          Gildas Bazin <gbazin@netcourrier.com>
+ *          Gildas Bazin <gbazin@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -118,7 +118,16 @@ static int OpenDecoder( vlc_object_t *p_this )
 
     /* Set output properties */
     p_dec->fmt_out.i_cat = AUDIO_ES;
-    p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','b');
+
+    if( p_dec->fmt_out.audio.i_bitspersample == 24 )
+    {
+        p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','b');
+    }
+    else
+    {
+        p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','b');
+        p_dec->fmt_out.audio.i_bitspersample = 16;
+    }
 
     /* Set callback */
     p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
@@ -154,7 +163,7 @@ static void *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
     decoder_sys_t *p_sys = p_dec->p_sys;
     block_t       *p_block;
     unsigned int  i_rate = 0, i_original_channels = 0, i_channels = 0;
-    int           i_frame_length;
+    int           i_frame_length, i_bitspersample;
     uint8_t       i_header;
 
     if( !pp_block || !*pp_block ) return NULL;
@@ -242,6 +251,26 @@ static void *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
         break;
     }
 
+    switch ( (i_header >> 6) & 0x3 )
+    {
+    case 2:
+        p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','b');
+        p_dec->fmt_out.audio.i_bitspersample = 24;
+        i_bitspersample = 24;
+        break;
+    case 1:
+        p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','b');
+        p_dec->fmt_out.audio.i_bitspersample = 24;
+        i_bitspersample = 20;
+        break;
+    case 0:
+    default:
+        p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','b');
+        p_dec->fmt_out.audio.i_bitspersample = 16;
+        i_bitspersample = 16;
+        break;
+    }
+
     /* Check frame sync and drop it. */
     if( p_block->p_buffer[5] != 0x80 )
     {
@@ -263,10 +292,11 @@ static void *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
         = i_original_channels & AOUT_CHAN_PHYSMASK;
 
     i_frame_length = (p_block->i_buffer - LPCM_HEADER_LEN) /
-        ( p_dec->fmt_out.audio.i_channels * 2 );
+        p_dec->fmt_out.audio.i_channels * 8 / i_bitspersample;
 
     if( p_sys->b_packetizer )
     {
+        p_dec->fmt_out.i_codec = VLC_FOURCC('l','p','c','m');
         p_block->i_pts = p_block->i_dts = aout_DateGet( &p_sys->end_date );
         p_block->i_length =
             aout_DateIncrement( &p_sys->end_date, i_frame_length ) -
@@ -285,9 +315,71 @@ static void *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
         p_aout_buffer->end_date =
             aout_DateIncrement( &p_sys->end_date, i_frame_length );
 
-        memcpy( p_aout_buffer->p_buffer,
-                p_block->p_buffer + LPCM_HEADER_LEN,
-                p_block->i_buffer - LPCM_HEADER_LEN );
+        p_block->p_buffer += LPCM_HEADER_LEN;
+        p_block->i_buffer -= LPCM_HEADER_LEN;
+
+        /* 20/24 bits LPCM use special packing */
+        if( i_bitspersample == 24 )
+        {
+            uint8_t *p_out = p_aout_buffer->p_buffer;
+
+            while( p_block->i_buffer / 12 )
+            {
+                /* Sample 1 */
+                p_out[0] = p_block->p_buffer[0];
+                p_out[1] = p_block->p_buffer[1];
+                p_out[2] = p_block->p_buffer[8];
+                /* Sample 2 */
+                p_out[3] = p_block->p_buffer[2];
+                p_out[4] = p_block->p_buffer[3];
+                p_out[5] = p_block->p_buffer[9];
+                /* Sample 3 */
+                p_out[6] = p_block->p_buffer[4];
+                p_out[7] = p_block->p_buffer[5];
+                p_out[8] = p_block->p_buffer[10];
+                /* Sample 4 */
+                p_out[9] = p_block->p_buffer[6];
+                p_out[10] = p_block->p_buffer[7];
+                p_out[11] = p_block->p_buffer[11];
+
+                p_block->i_buffer -= 12;
+                p_block->p_buffer += 12;
+                p_out += 12;
+            }
+        }
+        else if( i_bitspersample == 20 )
+        {
+            uint8_t *p_out = p_aout_buffer->p_buffer;
+
+            while( p_block->i_buffer / 10 )
+            {
+                /* Sample 1 */
+                p_out[0] = p_block->p_buffer[0];
+                p_out[1] = p_block->p_buffer[1];
+                p_out[2] = p_block->p_buffer[8] & 0xF0;
+                /* Sample 2 */
+                p_out[3] = p_block->p_buffer[2];
+                p_out[4] = p_block->p_buffer[3];
+                p_out[5] = p_block->p_buffer[8] << 4;
+                /* Sample 3 */
+                p_out[6] = p_block->p_buffer[4];
+                p_out[7] = p_block->p_buffer[5];
+                p_out[8] = p_block->p_buffer[9] & 0xF0;
+                /* Sample 4 */
+                p_out[9] = p_block->p_buffer[6];
+                p_out[10] = p_block->p_buffer[7];
+                p_out[11] = p_block->p_buffer[9] << 4;
+
+                p_block->i_buffer -= 10;
+                p_block->p_buffer += 10;
+                p_out += 12;
+            }
+        }
+        else
+        {
+            memcpy( p_aout_buffer->p_buffer,
+                    p_block->p_buffer, p_block->i_buffer );
+        }
 
         block_Release( p_block );
         return p_aout_buffer;
index 239ba1f0b487b32e2fa9a8e6bc0d234a1bfd50d9..972efc106c7873ccb93b9bffb398e36a6dda0495 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * common.c : audio output management of common data structures
  *****************************************************************************
- * Copyright (C) 2002-2004 VideoLAN
+ * Copyright (C) 2002-2005 VideoLAN
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
@@ -129,6 +129,13 @@ void aout_FormatPrepare( audio_sample_format_t * p_format )
         i_result = 2;
         break;
 
+    case VLC_FOURCC('u','2','4','l'):
+    case VLC_FOURCC('s','2','4','l'):
+    case VLC_FOURCC('u','2','4','b'):
+    case VLC_FOURCC('s','2','4','b'):
+        i_result = 3;
+        break;
+
     case VLC_FOURCC('f','l','3','2'):
     case VLC_FOURCC('f','i','3','2'):
         i_result = 4;