[vlc-commits] araw: decode/encode 24-bits PCM to/from S32N

Rémi Denis-Courmont git at videolan.org
Wed Dec 19 19:34:24 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Dec 19 19:52:57 2012 +0200| [8429bce545a11a863b478be2265a0228c50c5db0] | committer: Rémi Denis-Courmont

araw: decode/encode 24-bits PCM to/from S32N

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

 modules/codec/araw.c |  146 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 142 insertions(+), 4 deletions(-)

diff --git a/modules/codec/araw.c b/modules/codec/araw.c
index b0ee2ec..3ef2c92 100644
--- a/modules/codec/araw.c
+++ b/modules/codec/araw.c
@@ -87,6 +87,10 @@ static void U16BDecode( void *, const uint8_t *, unsigned );
 static void U16LDecode( void *, const uint8_t *, unsigned );
 static void S16IDecode( void *, const uint8_t *, unsigned );
 static void S20BDecode( void *, const uint8_t *, unsigned );
+static void U24BDecode( void *, const uint8_t *, unsigned );
+static void U24LDecode( void *, const uint8_t *, unsigned );
+static void S24BDecode( void *, const uint8_t *, unsigned );
+static void S24LDecode( void *, const uint8_t *, unsigned );
 static void U32BDecode( void *, const uint8_t *, unsigned );
 static void U32LDecode( void *, const uint8_t *, unsigned );
 static void Swap32Decode( void *, const uint8_t *, unsigned );
@@ -159,11 +163,27 @@ static int DecoderOpen( vlc_object_t *p_this )
     case VLC_CODEC_S32I:
         format = VLC_CODEC_S32N;
         decode = Swap32Decode;
-     case VLC_CODEC_S32N:
+    case VLC_CODEC_S32N:
         bits = 32;
         break;
-    case VLC_CODEC_S24L:
+    case VLC_CODEC_U24B:
+        format = VLC_CODEC_S32N;
+        decode = U24BDecode;
+        bits = 24;
+        break;
+    case VLC_CODEC_U24L:
+        format = VLC_CODEC_S32N;
+        decode = U24LDecode;
+        bits = 24;
+        break;
     case VLC_CODEC_S24B:
+        format = VLC_CODEC_S32N;
+        decode = S24BDecode;
+        bits = 24;
+        break;
+    case VLC_CODEC_S24L:
+        format = VLC_CODEC_S32N;
+        decode = S24LDecode;
         bits = 24;
         break;
     case VLC_CODEC_S20B:
@@ -373,6 +393,54 @@ static void S20BDecode( void *outp, const uint8_t *in, unsigned samples )
         *(out++) = (U16_AT(in) << 16) | ((in[2] & 0xF0) << 8);
 }
 
+static void U24BDecode( void *outp, const uint8_t *in, unsigned samples )
+{
+    uint32_t *out = outp;
+
+    for( size_t i = 0; i < samples; i++ )
+    {
+        uint32_t s = ((in[0] << 24) | (in[1] << 16) | (in[2] << 8)) - 0x80000000;
+        *(out++) = s;
+        in += 3;
+    }
+}
+
+static void U24LDecode( void *outp, const uint8_t *in, unsigned samples )
+{
+    uint32_t *out = outp;
+
+    for( size_t i = 0; i < samples; i++ )
+    {
+        uint32_t s = ((in[2] << 24) | (in[1] << 16) | (in[0] << 8)) - 0x80000000;
+        *(out++) = s;
+        in += 3;
+    }
+}
+
+static void S24BDecode( void *outp, const uint8_t *in, unsigned samples )
+{
+    uint32_t *out = outp;
+
+    for( size_t i = 0; i < samples; i++ )
+    {
+        uint32_t s = ((in[0] << 24) | (in[1] << 16) | (in[2] << 8));
+        *(out++) = s;
+        in += 3;
+    }
+}
+
+static void S24LDecode( void *outp, const uint8_t *in, unsigned samples )
+{
+    uint32_t *out = outp;
+
+    for( size_t i = 0; i < samples; i++ )
+    {
+        uint32_t s = ((in[2] << 24) | (in[1] << 16) | (in[0] << 8));
+        *(out++) = s;
+        in += 3;
+    }
+}
+
 static void U32BDecode( void *outp, const uint8_t *in, unsigned samples )
 {
     uint32_t *out = outp;
@@ -486,6 +554,62 @@ static void U16NEncode( void *outp, const uint8_t *inp, unsigned samples )
         *(out++) =  *(in++) + 0x8000;
 }
 
+static void U24BEncode( void *outp, const uint8_t *inp, unsigned samples )
+{
+    const uint32_t *in = (const uint32_t *)inp;
+    uint8_t *out = outp;
+
+    for( size_t i = 0; i < samples; i++ )
+    {
+        uint32_t s = *(in++);
+        *(out++) = (s >> 24) + 0x80;
+        *(out++) = (s >> 16);
+        *(out++) = (s >>  8);
+    }
+}
+
+static void U24LEncode( void *outp, const uint8_t *inp, unsigned samples )
+{
+    const uint32_t *in = (const uint32_t *)inp;
+    uint8_t *out = outp;
+
+    for( size_t i = 0; i < samples; i++ )
+    {
+        uint32_t s = *(in++);
+        *(out++) = (s >>  8);
+        *(out++) = (s >> 16);
+        *(out++) = (s >> 24) + 0x80;
+    }
+}
+
+static void S24BEncode( void *outp, const uint8_t *inp, unsigned samples )
+{
+    const uint32_t *in = (const uint32_t *)inp;
+    uint8_t *out = outp;
+
+    for( size_t i = 0; i < samples; i++ )
+    {
+        uint32_t s = *(in++);
+        *(out++) = (s >> 24);
+        *(out++) = (s >> 16);
+        *(out++) = (s >>  8);
+    }
+}
+
+static void S24LEncode( void *outp, const uint8_t *inp, unsigned samples )
+{
+    const uint32_t *in = (const uint32_t *)inp;
+    uint8_t *out = outp;
+
+    for( size_t i = 0; i < samples; i++ )
+    {
+        uint32_t s = *(in++);
+        *(out++) = (s >>  8);
+        *(out++) = (s >> 16);
+        *(out++) = (s >> 24);
+    }
+}
+
 static void U32IEncode( void *outp, const uint8_t *inp, unsigned samples )
 {
     const uint32_t *in = (const uint32_t *)inp;
@@ -580,10 +704,24 @@ static int EncoderOpen( vlc_object_t *p_this )
         p_enc->fmt_in.i_codec = VLC_CODEC_S16N;
         p_enc->fmt_out.audio.i_bitspersample = 16;
         break;
-    case VLC_CODEC_U24L:
     case VLC_CODEC_U24B:
-    case VLC_CODEC_S24L:
+        encode = U24BEncode;
+        p_enc->fmt_in.i_codec = VLC_CODEC_S32N;
+        p_enc->fmt_out.audio.i_bitspersample = 24;
+        break;
+    case VLC_CODEC_U24L:
+        encode = U24LEncode;
+        p_enc->fmt_in.i_codec = VLC_CODEC_S32N;
+        p_enc->fmt_out.audio.i_bitspersample = 24;
+        break;
     case VLC_CODEC_S24B:
+        encode = S24BEncode;
+        p_enc->fmt_in.i_codec = VLC_CODEC_S32N;
+        p_enc->fmt_out.audio.i_bitspersample = 24;
+        break;
+    case VLC_CODEC_S24L:
+        encode = S24LEncode;
+        p_enc->fmt_in.i_codec = VLC_CODEC_S32N;
         p_enc->fmt_out.audio.i_bitspersample = 24;
         break;
     case VLC_CODEC_U32I:



More information about the vlc-commits mailing list