[FFmpeg-devel] [PATCH] IMA ADPCM encoder for QT

Kostya kostya.shishkov
Wed Feb 27 19:25:47 CET 2008


$subj
-------------- next part --------------
Index: Changelog
===================================================================
--- Changelog	(revision 12265)
+++ Changelog	(working copy)
@@ -110,6 +110,7 @@
 - TechnoTrend PVA demuxer
 - Linux Media Labs MPEG-4 (LMLM4) demuxer
 - AVM2 (Flash 9) SWF muxer
+- QT variant of IMA ADPCM encoder
 
 version 0.4.9-pre1:
 
Index: libavcodec/allcodecs.c
===================================================================
--- libavcodec/allcodecs.c	(revision 12190)
+++ libavcodec/allcodecs.c	(working copy)
@@ -249,7 +249,7 @@
     REGISTER_DECODER (ADPCM_IMA_DK4, adpcm_ima_dk4);
     REGISTER_DECODER (ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs);
     REGISTER_DECODER (ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead);
-    REGISTER_DECODER (ADPCM_IMA_QT, adpcm_ima_qt);
+    REGISTER_ENCDEC  (ADPCM_IMA_QT, adpcm_ima_qt);
     REGISTER_DECODER (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
     REGISTER_ENCDEC  (ADPCM_IMA_WAV, adpcm_ima_wav);
     REGISTER_DECODER (ADPCM_IMA_WS, adpcm_ima_ws);
Index: libavcodec/adpcm.c
===================================================================
--- libavcodec/adpcm.c	(revision 12190)
+++ libavcodec/adpcm.c	(working copy)
@@ -165,6 +165,10 @@
         avctx->block_align = BLKSIZE;
         /* seems frame_size isn't taken into account... have to buffer the samples :-( */
         break;
+    case CODEC_ID_ADPCM_IMA_QT:
+        avctx->frame_size = 64;
+        avctx->block_align = 34 * avctx->channels;
+        break;
     case CODEC_ID_ADPCM_MS:
         avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */
                                                              /* and we have 7 bytes per channel overhead */
@@ -295,7 +299,7 @@
     nodes[0]->step = c->step_index;
     nodes[0]->sample1 = c->sample1;
     nodes[0]->sample2 = c->sample2;
-    if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_SWF))
+    if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_IMA_QT) || (version == CODEC_ID_ADPCM_SWF))
         nodes[0]->sample1 = c->prev_sample;
     if(version == CODEC_ID_ADPCM_MS)
         nodes[0]->step = c->idelta;
@@ -366,7 +370,7 @@
                     next_##NAME:;
                     STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8));
                 }
-            } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_SWF)) {
+            } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_IMA_QT)|| (version == CODEC_ID_ADPCM_SWF)) {
 #define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\
                 const int predictor = nodes[j]->sample1;\
                 const int div = (sample - predictor) * 4 / STEP_TABLE;\
@@ -509,6 +513,36 @@
                 samples += 8 * avctx->channels;
             }
         break;
+    case CODEC_ID_ADPCM_IMA_QT:
+    {
+        int ch, i;
+        PutBitContext pb;
+        init_put_bits(&pb, dst, buf_size*8);
+
+        for(ch=0; ch<avctx->channels; ch++){
+            put_bits(&pb, 9, (c->status[ch].prev_sample + 0x10000) >> 7);
+            put_bits(&pb, 7, c->status[ch].step_index);
+            if(avctx->trellis > 0) {
+                uint8_t buf[64];
+                adpcm_compress_trellis(avctx, samples+ch, buf, &c->status[ch], 64);
+                for(i=0; i<64; i++)
+                    put_bits(&pb, 4, buf[i^1]);
+                c->status[ch].prev_sample = c->status[ch].predictor & ~0x7F;
+            } else {
+                for (i=0; i<64; i+=2){
+                    int t1, t2;
+                    t1 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+0)+ch]);
+                    t2 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+1)+ch]);
+                    put_bits(&pb, 4, t2);
+                    put_bits(&pb, 4, t1);
+                }
+                c->status[ch].prev_sample &= ~0x7F;
+            }
+        }
+
+        dst += put_bits_count(&pb)>>3;
+        break;
+    }
     case CODEC_ID_ADPCM_SWF:
     {
         int i;
@@ -1588,7 +1622,7 @@
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs);
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead);
-ADPCM_DECODER(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
+ADPCM_CODEC  (CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
 ADPCM_CODEC  (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
 ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);
Index: tests/rotozoom.regression.ref
===================================================================
--- tests/rotozoom.regression.ref	(revision 12190)
+++ tests/rotozoom.regression.ref	(working copy)
@@ -179,6 +179,10 @@
 266300 ./tests/data/a-adpcm_ima.wav
 947196b1739a9d6fe0c29424cf61cd8c *./tests/data/adpcm_ima_wav.rotozoom.out.wav
 stddev:904.20 PSNR:37.19 bytes:1056768
+efdae2746040dbc27be402b149556f1e *./tests/data/a-adpcm_qt.aiff
+281184 ./tests/data/a-adpcm_qt.aiff
+468fcd54a438f1b74060c2e9665be59e *./tests/data/adpcm_ima_qt.rotozoom.out.wav
+stddev:8931.22 PSNR:17.30 bytes:1056768
 628d4789cf9ee16a756ac54b7fd8650d *./tests/data/a-adpcm_ms.wav
 267320 ./tests/data/a-adpcm_ms.wav
 91a84bb4f319a3a0bf0c0441b3d3a529 *./tests/data/adpcm_ms.rotozoom.out.wav
Index: tests/regression.sh
===================================================================
--- tests/regression.sh	(revision 12190)
+++ tests/regression.sh	(working copy)
@@ -401,6 +401,11 @@
 do_audio_decoding
 fi
 
+if [ -n "$do_adpcm_ima_qt" ] ; then
+do_audio_encoding adpcm_qt.aiff "-ar 44100" "-acodec adpcm_ima_qt"
+do_audio_decoding
+fi
+
 if [ -n "$do_adpcm_ms" ] ; then
 do_audio_encoding adpcm_ms.wav "-ar 44100" "-acodec adpcm_ms"
 do_audio_decoding
Index: tests/ffmpeg.regression.ref
===================================================================
--- tests/ffmpeg.regression.ref	(revision 12190)
+++ tests/ffmpeg.regression.ref	(working copy)
@@ -179,6 +179,10 @@
 266300 ./tests/data/a-adpcm_ima.wav
 947196b1739a9d6fe0c29424cf61cd8c *./tests/data/adpcm_ima_wav.vsynth.out.wav
 stddev:904.20 PSNR:37.19 bytes:1056768
+efdae2746040dbc27be402b149556f1e *./tests/data/a-adpcm_qt.aiff
+281184 ./tests/data/a-adpcm_qt.aiff
+468fcd54a438f1b74060c2e9665be59e *./tests/data/adpcm_ima_qt.vsynth.out.wav
+stddev:8931.22 PSNR:17.30 bytes:1056768
 628d4789cf9ee16a756ac54b7fd8650d *./tests/data/a-adpcm_ms.wav
 267320 ./tests/data/a-adpcm_ms.wav
 91a84bb4f319a3a0bf0c0441b3d3a529 *./tests/data/adpcm_ms.vsynth.out.wav
Index: doc/general.texi
===================================================================
--- doc/general.texi	(revision 12190)
+++ doc/general.texi	(working copy)
@@ -261,7 +261,7 @@
 @item AMV IMA ADPCM          @tab      @tab X
 @tab Used in AMV files
 @item MS IMA ADPCM           @tab X    @tab X
- at item QT IMA ADPCM           @tab      @tab X
+ at item QT IMA ADPCM           @tab X    @tab X
 @item 4X IMA ADPCM           @tab      @tab X
 @item G.726  ADPCM           @tab X    @tab X
 @item Duck DK3 IMA ADPCM     @tab      @tab X
Index: Makefile
===================================================================
--- Makefile	(revision 12190)
+++ Makefile	(working copy)
@@ -300,6 +300,7 @@
         ac3                                     \
         g726                                    \
         adpcm_ima_wav                           \
+        adpcm_ima_qt                            \
         adpcm_ms                                \
         adpcm_yam                               \
         adpcm_swf                               \



More information about the ffmpeg-devel mailing list