diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-11-27 00:30:13 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-11-27 00:30:13 +0100 |
commit | 5c15b78e4a47c46de03d5e7291ed19a717f36885 (patch) | |
tree | a88ba284818fa1b64b1da37872bb4a60bd66a976 /libavcodec/adxenc.c | |
parent | 22cb8e7b3436b6ad12e4e2d588dd8775d2da1684 (diff) | |
parent | 7c5ce99bd92fb480b7235cbc9a005f7e6d31f1d7 (diff) | |
download | ffmpeg-5c15b78e4a47c46de03d5e7291ed19a717f36885.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master: (42 commits)
swscale: fix signed overflow in yuv2mono_X_c_template
snow: fix integer overflows
svq1enc: remove stale altivec-related hack
snow: fix signed overflow in byte to 32-bit replication
adx: rename ff_adx_decode_header() to avpriv_adx_decode_header()
avformat: add CRI ADX format demuxer
adx: add an ADX parser.
adx: move header decoding to ADX common code
adx: calculate the number of blocks in a packet
adx: define and use 2 new macro constants BLOCK_SIZE and BLOCK_SAMPLES
adx: check for unsupported ADX formats
adx: simplify encoding by using put_sbits()
adx: calculate correct LPC coeffs
adx: use 12-bit coefficients instead of 14-bit to avoid integer overflow
adx: simplify adx_decode() by using get_sbits() to read residual samples
adx: fix the data offset parsing in adx_decode_header()
adx: remove unneeded post-decode channel interleaving
adx: validate header values
adx: cosmetics: general pretty-printing and comment clean-up
adx: remove useless comments
...
Conflicts:
Changelog
libavcodec/cook.c
libavcodec/fraps.c
libavcodec/nuv.c
libavcodec/pthread.c
libavcodec/version.h
libavformat/Makefile
libavformat/version.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/adxenc.c')
-rw-r--r-- | libavcodec/adxenc.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c index 893afe0981..51545fa06c 100644 --- a/libavcodec/adxenc.c +++ b/libavcodec/adxenc.c @@ -22,6 +22,7 @@ #include "libavutil/intreadwrite.h" #include "avcodec.h" #include "adx.h" +#include "put_bits.h" /** * @file @@ -34,8 +35,10 @@ /* 18 bytes <-> 32 samples */ -static void adx_encode(unsigned char *adx,const short *wav,PREV *prev) +static void adx_encode(ADXContext *c, unsigned char *adx, const short *wav, + ADXChannelState *prev) { + PutBitContext pb; int scale; int i; int s0,s1,s2,d; @@ -47,7 +50,7 @@ static void adx_encode(unsigned char *adx,const short *wav,PREV *prev) s2 = prev->s2; for(i=0;i<32;i++) { s0 = wav[i]; - d = ((s0<<14) - SCALE1*s1 + SCALE2*s2)/BASEVOL; + d = ((s0 << COEFF_BITS) - c->coeff[0] * s1 - c->coeff[1] * s2) >> COEFF_BITS; data[i]=d; if (max<d) max=d; if (min>d) min=d; @@ -71,9 +74,10 @@ static void adx_encode(unsigned char *adx,const short *wav,PREV *prev) AV_WB16(adx, scale); - for(i=0;i<16;i++) { - adx[i+2] = ((data[i*2]/scale)<<4) | ((data[i*2+1]/scale)&0xf); - } + init_put_bits(&pb, adx + 2, 16); + for (i = 0; i < 32; i++) + put_sbits(&pb, 4, av_clip(data[i]/scale, -8, 7)); + flush_put_bits(&pb); } static int adx_encode_header(AVCodecContext *avctx,unsigned char *buf,size_t bufsize) @@ -101,19 +105,24 @@ static int adx_encode_header(AVCodecContext *avctx,unsigned char *buf,size_t buf } adxhdr; /* big endian */ /* offset-6 "(c)CRI" */ #endif + ADXContext *c = avctx->priv_data; + AV_WB32(buf+0x00,0x80000000|0x20); AV_WB32(buf+0x04,0x03120400|avctx->channels); AV_WB32(buf+0x08,avctx->sample_rate); AV_WB32(buf+0x0c,0); /* FIXME: set after */ - AV_WB32(buf+0x10,0x01040300); - AV_WB32(buf+0x14,0x00000000); - AV_WB32(buf+0x18,0x00000000); - memcpy(buf+0x1c,"\0\0(c)CRI",8); + AV_WB16(buf + 0x10, c->cutoff); + AV_WB32(buf + 0x12, 0x03000000); + AV_WB32(buf + 0x16, 0x00000000); + AV_WB32(buf + 0x1a, 0x00000000); + memcpy (buf + 0x1e, "(c)CRI", 6); return 0x20+4; } static av_cold int adx_encode_init(AVCodecContext *avctx) { + ADXContext *c = avctx->priv_data; + if (avctx->channels > 2) return -1; /* only stereo or mono =) */ avctx->frame_size = 32; @@ -123,6 +132,10 @@ static av_cold int adx_encode_init(AVCodecContext *avctx) // avctx->bit_rate = avctx->sample_rate*avctx->channels*18*8/32; + /* the cutoff can be adjusted, but this seems to work pretty well */ + c->cutoff = 500; + ff_adx_calculate_coeffs(c->cutoff, avctx->sample_rate, COEFF_BITS, c->coeff); + av_log(avctx, AV_LOG_DEBUG, "adx encode init\n"); return 0; @@ -158,7 +171,7 @@ static int adx_encode_frame(AVCodecContext *avctx, if (avctx->channels==1) { while(rest>=32) { - adx_encode(dst,samples,c->prev); + adx_encode(c, dst, samples, c->prev); dst+=18; samples+=32; rest-=32; @@ -173,8 +186,8 @@ static int adx_encode_frame(AVCodecContext *avctx, tmpbuf[i+32] = samples[i*2+1]; } - adx_encode(dst,tmpbuf,c->prev); - adx_encode(dst+18,tmpbuf+32,c->prev+1); + adx_encode(c, dst, tmpbuf, c->prev); + adx_encode(c, dst + 18, tmpbuf + 32, c->prev + 1); dst+=18*2; samples+=32*2; rest-=32*2; |