Commit 95f3019a authored by Justin Ruggles's avatar Justin Ruggles

ac3dec: reorder output channels to SMPTE channel order

Originally committed as revision 18542 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 8b5ec087
...@@ -1233,6 +1233,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, ...@@ -1233,6 +1233,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
AC3DecodeContext *s = avctx->priv_data; AC3DecodeContext *s = avctx->priv_data;
int16_t *out_samples = (int16_t *)data; int16_t *out_samples = (int16_t *)data;
int blk, ch, err; int blk, ch, err;
const uint8_t *channel_map;
/* initialize the GetBitContext with the start of valid AC-3 Frame */ /* initialize the GetBitContext with the start of valid AC-3 Frame */
if (s->input_buffer) { if (s->input_buffer) {
...@@ -1321,6 +1322,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, ...@@ -1321,6 +1322,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
} }
/* decode the audio blocks */ /* decode the audio blocks */
channel_map = ff_ac3_dec_channel_map[s->output_mode & ~AC3_OUTPUT_LFEON][s->lfe_on];
for (blk = 0; blk < s->num_blocks; blk++) { for (blk = 0; blk < s->num_blocks; blk++) {
const float *output[s->out_channels]; const float *output[s->out_channels];
if (!err && decode_audio_block(s, blk)) { if (!err && decode_audio_block(s, blk)) {
...@@ -1328,7 +1330,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, ...@@ -1328,7 +1330,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size,
err = 1; err = 1;
} }
for (ch = 0; ch < s->out_channels; ch++) for (ch = 0; ch < s->out_channels; ch++)
output[ch] = s->output[ch]; output[ch] = s->output[channel_map[ch]];
s->dsp.float_to_int16_interleave(out_samples, output, 256, s->out_channels); s->dsp.float_to_int16_interleave(out_samples, output, 256, s->out_channels);
out_samples += 256 * s->out_channels; out_samples += 256 * s->out_channels;
} }
......
...@@ -79,21 +79,34 @@ const uint8_t ff_ac3_channels_tab[8] = { ...@@ -79,21 +79,34 @@ const uint8_t ff_ac3_channels_tab[8] = {
2, 1, 2, 3, 3, 4, 4, 5 2, 1, 2, 3, 3, 4, 4, 5
}; };
#define COMMON_CHANNEL_MAP \
{ { 0, 1, }, { 0, 1, 2, } },\
{ { 0, }, { 0, 1, } },\
{ { 0, 1, }, { 0, 1, 2, } },\
{ { 0, 2, 1, }, { 0, 2, 1, 3, } },\
{ { 0, 1, 2, }, { 0, 1, 3, 2, } },\
{ { 0, 2, 1, 3, }, { 0, 2, 1, 4, 3, } },
/** /**
* Table to remap channels from SMPTE order to AC-3 order. * Table to remap channels from SMPTE order to AC-3 order.
* [channel_mode][lfe][ch] * [channel_mode][lfe][ch]
*/ */
const uint8_t ff_ac3_enc_channel_map[8][2][6] = { const uint8_t ff_ac3_enc_channel_map[8][2][6] = {
{ { 0, 1, }, { 0, 1, 2, } }, COMMON_CHANNEL_MAP
{ { 0, }, { 0, 1, } },
{ { 0, 1, }, { 0, 1, 2, } },
{ { 0, 2, 1, }, { 0, 2, 1, 3, } },
{ { 0, 1, 2, }, { 0, 1, 3, 2, } },
{ { 0, 2, 1, 3, }, { 0, 2, 1, 4, 3, } },
{ { 0, 1, 2, 3, 4, }, { 0, 1, 3, 4, 2, } }, { { 0, 1, 2, 3, 4, }, { 0, 1, 3, 4, 2, } },
{ { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } }, { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } },
}; };
/**
* Table to remap channels from from AC-3 order to SMPTE order.
* [channel_mode][lfe][ch]
*/
const uint8_t ff_ac3_dec_channel_map[8][2][6] = {
COMMON_CHANNEL_MAP
{ { 0, 1, 2, 3, 4, }, { 0, 1, 4, 2, 3, } },
{ { 0, 2, 1, 3, 4, }, { 0, 2, 1, 5, 3, 4 } },
};
/* possible frequencies */ /* possible frequencies */
const uint16_t ff_ac3_sample_rate_tab[3] = { 48000, 44100, 32000 }; const uint16_t ff_ac3_sample_rate_tab[3] = { 48000, 44100, 32000 };
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
extern const uint16_t ff_ac3_frame_size_tab[38][3]; extern const uint16_t ff_ac3_frame_size_tab[38][3];
extern const uint8_t ff_ac3_channels_tab[8]; extern const uint8_t ff_ac3_channels_tab[8];
extern const uint8_t ff_ac3_enc_channel_map[8][2][6]; extern const uint8_t ff_ac3_enc_channel_map[8][2][6];
extern const uint8_t ff_ac3_dec_channel_map[8][2][6];
extern const uint16_t ff_ac3_sample_rate_tab[3]; extern const uint16_t ff_ac3_sample_rate_tab[3];
extern const uint16_t ff_ac3_bitrate_tab[19]; extern const uint16_t ff_ac3_bitrate_tab[19];
extern const int16_t ff_ac3_window[256]; extern const int16_t ff_ac3_window[256];
......
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