1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

ac3enc: reorder input channels to AC-3 channel order

Originally committed as revision 18540 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Justin Ruggles 2009-04-17 08:39:11 +00:00
parent 35e2e681b8
commit a7c6e1171b
3 changed files with 22 additions and 3 deletions

View File

@ -36,6 +36,7 @@ typedef struct AC3EncodeContext {
int nb_channels; int nb_channels;
int nb_all_channels; int nb_all_channels;
int lfe_channel; int lfe_channel;
const uint8_t *channel_map;
int bit_rate; int bit_rate;
unsigned int sample_rate; unsigned int sample_rate;
unsigned int bitstream_id; unsigned int bitstream_id;
@ -638,6 +639,7 @@ static av_cold int AC3_encode_init(AVCodecContext *avctx)
s->nb_all_channels = channels; s->nb_all_channels = channels;
s->nb_channels = channels > 5 ? 5 : channels; s->nb_channels = channels > 5 ? 5 : channels;
s->lfe_channel = s->lfe ? 5 : -1; s->lfe_channel = s->lfe ? 5 : -1;
s->channel_map = ff_ac3_enc_channel_map[s->channel_mode][s->lfe];
/* frequency */ /* frequency */
for(i=0;i<3;i++) { for(i=0;i<3;i++) {
@ -1158,19 +1160,20 @@ static int AC3_encode_frame(AVCodecContext *avctx,
frame_bits = 0; frame_bits = 0;
for(ch=0;ch<s->nb_all_channels;ch++) { for(ch=0;ch<s->nb_all_channels;ch++) {
int ich = s->channel_map[ch];
/* fixed mdct to the six sub blocks & exponent computation */ /* fixed mdct to the six sub blocks & exponent computation */
for(i=0;i<NB_BLOCKS;i++) { for(i=0;i<NB_BLOCKS;i++) {
int16_t *sptr; int16_t *sptr;
int sinc; int sinc;
/* compute input samples */ /* 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; 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++) { for(j=0;j<N/2;j++) {
v = *sptr; v = *sptr;
input_samples[j + N/2] = v; input_samples[j + N/2] = v;
s->last_samples[ch][j] = v; s->last_samples[ich][j] = v;
sptr += sinc; sptr += sinc;
} }

View File

@ -79,6 +79,21 @@ const uint8_t ff_ac3_channels_tab[8] = {
2, 1, 2, 3, 3, 4, 4, 5 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 */ /* 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 };

View File

@ -26,6 +26,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 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];