IMA ADPCM encoder - QT variant

Originally committed as revision 12348 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Kostya Shishkov 17 years ago
parent 11c55efa34
commit 9dc92a38a0
  1. 1
      Changelog
  2. 1
      Makefile
  3. 2
      doc/general.texi
  4. 40
      libavcodec/adpcm.c
  5. 2
      libavcodec/allcodecs.c
  6. 4
      libavcodec/avcodec.h
  7. 4
      tests/ffmpeg.regression.ref
  8. 5
      tests/regression.sh
  9. 4
      tests/rotozoom.regression.ref
  10. 55
      tests/seek.regression.ref

@ -110,6 +110,7 @@ version <next>
- TechnoTrend PVA demuxer - TechnoTrend PVA demuxer
- Linux Media Labs MPEG-4 (LMLM4) demuxer - Linux Media Labs MPEG-4 (LMLM4) demuxer
- AVM2 (Flash 9) SWF muxer - AVM2 (Flash 9) SWF muxer
- QT variant of IMA ADPCM encoder
version 0.4.9-pre1: version 0.4.9-pre1:

@ -314,6 +314,7 @@ CODEC_TESTS = $(addprefix regtest-, \
ac3 \ ac3 \
g726 \ g726 \
adpcm_ima_wav \ adpcm_ima_wav \
adpcm_ima_qt \
adpcm_ms \ adpcm_ms \
adpcm_yam \ adpcm_yam \
adpcm_swf \ adpcm_swf \

@ -261,7 +261,7 @@ following image formats are supported:
@item AMV IMA ADPCM @tab @tab X @item AMV IMA ADPCM @tab @tab X
@tab Used in AMV files @tab Used in AMV files
@item MS IMA ADPCM @tab X @tab X @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 4X IMA ADPCM @tab @tab X
@item G.726 ADPCM @tab X @tab X @item G.726 ADPCM @tab X @tab X
@item Duck DK3 IMA ADPCM @tab @tab X @item Duck DK3 IMA ADPCM @tab @tab X

@ -165,6 +165,10 @@ static int adpcm_encode_init(AVCodecContext *avctx)
avctx->block_align = BLKSIZE; avctx->block_align = BLKSIZE;
/* seems frame_size isn't taken into account... have to buffer the samples :-( */ /* seems frame_size isn't taken into account... have to buffer the samples :-( */
break; break;
case CODEC_ID_ADPCM_IMA_QT:
avctx->frame_size = 64;
avctx->block_align = 34 * avctx->channels;
break;
case CODEC_ID_ADPCM_MS: case CODEC_ID_ADPCM_MS:
avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */ 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 */ /* 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]->step = c->step_index;
nodes[0]->sample1 = c->sample1; nodes[0]->sample1 = c->sample1;
nodes[0]->sample2 = c->sample2; 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; nodes[0]->sample1 = c->prev_sample;
if(version == CODEC_ID_ADPCM_MS) if(version == CODEC_ID_ADPCM_MS)
nodes[0]->step = c->idelta; nodes[0]->step = c->idelta;
@ -366,7 +370,7 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples,
next_##NAME:; next_##NAME:;
STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8)); 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)\ #define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\
const int predictor = nodes[j]->sample1;\ const int predictor = nodes[j]->sample1;\
const int div = (sample - predictor) * 4 / STEP_TABLE;\ const int div = (sample - predictor) * 4 / STEP_TABLE;\
@ -509,6 +513,36 @@ static int adpcm_encode_frame(AVCodecContext *avctx,
samples += 8 * avctx->channels; samples += 8 * avctx->channels;
} }
break; 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: case CODEC_ID_ADPCM_SWF:
{ {
int i; 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_DK4, adpcm_ima_dk4);
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs); 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_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_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
ADPCM_CODEC (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav); ADPCM_CODEC (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws); ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws);

@ -249,7 +249,7 @@ void avcodec_register_all(void)
REGISTER_DECODER (ADPCM_IMA_DK4, adpcm_ima_dk4); REGISTER_DECODER (ADPCM_IMA_DK4, adpcm_ima_dk4);
REGISTER_DECODER (ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs); REGISTER_DECODER (ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs);
REGISTER_DECODER (ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead); 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_DECODER (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg);
REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav); REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav);
REGISTER_DECODER (ADPCM_IMA_WS, adpcm_ima_ws); REGISTER_DECODER (ADPCM_IMA_WS, adpcm_ima_ws);

@ -31,8 +31,8 @@
#include <sys/types.h> /* size_t */ #include <sys/types.h> /* size_t */
#define LIBAVCODEC_VERSION_MAJOR 51 #define LIBAVCODEC_VERSION_MAJOR 51
#define LIBAVCODEC_VERSION_MINOR 50 #define LIBAVCODEC_VERSION_MINOR 51
#define LIBAVCODEC_VERSION_MICRO 1 #define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \ LIBAVCODEC_VERSION_MINOR, \

@ -179,6 +179,10 @@ stddev:8368.02 PSNR:17.87 bytes:96256
266300 ./tests/data/a-adpcm_ima.wav 266300 ./tests/data/a-adpcm_ima.wav
947196b1739a9d6fe0c29424cf61cd8c *./tests/data/adpcm_ima_wav.vsynth.out.wav 947196b1739a9d6fe0c29424cf61cd8c *./tests/data/adpcm_ima_wav.vsynth.out.wav
stddev:904.20 PSNR:37.19 bytes:1056768 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 628d4789cf9ee16a756ac54b7fd8650d *./tests/data/a-adpcm_ms.wav
267320 ./tests/data/a-adpcm_ms.wav 267320 ./tests/data/a-adpcm_ms.wav
91a84bb4f319a3a0bf0c0441b3d3a529 *./tests/data/adpcm_ms.vsynth.out.wav 91a84bb4f319a3a0bf0c0441b3d3a529 *./tests/data/adpcm_ms.vsynth.out.wav

@ -401,6 +401,11 @@ do_audio_encoding adpcm_ima.wav "-ar 44100" "-acodec adpcm_ima_wav"
do_audio_decoding do_audio_decoding
fi 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 if [ -n "$do_adpcm_ms" ] ; then
do_audio_encoding adpcm_ms.wav "-ar 44100" "-acodec adpcm_ms" do_audio_encoding adpcm_ms.wav "-ar 44100" "-acodec adpcm_ms"
do_audio_decoding do_audio_decoding

@ -179,6 +179,10 @@ stddev:8368.02 PSNR:17.87 bytes:96256
266300 ./tests/data/a-adpcm_ima.wav 266300 ./tests/data/a-adpcm_ima.wav
947196b1739a9d6fe0c29424cf61cd8c *./tests/data/adpcm_ima_wav.rotozoom.out.wav 947196b1739a9d6fe0c29424cf61cd8c *./tests/data/adpcm_ima_wav.rotozoom.out.wav
stddev:904.20 PSNR:37.19 bytes:1056768 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 628d4789cf9ee16a756ac54b7fd8650d *./tests/data/a-adpcm_ms.wav
267320 ./tests/data/a-adpcm_ms.wav 267320 ./tests/data/a-adpcm_ms.wav
91a84bb4f319a3a0bf0c0441b3d3a529 *./tests/data/adpcm_ms.rotozoom.out.wav 91a84bb4f319a3a0bf0c0441b3d3a529 *./tests/data/adpcm_ms.rotozoom.out.wav

@ -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:-1 ts:-0.645825 flags:1
ret: 0 st: 0 dts:-0.703991 pts:-0.703991 pos:41020 size:4096 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 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: 0 dts:0.000000 pts:0.000000 pos:56 size:4096 flags:1
ret: 0 st:-1 ts:-1.000000 flags:0 ret: 0 st:-1 ts:-1.000000 flags:0

Loading…
Cancel
Save