Commit f760b70f authored by Justin Ruggles's avatar Justin Ruggles Committed by Corey Hickey

AC3: support encoding fractional frame sizes

Patch by Justin Ruggles, jruggle <<at>> earthlink <<dot>> net

Originally committed as revision 5263 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent c4e7baa8
...@@ -38,6 +38,8 @@ typedef struct AC3EncodeContext { ...@@ -38,6 +38,8 @@ typedef struct AC3EncodeContext {
unsigned int bsid; unsigned int bsid;
unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */ unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */
unsigned int frame_size; /* current frame size in words */ unsigned int frame_size; /* current frame size in words */
unsigned int bits_written;
unsigned int samples_written;
int halfratecod; int halfratecod;
unsigned int frmsizecod; unsigned int frmsizecod;
unsigned int fscod; /* frequency */ unsigned int fscod; /* frequency */
...@@ -859,7 +861,8 @@ static int AC3_encode_init(AVCodecContext *avctx) ...@@ -859,7 +861,8 @@ static int AC3_encode_init(AVCodecContext *avctx)
s->bit_rate = bitrate; s->bit_rate = bitrate;
s->frmsizecod = i << 1; s->frmsizecod = i << 1;
s->frame_size_min = (bitrate * 1000 * AC3_FRAME_SIZE) / (freq * 16); 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; s->frame_size = s->frame_size_min;
/* bit allocation init */ /* bit allocation init */
...@@ -1422,6 +1425,15 @@ static int AC3_encode_frame(AVCodecContext *avctx, ...@@ -1422,6 +1425,15 @@ static int AC3_encode_frame(AVCodecContext *avctx,
} }
} }
/* 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); compute_bit_allocation(s, bap, encoded_exp, exp_strategy, frame_bits);
/* everything is known... let's output the frame */ /* everything is known... let's output the frame */
output_frame_header(s, frame); output_frame_header(s, frame);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment