]> git.sesse.net Git - ffmpeg/commitdiff
adpcm_ima_ws: fix stereo decoding
authorJustin Ruggles <justin.ruggles@gmail.com>
Mon, 23 Jan 2012 17:23:27 +0000 (12:23 -0500)
committerJustin Ruggles <justin.ruggles@gmail.com>
Tue, 24 Jan 2012 19:13:46 +0000 (14:13 -0500)
Stereo ADPCM IMA WS is planar for VQA version 3 and 2-sample interleaved for
VQA version 2.

libavcodec/adpcm.c
libavformat/westwood_vqa.c

index 64bea6a5daefda215d813dbeafe67369e528b98e..bd86ab0e61b49e1b614ed0f67b344dddf3e8ef7a 100644 (file)
@@ -86,6 +86,7 @@ static const int swf_index_tables[4][16] = {
 typedef struct ADPCMDecodeContext {
     AVFrame frame;
     ADPCMChannelStatus status[6];
+    int vqa_version;                /**< VQA version. Used for ADPCM_IMA_WS */
 } ADPCMDecodeContext;
 
 static av_cold int adpcm_decode_init(AVCodecContext * avctx)
@@ -126,6 +127,10 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
             c->status[1].predictor = AV_RL32(avctx->extradata + 4);
         }
         break;
+    case CODEC_ID_ADPCM_IMA_WS:
+        if (avctx->extradata && avctx->extradata_size >= 42)
+            c->vqa_version = AV_RL16(avctx->extradata);
+        break;
     default:
         break;
     }
@@ -774,7 +779,6 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
         }
         break;
-    case CODEC_ID_ADPCM_IMA_WS:
     case CODEC_ID_ADPCM_IMA_APC:
         while (src < buf + buf_size) {
             uint8_t v = *src++;
@@ -782,6 +786,30 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
         }
         break;
+    case CODEC_ID_ADPCM_IMA_WS:
+        for (channel = 0; channel < avctx->channels; channel++) {
+            const uint8_t *src0;
+            int src_stride;
+            int16_t *smp = samples + channel;
+
+            if (c->vqa_version == 3) {
+                src0 = src + channel * buf_size / 2;
+                src_stride = 1;
+            } else {
+                src0 = src + channel;
+                src_stride = avctx->channels;
+            }
+            for (n = nb_samples / 2; n > 0; n--) {
+                uint8_t v = *src0;
+                src0 += src_stride;
+                *smp = adpcm_ima_expand_nibble(&c->status[channel], v >> 4  , 3);
+                smp += avctx->channels;
+                *smp = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
+                smp += avctx->channels;
+            }
+        }
+        src = buf + buf_size;
+        break;
     case CODEC_ID_ADPCM_XA:
         while (buf_size >= 128) {
             xa_decode(samples, src, &c->status[0], &c->status[1],
index 4d6397b88c2a64b39dcc474ed272a9ed7fabaa7b..c2aebe5e807bed478bf15d8680ed455109b96d54 100644 (file)
@@ -128,6 +128,12 @@ static int wsvqa_read_header(AVFormatContext *s,
         st->start_time = 0;
         st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
 
+        st->codec->extradata_size = VQA_HEADER_SIZE;
+        st->codec->extradata = av_mallocz(VQA_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
+        if (!st->codec->extradata)
+            return AVERROR(ENOMEM);
+        memcpy(st->codec->extradata, header, VQA_HEADER_SIZE);
+
         if (!sample_rate)
             sample_rate = 22050;
         st->codec->sample_rate = sample_rate;