Commit 4acc790f authored by Justin Ruggles's avatar Justin Ruggles

Split input sample deinterleaving into a separate function.

Originally committed as revision 25989 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 152cc528
...@@ -105,6 +105,40 @@ static int16_t xcos1[128]; ...@@ -105,6 +105,40 @@ static int16_t xcos1[128];
static int16_t xsin1[128]; static int16_t xsin1[128];
/**
* Deinterleave input samples.
* Channels are reordered from FFmpeg's default order to AC-3 order.
*/
static void deinterleave_input_samples(AC3EncodeContext *s,
const int16_t *samples,
int16_t planar_samples[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE+AC3_FRAME_SIZE])
{
int ch, i;
/* deinterleave and remap input samples */
for (ch = 0; ch < s->channels; ch++) {
const int16_t *sptr;
int sinc;
/* copy last 256 samples of previous frame to the start of the current frame */
memcpy(&planar_samples[ch][0], s->last_samples[ch],
AC3_BLOCK_SIZE * sizeof(planar_samples[0][0]));
/* deinterleave */
sinc = s->channels;
sptr = samples + s->channel_map[ch];
for (i = AC3_BLOCK_SIZE; i < AC3_FRAME_SIZE+AC3_BLOCK_SIZE; i++) {
planar_samples[ch][i] = *sptr;
sptr += sinc;
}
/* save last 256 samples for next frame */
memcpy(s->last_samples[ch], &planar_samples[ch][6* AC3_BLOCK_SIZE],
AC3_BLOCK_SIZE * sizeof(planar_samples[0][0]));
}
}
/** /**
* Initialize FFT tables. * Initialize FFT tables.
* @param ln log2(FFT size) * @param ln log2(FFT size)
...@@ -1092,27 +1126,7 @@ static int ac3_encode_frame(AVCodecContext *avctx, ...@@ -1092,27 +1126,7 @@ static int ac3_encode_frame(AVCodecContext *avctx,
int8_t exp_shift[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS]; int8_t exp_shift[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS];
int frame_bits; int frame_bits;
/* deinterleave and remap input samples */ deinterleave_input_samples(s, samples, planar_samples);
for (ch = 0; ch < s->channels; ch++) {
const int16_t *sptr;
int sinc;
/* copy last 256 samples of previous frame to the start of the current frame */
memcpy(&planar_samples[ch][0], s->last_samples[ch],
AC3_BLOCK_SIZE * sizeof(planar_samples[0][0]));
/* deinterleave */
sinc = s->channels;
sptr = samples + s->channel_map[ch];
for (i = AC3_BLOCK_SIZE; i < AC3_FRAME_SIZE+AC3_BLOCK_SIZE; i++) {
planar_samples[ch][i] = *sptr;
sptr += sinc;
}
/* save last 256 samples for next frame */
memcpy(s->last_samples[ch], &planar_samples[ch][6* AC3_BLOCK_SIZE],
AC3_BLOCK_SIZE * sizeof(planar_samples[0][0]));
}
/* apply MDCT */ /* apply MDCT */
for (ch = 0; ch < s->channels; ch++) { for (ch = 0; ch < s->channels; ch++) {
......
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