IMA ADPCM encoder - QT variant
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 6 Mar 2008 07:30:41 +0000 (07:30 +0000)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 6 Mar 2008 07:30:41 +0000 (07:30 +0000)
Originally committed as revision 12348 to svn://svn.ffmpeg.org/ffmpeg/trunk

Changelog
Makefile
doc/general.texi
libavcodec/adpcm.c
libavcodec/allcodecs.c
libavcodec/avcodec.h
tests/ffmpeg.regression.ref
tests/regression.sh
tests/rotozoom.regression.ref
tests/seek.regression.ref

index 3249c60..8fe1dda 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -110,6 +110,7 @@ version <next>
 - 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 1a300c9..3551543 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -314,6 +314,7 @@ CODEC_TESTS = $(addprefix regtest-,             \
         ac3                                     \
         g726                                    \
         adpcm_ima_wav                           \
+        adpcm_ima_qt                            \
         adpcm_ms                                \
         adpcm_yam                               \
         adpcm_swf                               \
index 8fc27d6..df7c5e7 100644 (file)
@@ -261,7 +261,7 @@ following image formats are supported:
 @item AMV IMA ADPCM          @tab      @tab X
 @tab Used in AMV files
 @item MS IMA ADPCM           @tab X    @tab X
-@item QT IMA ADPCM           @tab      @tab X
+@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 eadcfae..4e5c54e 100644 (file)
@@ -165,6 +165,10 @@ static int adpcm_encode_init(AVCodecContext *avctx)
         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 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
     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 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
                     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 @@ static int adpcm_encode_frame(AVCodecContext *avctx,
                 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_DK3, adpcm_ima_dk3);
 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 9bb35fa..1eaf093 100644 (file)
@@ -249,7 +249,7 @@ void avcodec_register_all(void)
     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 5e38cf6..7b4e1b4 100644 (file)
@@ -31,8 +31,8 @@
 #include <sys/types.h> /* size_t */
 
 #define LIBAVCODEC_VERSION_MAJOR 51
-#define LIBAVCODEC_VERSION_MINOR 50
-#define LIBAVCODEC_VERSION_MICRO  1
+#define LIBAVCODEC_VERSION_MINOR 51
+#define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
index 43f79ef..f175eb5 100644 (file)
@@ -179,6 +179,10 @@ stddev:8368.02 PSNR:17.87 bytes:96256
 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 44bf9eb..cbbeda0 100755 (executable)
@@ -401,6 +401,11 @@ do_audio_encoding adpcm_ima.wav "-ar 44100" "-acodec adpcm_ima_wav"
 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 4ec5eb5..2f1b2b7 100644 (file)
@@ -179,6 +179,10 @@ stddev:8368.02 PSNR:17.87 bytes:96256
 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 a760b9e..96c5cc7 100644 (file)
@@ -95,6 +95,61 @@ ret: 0 st: 0 dts:0.511995 pts:0.511995 pos:8252 size:4096 flags:1
 ret: 0 st:-1 ts:-0.645825 flags:1
 ret: 0 st: 0 dts:-0.703991 pts:-0.703991 pos:41020 size:4096 flags:1
 ----------------
+tests/data/a-adpcm_qt.aiff
+ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:72 size:4080 flags:1
+ret: 0 st:-1 ts:-1.000000 flags:0
+ret:-5
+ret: 0 st:-1 ts:1.894167 flags:1
+ret: 0 st: 0 dts:1.894059 pts:1.894059 pos:88812 size:4080 flags:1
+ret: 0 st: 0 ts:0.788345 flags:0
+ret: 0 st: 0 dts:0.789546 pts:0.789546 pos:37064 size:4080 flags:1
+ret: 0 st: 0 ts:-0.317506 flags:1
+ret: 0 st: 0 dts:-0.317846 pts:-0.317846 pos:69832 size:4080 flags:1
+ret: 0 st:-1 ts:2.576668 flags:0
+ret: 0 st: 0 dts:2.577642 pts:2.577642 pos:120840 size:4080 flags:1
+ret: 0 st:-1 ts:1.470835 flags:1
+ret: 0 st: 0 dts:1.470249 pts:1.470249 pos:68956 size:4080 flags:1
+ret: 0 st: 0 ts:0.365011 flags:0
+ret: 0 st: 0 dts:0.365737 pts:0.365737 pos:17208 size:4080 flags:1
+ret: 0 st: 0 ts:-0.740839 flags:1
+ret: 0 st: 0 dts:-0.741655 pts:-0.741655 pos:49976 size:4080 flags:1
+ret: 0 st:-1 ts:2.153336 flags:0
+ret: 0 st: 0 dts:2.153855 pts:2.153855 pos:100984 size:4080 flags:1
+ret: 0 st:-1 ts:1.047503 flags:1
+ret: 0 st: 0 dts:1.046440 pts:1.046440 pos:49100 size:4080 flags:1
+ret: 0 st: 0 ts:-0.058322 flags:0
+ret: 0 st: 0 dts:-0.058050 pts:-0.058050 pos:81868 size:4080 flags:1
+ret: 0 st: 0 ts:2.835828 flags:1
+ret: 0 st: 0 dts:2.834535 pts:2.834535 pos:132876 size:4080 flags:1
+ret: 0 st:-1 ts:1.730004 flags:0
+ret: 0 st: 0 dts:1.730045 pts:1.730045 pos:81128 size:4080 flags:1
+ret: 0 st:-1 ts:0.624171 flags:1
+ret: 0 st: 0 dts:0.624082 pts:0.624082 pos:29312 size:4080 flags:1
+ret: 0 st: 0 ts:-0.481655 flags:0
+ret: 0 st: 0 dts:-0.480408 pts:-0.480408 pos:62080 size:4080 flags:1
+ret: 0 st: 0 ts:2.412494 flags:1
+ret: 0 st: 0 dts:2.412200 pts:2.412200 pos:113088 size:4080 flags:1
+ret: 0 st:-1 ts:1.306672 flags:0
+ret: 0 st: 0 dts:1.307687 pts:1.307687 pos:61340 size:4080 flags:1
+ret: 0 st:-1 ts:0.200839 flags:1
+ret: 0 st: 0 dts:0.200295 pts:0.200295 pos:9456 size:4080 flags:1
+ret: 0 st: 0 ts:-0.904989 flags:0
+ret: 0 st: 0 dts:-0.904218 pts:-0.904218 pos:42224 size:4080 flags:1
+ret: 0 st: 0 ts:1.989184 flags:1
+ret: 0 st: 0 dts:1.988390 pts:1.988390 pos:93232 size:4080 flags:1
+ret: 0 st:-1 ts:0.883340 flags:0
+ret: 0 st: 0 dts:0.883900 pts:0.883900 pos:41484 size:4080 flags:1
+ret: 0 st:-1 ts:-0.222493 flags:1
+ret: 0 st: 0 dts:-0.223515 pts:-0.223515 pos:74252 size:4080 flags:1
+ret: 0 st: 0 ts:2.671678 flags:0
+ret: 0 st: 0 dts:2.671995 pts:2.671995 pos:125260 size:4080 flags:1
+ret: 0 st: 0 ts:1.565850 flags:1
+ret: 0 st: 0 dts:1.564580 pts:1.564580 pos:73376 size:4080 flags:1
+ret: 0 st:-1 ts:0.460008 flags:0
+ret: 0 st: 0 dts:0.460091 pts:0.460091 pos:21628 size:4080 flags:1
+ret: 0 st:-1 ts:-0.645825 flags:1
+ret: 0 st: 0 dts:-0.645873 pts:-0.645873 pos:54396 size:4080 flags:1
+----------------
 tests/data/a-adpcm_ms.wav
 ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:56 size:4096 flags:1
 ret: 0 st:-1 ts:-1.000000 flags:0