From d1015e88b44d0312470bf1f24fd3c9360f6f69a6 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 24 Jun 2006 13:56:29 +0000 Subject: [PATCH] simplify & optimize things a little Originally committed as revision 5516 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/flacenc.c | 75 ++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index 76855ffabe..d88b11d4c4 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -82,10 +82,6 @@ static const int flac_blocksizes[16] = { 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }; -static const int flac_blocksizes_ordered[14] = { - 0, 192, 256, 512, 576, 1024, 1152, 2048, 2304, 4096, 4608, 8192, 16384, 32768 -}; - /** * Writes streaminfo metadata block to byte array */ @@ -122,17 +118,13 @@ static int select_blocksize(int samplerate) int blocksize; assert(samplerate > 0); - blocksize = 0; + blocksize = flac_blocksizes[1]; target = (samplerate * BLOCK_TIME_MS) / 1000; - for(i=13; i>=0; i--) { - if(target >= flac_blocksizes_ordered[i]) { - blocksize = flac_blocksizes_ordered[i]; - break; + for(i=0; i<16; i++) { + if(target >= flac_blocksizes[i] && flac_blocksizes[i] > blocksize) { + blocksize = flac_blocksizes[i]; } } - if(blocksize == 0) { - blocksize = flac_blocksizes_ordered[1]; - } return blocksize; } @@ -144,10 +136,6 @@ static int flac_encode_init(AVCodecContext *avctx) int i; uint8_t *streaminfo; - if(s == NULL) { - return -1; - } - if(avctx->sample_fmt != SAMPLE_FMT_S16) { return -1; } @@ -282,26 +270,26 @@ static void encode_residual_verbatim(FlacEncodeContext *s, int ch) static void encode_residual_fixed(int32_t *res, int32_t *smp, int n, int order) { int i; - int32_t pred; for(i=0; i= 0 && bits <= 31); - uval = (val < 0) ? (1UL << bits) + val : val; - put_bits(pb, bits, uval); + + put_bits(pb, bits, val & ((1<= 0x80) bytes++; - if(val >= 0x800) bytes++; - if(val >= 0x10000) bytes++; - if(val >= 0x200000) bytes++; - if(val >= 0x4000000) bytes++; + int bytes, shift; - if(bytes == 1) { + if(val < 0x80){ put_bits(pb, 8, val); return; } + bytes= (av_log2(val)-1) / 5; shift = (bytes - 1) * 6; - mask = 0x80 + ((1 << 7) - (1 << (8 - bytes))); - put_bits(pb, 8, mask | (val >> shift)); - for(i=0; i>bytes)) | (val >> shift)); + while(shift >= 6){ shift -= 6; put_bits(pb, 8, 0x80 | ((val >> shift) & 0x3F)); }