[FFmpeg-cvslog] r18540 - in trunk/libavcodec: ac3enc.c ac3tab.c ac3tab.h

jbr subversion
Fri Apr 17 10:39:12 CEST 2009


Author: jbr
Date: Fri Apr 17 10:39:11 2009
New Revision: 18540

Log:
ac3enc: reorder input channels to AC-3 channel order

Modified:
   trunk/libavcodec/ac3enc.c
   trunk/libavcodec/ac3tab.c
   trunk/libavcodec/ac3tab.h

Modified: trunk/libavcodec/ac3enc.c
==============================================================================
--- trunk/libavcodec/ac3enc.c	Thu Apr 16 18:54:35 2009	(r18539)
+++ trunk/libavcodec/ac3enc.c	Fri Apr 17 10:39:11 2009	(r18540)
@@ -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(AVCod
     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(AVCodecConte
 
     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;
             }
 

Modified: trunk/libavcodec/ac3tab.c
==============================================================================
--- trunk/libavcodec/ac3tab.c	Thu Apr 16 18:54:35 2009	(r18539)
+++ trunk/libavcodec/ac3tab.c	Fri Apr 17 10:39:11 2009	(r18540)
@@ -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 };
 

Modified: trunk/libavcodec/ac3tab.h
==============================================================================
--- trunk/libavcodec/ac3tab.h	Thu Apr 16 18:54:35 2009	(r18539)
+++ trunk/libavcodec/ac3tab.h	Fri Apr 17 10:39:11 2009	(r18540)
@@ -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];



More information about the ffmpeg-cvslog mailing list