changeset 9452:42803399ba8a libavcodec

ac3enc: reorder input channels to AC-3 channel order
author jbr
date Fri, 17 Apr 2009 08:39:11 +0000
parents 93c20dd3da43
children b5bc4764ff7a
files ac3enc.c ac3tab.c ac3tab.h
diffstat 3 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ac3enc.c	Thu Apr 16 08:39:13 2009 +0000
+++ b/ac3enc.c	Fri Apr 17 08:39:11 2009 +0000
@@ -36,6 +36,7 @@
     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 @@
     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 @@
 
     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;
             }
 
--- a/ac3tab.c	Thu Apr 16 08:39:13 2009 +0000
+++ b/ac3tab.c	Fri Apr 17 08:39:11 2009 +0000
@@ -79,6 +79,21 @@
     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 };
 
--- a/ac3tab.h	Thu Apr 16 08:39:13 2009 +0000
+++ b/ac3tab.h	Fri Apr 17 08:39:11 2009 +0000
@@ -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];