add Creative 8 bits ADPCM schemes support
authorAurelien Jacobs <aurel@gnuage.org>
Thu, 16 Feb 2006 00:09:23 +0000 (00:09 +0000)
committerAurelien Jacobs <aurel@gnuage.org>
Thu, 16 Feb 2006 00:09:23 +0000 (00:09 +0000)
Originally committed as revision 5024 to svn://svn.ffmpeg.org/ffmpeg/trunk

doc/ffmpeg-doc.texi
libavcodec/adpcm.c
libavcodec/allcodecs.c
libavcodec/avcodec.h
libavformat/voc.c

index 4ca03346e06384b7282efa00e0f84ff612416172..6ad6eae5cba02045926d0f3a690a3d0567ddf6f2 100644 (file)
@@ -833,6 +833,7 @@ other implementations.
 @item Electronic Arts ADPCM  @tab      @tab X
 @tab Used in various EA titles.
 @item Creative ADPCM         @tab      @tab X
+@tab 16 -> 4, 8 -> 4, 8 -> 3, 8 -> 2
 @item RA144                  @tab      @tab X
 @tab Real 14400 bit/s codec
 @item RA288                  @tab      @tab X
index ed3106aa0f7de50ed460ebdd7c7411ce99083771..de66daf7dbe801c410fa79cb084e4f381fef16c2 100644 (file)
@@ -514,6 +514,34 @@ static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble)
     return (short)predictor;
 }
 
+static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift)
+{
+    int sign, delta, diff;
+
+    sign = nibble & (1<<(size-1));
+    delta = nibble & ((1<<(size-1))-1);
+    diff = delta << (7 + c->step + shift);
+
+    if (sign)
+        c->predictor -= diff;
+    else
+        c->predictor += diff;
+
+    /* clamp result */
+    if (c->predictor > 16256)
+        c->predictor = 16256;
+    else if (c->predictor < -16384)
+        c->predictor = -16384;
+
+    /* calculate new step */
+    if (delta >= (2*size - 3) && c->step < 3)
+        c->step++;
+    else if (delta == 0 && c->step > 0)
+        c->step--;
+
+    return (short) c->predictor;
+}
+
 static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned char nibble)
 {
     if(!c->step) {
@@ -644,7 +672,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
     samples = data;
     src = buf;
 
-    st = avctx->channels == 2;
+    st = avctx->channels == 2 ? 1 : 0;
 
     switch(avctx->codec->id) {
     case CODEC_ID_ADPCM_IMA_QT:
@@ -973,6 +1001,48 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
             src++;
         }
         break;
+    case CODEC_ID_ADPCM_SBPRO_4:
+    case CODEC_ID_ADPCM_SBPRO_3:
+    case CODEC_ID_ADPCM_SBPRO_2:
+        if (!c->status[0].step_index) {
+            /* the first byte is a raw sample */
+            *samples++ = 128 * (*src++ - 0x80);
+            if (st)
+              *samples++ = 128 * (*src++ - 0x80);
+            c->status[0].step_index = 1;
+        }
+        if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
+            while (src < buf + buf_size) {
+                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+                    (src[0] >> 4) & 0x0F, 4, 0);
+                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
+                    src[0] & 0x0F, 4, 0);
+                src++;
+            }
+        } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
+            while (src < buf + buf_size) {
+                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+                    (src[0] >> 5) & 0x07, 3, 0);
+                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+                    (src[0] >> 2) & 0x07, 3, 0);
+                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+                    src[0] & 0x03, 2, 0);
+                src++;
+            }
+        } else {
+            while (src < buf + buf_size) {
+                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+                    (src[0] >> 6) & 0x03, 2, 2);
+                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
+                    (src[0] >> 4) & 0x03, 2, 2);
+                *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
+                    (src[0] >> 2) & 0x03, 2, 2);
+                *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
+                    src[0] & 0x03, 2, 2);
+                src++;
+            }
+        }
+        break;
     case CODEC_ID_ADPCM_SWF:
     {
         GetBitContext gb;
@@ -1117,5 +1187,8 @@ ADPCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea);
 ADPCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct);
 ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf);
 ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha);
+ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4);
+ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3);
+ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2);
 
 #undef ADPCM_CODEC
index f3238f287488be059117cddca5600a765cde7922..4730af1de6d492a255793f0291b4a0943e4729bc 100644 (file)
@@ -593,6 +593,9 @@ PCM_CODEC(CODEC_ID_ADPCM_G726, adpcm_g726);
 PCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct);
 PCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf);
 PCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha);
+PCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4);
+PCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3);
+PCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2);
 #undef PCM_CODEC
 
     /* subtitles */
index 10167d73b65e142911c7240f6cf488eea126225f..3e050a9a17565af5511f0ae301b5a78d009a26b8 100644 (file)
@@ -21,8 +21,8 @@ extern "C" {
 #define AV_STRINGIFY(s)         AV_TOSTRING(s)
 #define AV_TOSTRING(s) #s
 
-#define LIBAVCODEC_VERSION_INT  ((51<<16)+(5<<8)+0)
-#define LIBAVCODEC_VERSION      51.5.0
+#define LIBAVCODEC_VERSION_INT  ((51<<16)+(6<<8)+0)
+#define LIBAVCODEC_VERSION      51.6.0
 #define LIBAVCODEC_BUILD        LIBAVCODEC_VERSION_INT
 
 #define LIBAVCODEC_IDENT        "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
@@ -153,6 +153,9 @@ enum CodecID {
     CODEC_ID_ADPCM_CT,
     CODEC_ID_ADPCM_SWF,
     CODEC_ID_ADPCM_YAMAHA,
+    CODEC_ID_ADPCM_SBPRO_4,
+    CODEC_ID_ADPCM_SBPRO_3,
+    CODEC_ID_ADPCM_SBPRO_2,
 
     /* AMR */
     CODEC_ID_AMR_NB= 0x12000,
@@ -2271,6 +2274,9 @@ PCM_CODEC(CODEC_ID_ADPCM_G726, adpcm_g726);
 PCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct);
 PCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf);
 PCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha);
+PCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4);
+PCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3);
+PCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2);
 
 #undef PCM_CODEC
 
index 712f71a725aac4525accbb7c8ffb0d9e1eab886f..7fb85500714de34cfe7090c5ed0a1bbec5907071 100644 (file)
@@ -41,6 +41,9 @@ static const unsigned char voc_magic[] = "Creative Voice File\x1A";
 
 static const CodecTag voc_codec_tags[] = {
     {CODEC_ID_PCM_U8,        0x00},
+    {CODEC_ID_ADPCM_SBPRO_4, 0x01},
+    {CODEC_ID_ADPCM_SBPRO_3, 0x02},
+    {CODEC_ID_ADPCM_SBPRO_2, 0x03},
     {CODEC_ID_PCM_S16LE,     0x04},
     {CODEC_ID_PCM_ALAW,      0x06},
     {CODEC_ID_PCM_MULAW,     0x07},