Mercurial > libavcodec.hg
comparison ac3enc.c @ 3246:219afc0c4a80 libavcodec
AC3: support encoding fractional frame sizes
Patch by Justin Ruggles, jruggle <<at>> earthlink <<dot>> net
author | corey |
---|---|
date | Mon, 03 Apr 2006 00:51:09 +0000 |
parents | ed485fd3f984 |
children | 8d42d21e570c |
comparison
equal
deleted
inserted
replaced
3245:c2c29be6282e | 3246:219afc0c4a80 |
---|---|
36 int bit_rate; | 36 int bit_rate; |
37 unsigned int sample_rate; | 37 unsigned int sample_rate; |
38 unsigned int bsid; | 38 unsigned int bsid; |
39 unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */ | 39 unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */ |
40 unsigned int frame_size; /* current frame size in words */ | 40 unsigned int frame_size; /* current frame size in words */ |
41 unsigned int bits_written; | |
42 unsigned int samples_written; | |
41 int halfratecod; | 43 int halfratecod; |
42 unsigned int frmsizecod; | 44 unsigned int frmsizecod; |
43 unsigned int fscod; /* frequency */ | 45 unsigned int fscod; /* frequency */ |
44 unsigned int acmod; | 46 unsigned int acmod; |
45 int lfe; | 47 int lfe; |
857 if (i == 19) | 859 if (i == 19) |
858 return -1; | 860 return -1; |
859 s->bit_rate = bitrate; | 861 s->bit_rate = bitrate; |
860 s->frmsizecod = i << 1; | 862 s->frmsizecod = i << 1; |
861 s->frame_size_min = (bitrate * 1000 * AC3_FRAME_SIZE) / (freq * 16); | 863 s->frame_size_min = (bitrate * 1000 * AC3_FRAME_SIZE) / (freq * 16); |
862 /* for now we do not handle fractional sizes */ | 864 s->bits_written = 0; |
865 s->samples_written = 0; | |
863 s->frame_size = s->frame_size_min; | 866 s->frame_size = s->frame_size_min; |
864 | 867 |
865 /* bit allocation init */ | 868 /* bit allocation init */ |
866 for(ch=0;ch<s->nb_channels;ch++) { | 869 for(ch=0;ch<s->nb_channels;ch++) { |
867 /* bandwidth for each channel */ | 870 /* bandwidth for each channel */ |
1420 } | 1423 } |
1421 i = j; | 1424 i = j; |
1422 } | 1425 } |
1423 } | 1426 } |
1424 | 1427 |
1428 /* adjust for fractional frame sizes */ | |
1429 while(s->bits_written >= s->bit_rate*1000 && s->samples_written >= s->sample_rate) { | |
1430 s->bits_written -= s->bit_rate*1000; | |
1431 s->samples_written -= s->sample_rate; | |
1432 } | |
1433 s->frame_size = s->frame_size_min + (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate*1000); | |
1434 s->bits_written += s->frame_size * 16; | |
1435 s->samples_written += AC3_FRAME_SIZE; | |
1436 | |
1425 compute_bit_allocation(s, bap, encoded_exp, exp_strategy, frame_bits); | 1437 compute_bit_allocation(s, bap, encoded_exp, exp_strategy, frame_bits); |
1426 /* everything is known... let's output the frame */ | 1438 /* everything is known... let's output the frame */ |
1427 output_frame_header(s, frame); | 1439 output_frame_header(s, frame); |
1428 | 1440 |
1429 for(i=0;i<NB_BLOCKS;i++) { | 1441 for(i=0;i<NB_BLOCKS;i++) { |