changeset 5549:b97f9b97e454 libavcodec

Trellis quantization support for adpcm_swf.
author banan
date Sun, 19 Aug 2007 20:31:53 +0000
parents b763947a7676
children a0b2065d5df1
files adpcm.c
diffstat 1 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/adpcm.c	Sun Aug 19 12:36:15 2007 +0000
+++ b/adpcm.c	Sun Aug 19 20:31:53 2007 +0000
@@ -297,7 +297,7 @@
     nodes[0]->step = c->step_index;
     nodes[0]->sample1 = c->sample1;
     nodes[0]->sample2 = c->sample2;
-    if(version == CODEC_ID_ADPCM_IMA_WAV)
+    if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_SWF))
         nodes[0]->sample1 = c->prev_sample;
     if(version == CODEC_ID_ADPCM_MS)
         nodes[0]->step = c->idelta;
@@ -368,7 +368,7 @@
                     next_##NAME:;
                     STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8));
                 }
-            } else if(version == CODEC_ID_ADPCM_IMA_WAV) {
+            } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (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;\
@@ -519,6 +519,8 @@
         PutBitContext pb;
         init_put_bits(&pb, dst, buf_size*8);
 
+        n = avctx->frame_size-1;
+
         //Store AdpcmCodeSize
         put_bits(&pb, 2, 2);                //Set 4bits flash adpcm format
 
@@ -530,10 +532,22 @@
             c->status[i].prev_sample = (signed short)samples[i];
         }
 
+        if(avctx->trellis > 0) {
+            uint8_t buf[2][n];
+            adpcm_compress_trellis(avctx, samples+2, buf[0], &c->status[0], n);
+            if (avctx->channels == 2)
+                adpcm_compress_trellis(avctx, samples+3, buf[1], &c->status[1], n);
+            for(i=0; i<n; i++) {
+                put_bits(&pb, 4, buf[0][i]);
+                if (avctx->channels == 2)
+                    put_bits(&pb, 4, buf[1][i]);
+            }
+        } else {
         for (i=1; i<avctx->frame_size; i++) {
             put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels*i]) & 0xF);
             if (avctx->channels == 2)
                 put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2*i+1]) & 0xF);
+            }
         }
         flush_put_bits(&pb);
         dst += put_bits_count(&pb)>>3;