diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2009-04-17 08:39:11 +0000 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2009-04-17 08:39:11 +0000 |
commit | a7c6e1171b1984b949464c4d9070f10a1fd43d6d (patch) | |
tree | bdd1daca2bfc7ecfc91d1550f39ab3940b74b1e2 /libavcodec | |
parent | 35e2e681b820a878903c35b939bf130acdbb5c63 (diff) | |
download | ffmpeg-a7c6e1171b1984b949464c4d9070f10a1fd43d6d.tar.gz |
ac3enc: reorder input channels to AC-3 channel order
Originally committed as revision 18540 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/ac3enc.c | 9 | ||||
-rw-r--r-- | libavcodec/ac3tab.c | 15 | ||||
-rw-r--r-- | libavcodec/ac3tab.h | 1 |
3 files changed, 22 insertions, 3 deletions
diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index e851cdbc5c..4d51c2e187 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -36,6 +36,7 @@ typedef struct AC3EncodeContext { int nb_channels; int nb_all_channels; int lfe_channel; + const uint8_t *channel_map; int bit_rate; unsigned int sample_rate; unsigned int bitstream_id; @@ -638,6 +639,7 @@ static av_cold int AC3_encode_init(AVCodecContext *avctx) s->nb_all_channels = channels; s->nb_channels = channels > 5 ? 5 : channels; s->lfe_channel = s->lfe ? 5 : -1; + s->channel_map = ff_ac3_enc_channel_map[s->channel_mode][s->lfe]; /* frequency */ for(i=0;i<3;i++) { @@ -1158,19 +1160,20 @@ static int AC3_encode_frame(AVCodecContext *avctx, frame_bits = 0; for(ch=0;ch<s->nb_all_channels;ch++) { + int ich = s->channel_map[ch]; /* fixed mdct to the six sub blocks & exponent computation */ for(i=0;i<NB_BLOCKS;i++) { int16_t *sptr; int sinc; /* compute input samples */ - memcpy(input_samples, s->last_samples[ch], N/2 * sizeof(int16_t)); + memcpy(input_samples, s->last_samples[ich], N/2 * sizeof(int16_t)); sinc = s->nb_all_channels; - sptr = samples + (sinc * (N/2) * i) + ch; + sptr = samples + (sinc * (N/2) * i) + ich; for(j=0;j<N/2;j++) { v = *sptr; input_samples[j + N/2] = v; - s->last_samples[ch][j] = v; + s->last_samples[ich][j] = v; sptr += sinc; } diff --git a/libavcodec/ac3tab.c b/libavcodec/ac3tab.c index 69ede84de8..36a7449a72 100644 --- a/libavcodec/ac3tab.c +++ b/libavcodec/ac3tab.c @@ -79,6 +79,21 @@ const uint8_t ff_ac3_channels_tab[8] = { 2, 1, 2, 3, 3, 4, 4, 5 }; +/** + * Table to remap channels from SMPTE order to AC-3 order. + * [channel_mode][lfe][ch] + */ +const uint8_t ff_ac3_enc_channel_map[8][2][6] = { + { { 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, } }, + { { 0, 1, 2, 3, 4, }, { 0, 1, 3, 4, 2, } }, + { { 0, 2, 1, 3, 4, }, { 0, 2, 1, 4, 5, 3 } }, +}; + /* possible frequencies */ const uint16_t ff_ac3_sample_rate_tab[3] = { 48000, 44100, 32000 }; diff --git a/libavcodec/ac3tab.h b/libavcodec/ac3tab.h index c76b187a36..300e3c6bc0 100644 --- a/libavcodec/ac3tab.h +++ b/libavcodec/ac3tab.h @@ -26,6 +26,7 @@ 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_enc_channel_map[8][2][6]; extern const uint16_t ff_ac3_sample_rate_tab[3]; extern const uint16_t ff_ac3_bitrate_tab[19]; extern const int16_t ff_ac3_window[256]; |