[FFmpeg-devel] [PATCH 1/3] adpcm_dtk: Decode interleaved channels in parallel

James Almer jamrial at gmail.com
Mon May 13 00:47:14 CEST 2013


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/adpcm.c | 55 +++++++++++++++++++++++++++---------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index 1259bd4..fd636d9 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -1415,54 +1415,53 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
         break;
     }
     case AV_CODEC_ID_ADPCM_DTK:
-        for (channel = 0; channel < avctx->channels; channel++) {
-            samples = samples_p[channel];
+    {
+        uint16_t *smp[2];
 
-            /* Read in every sample for this channel.  */
+        smp[0] = samples_p[0];
+        smp[1] = samples_p[1];
             for (i = 0; i < nb_samples / 28; i++) {
-                int byte, header;
-                if (channel)
-                    bytestream2_skipu(&gb, 1);
-                header = bytestream2_get_byteu(&gb);
-                bytestream2_skipu(&gb, 3 - channel);
+                int byte, header[2];
+                header[0] = bytestream2_get_byteu(&gb);
+                header[1] = bytestream2_get_byteu(&gb);
+                bytestream2_skipu(&gb, 2);
 
                 /* Decode 28 samples.  */
                 for (n = 0; n < 28; n++) {
-                    int32_t sampledat, prev;
+                    int32_t sampledat[2], prev[2];
 
-                    switch (header >> 4) {
+                    for (channel = 0; channel < avctx->channels; channel++) {
+                    switch (header[channel] >> 4) {
                     case 1:
-                        prev = (c->status[channel].sample1 * 0x3c);
+                        prev[channel] = (c->status[channel].sample1 * 0x3c);
                         break;
                     case 2:
-                        prev = (c->status[channel].sample1 * 0x73) - (c->status[channel].sample2 * 0x34);
+                        prev[channel] = (c->status[channel].sample1 * 0x73) -
+                                        (c->status[channel].sample2 * 0x34);
                         break;
                     case 3:
-                        prev = (c->status[channel].sample1 * 0x62) - (c->status[channel].sample2 * 0x37);
+                        prev[channel] = (c->status[channel].sample1 * 0x62) -
+                                        (c->status[channel].sample2 * 0x37);
                         break;
                     default:
-                        prev = 0;
+                        prev[channel] = 0;
                     }
 
-                    prev = av_clip((prev + 0x20) >> 6, -0x200000, 0x1fffff);
+                    prev[channel] = av_clip((prev[channel] + 0x20) >> 6, -0x200000, 0x1fffff);
+                    }
 
                     byte = bytestream2_get_byteu(&gb);
-                    if (!channel)
-                        sampledat = sign_extend(byte, 4);
-                    else
-                        sampledat = sign_extend(byte >> 4, 4);
-
-                    sampledat = (((sampledat << 12) >> (header & 0xf)) << 6) + prev;
-                    *samples++ = av_clip_int16(sampledat >> 6);
-                    c->status[channel].sample2 = c->status[channel].sample1;
-                    c->status[channel].sample1 = sampledat;
+                    for (channel = 0; channel < avctx->channels; channel++) {
+                        sampledat[channel] = (((sign_extend(channel ? byte >> 4 : byte, 4) << 12) 
+                                             >> (header[channel] & 0xf)) << 6) + prev[channel];
+                        *smp[channel]++ = av_clip_int16(sampledat[channel] >> 6);
+                        c->status[channel].sample2 = c->status[channel].sample1;
+                        c->status[channel].sample1 = sampledat[channel];
+                    }
                 }
             }
-            if (!channel)
-                bytestream2_seek(&gb, 0, SEEK_SET);
-        }
         break;
-
+    }
     default:
         return -1;
     }
-- 
1.8.1.msysgit.1




More information about the ffmpeg-devel mailing list