Mercurial > libavcodec.hg
changeset 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 | c2c29be6282e |
children | ac7bfc9bf1a4 |
files | ac3enc.c |
diffstat | 1 files changed, 13 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ac3enc.c Fri Mar 31 20:43:37 2006 +0000 +++ b/ac3enc.c Mon Apr 03 00:51:09 2006 +0000 @@ -38,6 +38,8 @@ unsigned int bsid; unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */ unsigned int frame_size; /* current frame size in words */ + unsigned int bits_written; + unsigned int samples_written; int halfratecod; unsigned int frmsizecod; unsigned int fscod; /* frequency */ @@ -859,7 +861,8 @@ s->bit_rate = bitrate; s->frmsizecod = i << 1; s->frame_size_min = (bitrate * 1000 * AC3_FRAME_SIZE) / (freq * 16); - /* for now we do not handle fractional sizes */ + s->bits_written = 0; + s->samples_written = 0; s->frame_size = s->frame_size_min; /* bit allocation init */ @@ -1422,6 +1425,15 @@ } } + /* adjust for fractional frame sizes */ + while(s->bits_written >= s->bit_rate*1000 && s->samples_written >= s->sample_rate) { + s->bits_written -= s->bit_rate*1000; + s->samples_written -= s->sample_rate; + } + s->frame_size = s->frame_size_min + (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate*1000); + s->bits_written += s->frame_size * 16; + s->samples_written += AC3_FRAME_SIZE; + compute_bit_allocation(s, bap, encoded_exp, exp_strategy, frame_bits); /* everything is known... let's output the frame */ output_frame_header(s, frame);