[FFmpeg-soc] [soc]: r2709 - in aacenc: aacenc.c aacpsy.c aacpsy.h

kostya subversion at mplayerhq.hu
Mon Jul 7 08:16:24 CEST 2008


Author: kostya
Date: Mon Jul  7 08:16:24 2008
New Revision: 2709

Log:
Sync structure declarations with AAC decoder

Modified:
   aacenc/aacenc.c
   aacenc/aacpsy.c
   aacenc/aacpsy.h

Modified: aacenc/aacenc.c
==============================================================================
--- aacenc/aacenc.c	(original)
+++ aacenc/aacenc.c	Mon Jul  7 08:16:24 2008
@@ -177,7 +177,7 @@ typedef struct {
     int swb_num1024;
     const uint8_t *swb_sizes128;
     int swb_num128;
-    cpe_struct cpe;
+    ChannelElement cpe;
     AACPsyContext psy;
 } AACEncContext;
 
@@ -240,7 +240,7 @@ static int aac_encode_init(AVCodecContex
     return 0;
 }
 
-static void analyze(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, short *audio, int channel)
+static void analyze(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, short *audio, int channel)
 {
     int i, j, k;
 
@@ -270,14 +270,14 @@ static void analyze(AVCodecContext *avct
  * Encode ics_info element.
  * @see Table 4.6
  */
-static void put_ics_info(AVCodecContext *avctx, ics_struct *info)
+static void put_ics_info(AVCodecContext *avctx, IndividualChannelStream *info)
 {
     AACEncContext *s = avctx->priv_data;
     int i;
 
     put_bits(&s->pb, 1, 0);                // ics_reserved bit
     put_bits(&s->pb, 2, info->window_sequence);
-    put_bits(&s->pb, 1, info->window_shape);
+    put_bits(&s->pb, 1, info->use_kb_window[0]);
     if(info->window_sequence != EIGHT_SHORT_SEQUENCE){
         put_bits(&s->pb, 6, info->max_sfb);
         put_bits(&s->pb, 1, 0);            // no prediction
@@ -292,7 +292,7 @@ static void put_ics_info(AVCodecContext 
  * Encode MS data.
  * @see 4.6.8.1
  */
-static void encode_ms_info(PutBitContext *pb, cpe_struct *cpe)
+static void encode_ms_info(PutBitContext *pb, ChannelElement *cpe)
 {
     int i, w;
 
@@ -308,7 +308,7 @@ static void encode_ms_info(PutBitContext
 /**
  * Scan spectral band and determine optimal codebook for it.
  */
-static int determine_section_info(AACEncContext *s, cpe_struct *cpe, int channel, int win, int band, int start, int size)
+static int determine_section_info(AACEncContext *s, ChannelElement *cpe, int channel, int win, int band, int start, int size)
 {
     int i, j, w;
     int maxval, sign;
@@ -371,7 +371,7 @@ static int determine_section_info(AACEnc
     return bestcb;
 }
 
-static void encode_codebook(AACEncContext *s, cpe_struct *cpe, int channel, int start, int size, int cb)
+static void encode_codebook(AACEncContext *s, ChannelElement *cpe, int channel, int start, int size, int cb)
 {
     const uint8_t *bits = aac_cb_info[cb].bits;
     const uint16_t *codes = aac_cb_info[cb].codes;
@@ -421,7 +421,7 @@ static void encode_codebook(AACEncContex
     }
 }
 
-static void encode_section_data(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, int channel)
+static void encode_section_data(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel)
 {
     int i, w;
     int bits = cpe->ch[channel].ics.num_windows == 1 ? 5 : 3;
@@ -455,7 +455,7 @@ static void encode_section_data(AVCodecC
     }
 }
 
-static void encode_scale_factor_data(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, int channel)
+static void encode_scale_factor_data(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel)
 {
     int off = cpe->ch[channel].gain, diff;
     int i, w;
@@ -473,22 +473,22 @@ static void encode_scale_factor_data(AVC
     }
 }
 
-static void encode_pulse_data(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, int channel)
+static void encode_pulse_data(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel)
 {
     int i;
 
     put_bits(&s->pb, 1, cpe->ch[channel].pulse.present);
     if(!cpe->ch[channel].pulse.present) return;
 
-    put_bits(&s->pb, 2, cpe->ch[channel].pulse.num_pulse_minus1);
+    put_bits(&s->pb, 2, cpe->ch[channel].pulse.num_pulse - 1);
     put_bits(&s->pb, 6, cpe->ch[channel].pulse.start);
-    for(i = 0; i <= cpe->ch[channel].pulse.num_pulse_minus1; i++){
+    for(i = 0; i < cpe->ch[channel].pulse.num_pulse; i++){
         put_bits(&s->pb, 5, cpe->ch[channel].pulse.offset[i]);
         put_bits(&s->pb, 4, cpe->ch[channel].pulse.amp[i]);
     }
 }
 
-static void encode_tns_data(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, int channel)
+static void encode_tns_data(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel)
 {
     int i, w;
 
@@ -525,7 +525,7 @@ static void encode_tns_data(AVCodecConte
     }
 }
 
-static void encode_spectral_data(AVCodecContext *avctx, AACEncContext *s, cpe_struct *cpe, int channel)
+static void encode_spectral_data(AVCodecContext *avctx, AACEncContext *s, ChannelElement *cpe, int channel)
 {
     int start, i, w, w2;
 
@@ -550,7 +550,7 @@ static void encode_spectral_data(AVCodec
 /**
  * Encode one channel of audio data.
  */
-static int encode_individual_channel(AVCodecContext *avctx, cpe_struct *cpe, int channel)
+static int encode_individual_channel(AVCodecContext *avctx, ChannelElement *cpe, int channel)
 {
     AACEncContext *s = avctx->priv_data;
     int i, g, w;

Modified: aacenc/aacpsy.c
==============================================================================
--- aacenc/aacpsy.c	(original)
+++ aacenc/aacpsy.c	Mon Jul  7 08:16:24 2008
@@ -76,7 +76,7 @@ static inline float calc_distortion(floa
 /**
  * Produce integer coefficients from scalefactors provided by model.
  */
-static void psy_create_output(AACPsyContext *apc, cpe_struct *cpe, int search_pulses)
+static void psy_create_output(AACPsyContext *apc, ChannelElement *cpe, int search_pulses)
 {
     int i, w, w2, g, ch;
     int start, sum, maxsfb, cmaxsfb;
@@ -115,7 +115,7 @@ static void psy_create_output(AACPsyCont
                     if(pulses){
                         cpe->ch[ch].pulse.present = 1;
                         cpe->ch[ch].pulse.start = g;
-                        cpe->ch[ch].pulse.num_pulse_minus1 = pulses - 1;
+                        cpe->ch[ch].pulse.num_pulse = pulses;
                         for(i = 0; i < pulses; i++){
                             cpe->ch[ch].pulse.amp[i] = pamp[i];
                             cpe->ch[ch].pulse.offset[i] = i ? poff[i] - poff[i-1] : poff[0];
@@ -164,22 +164,22 @@ static void psy_create_output(AACPsyCont
     }
 }
 
-static void psy_null_window(AACPsyContext *apc, int16_t *audio, int channel, cpe_struct *cpe)
+static void psy_null_window(AACPsyContext *apc, int16_t *audio, int channel, ChannelElement *cpe)
 {
     int ch;
 
     for(ch = 0; ch < apc->avctx->channels; ch++){
         cpe->ch[ch].ics.window_sequence = ONLY_LONG_SEQUENCE;
-        cpe->ch[ch].ics.window_shape = 1;
+        cpe->ch[ch].ics.use_kb_window[0] = 1;
         cpe->ch[ch].ics.num_windows = 1;
         cpe->ch[ch].ics.swb_sizes = apc->bands1024;
         cpe->ch[ch].ics.num_swb = apc->num_bands1024;
         cpe->ch[ch].ics.group_len[0] = 0;
     }
-    cpe->common_window = cpe->ch[0].ics.window_shape == cpe->ch[1].ics.window_shape;
+    cpe->common_window = cpe->ch[0].ics.use_kb_window[0] == cpe->ch[1].ics.use_kb_window[0];
 }
 
-static void psy_null_process(AACPsyContext *apc, int16_t *audio, int channel, cpe_struct *cpe)
+static void psy_null_process(AACPsyContext *apc, int16_t *audio, int channel, ChannelElement *cpe)
 {
     int start;
     int ch, g, i;
@@ -220,23 +220,23 @@ static void psy_null_process(AACPsyConte
     psy_create_output(apc, cpe, 1);
 }
 
-static void psy_null8_window(AACPsyContext *apc, int16_t *audio, int channel, cpe_struct *cpe)
+static void psy_null8_window(AACPsyContext *apc, int16_t *audio, int channel, ChannelElement *cpe)
 {
     int ch, i;
 
     for(ch = 0; ch < apc->avctx->channels; ch++){
         cpe->ch[ch].ics.window_sequence = EIGHT_SHORT_SEQUENCE;
-        cpe->ch[ch].ics.window_shape = 1;
+        cpe->ch[ch].ics.use_kb_window[0] = 1;
         cpe->ch[ch].ics.num_windows = 8;
         cpe->ch[ch].ics.swb_sizes = apc->bands128;
         cpe->ch[ch].ics.num_swb = apc->num_bands128;
         for(i = 0; i < cpe->ch[ch].ics.num_windows; i++)
             cpe->ch[ch].ics.group_len[i] = i & 1;
     }
-    cpe->common_window = cpe->ch[0].ics.window_shape == cpe->ch[1].ics.window_shape;
+    cpe->common_window = cpe->ch[0].ics.use_kb_window[0] == cpe->ch[1].ics.use_kb_window[0];
 }
 
-static void psy_null8_process(AACPsyContext *apc, int16_t *audio, int channel, cpe_struct *cpe)
+static void psy_null8_process(AACPsyContext *apc, int16_t *audio, int channel, ChannelElement *cpe)
 {
     int start;
     int w, ch, g, i;
@@ -379,20 +379,20 @@ static int psy_3gpp_init(AACPsyContext *
  * Tell encoder which window types to use.
  * @see 3GPP TS26.403 5.4.1
  */
-static void psy_3gpp_window(AACPsyContext *apc, int16_t *audio, int channel, cpe_struct *cpe)
+static void psy_3gpp_window(AACPsyContext *apc, int16_t *audio, int channel, ChannelElement *cpe)
 {
     int ch;
 
 //XXX: stub, because encoder does not support long to short window transition yet :(
     for(ch = 0; ch < apc->avctx->channels; ch++){
         cpe->ch[ch].ics.window_sequence = ONLY_LONG_SEQUENCE;
-        cpe->ch[ch].ics.window_shape = 1;
+        cpe->ch[ch].ics.use_kb_window[0] = 1;
         cpe->ch[ch].ics.num_windows = 1;
         cpe->ch[ch].ics.swb_sizes = apc->bands1024;
         cpe->ch[ch].ics.num_swb = apc->num_bands1024;
         cpe->ch[ch].ics.group_len[0] = 0;
     }
-    cpe->common_window = cpe->ch[0].ics.window_shape == cpe->ch[1].ics.window_shape;
+    cpe->common_window = cpe->ch[0].ics.use_kb_window[0] == cpe->ch[1].ics.use_kb_window[0];
 }
 
 /**
@@ -409,7 +409,7 @@ static inline float modify_thr(float thr
  * Determine scalefactors and prepare coefficients for encoding.
  * @see 3GPP TS26.403 5.4
  */
-static void psy_3gpp_process(AACPsyContext *apc, int16_t *audio, int channel, cpe_struct *cpe)
+static void psy_3gpp_process(AACPsyContext *apc, int16_t *audio, int channel, ChannelElement *cpe)
 {
     int start;
     int ch, g, i;
@@ -617,12 +617,12 @@ int ff_aac_psy_init(AACPsyContext *ctx, 
     return 0;
 }
 
-void ff_aac_psy_suggest_window(AACPsyContext *ctx, int16_t *audio, int channel, cpe_struct *cpe)
+void ff_aac_psy_suggest_window(AACPsyContext *ctx, int16_t *audio, int channel, ChannelElement *cpe)
 {
     ctx->model->window(ctx, audio, channel, cpe);
 }
 
-void ff_aac_psy_analyze(AACPsyContext *ctx, int16_t *audio, int channel, cpe_struct *cpe)
+void ff_aac_psy_analyze(AACPsyContext *ctx, int16_t *audio, int channel, ChannelElement *cpe)
 {
     ctx->model->process(ctx, audio, channel, cpe);
 }

Modified: aacenc/aacpsy.h
==============================================================================
--- aacenc/aacpsy.h	(original)
+++ aacenc/aacpsy.h	Mon Jul  7 08:16:24 2008
@@ -35,35 +35,48 @@ enum AACPsyModelType{
 
 // data structures borrowed from aac.c with some minor modifications
 /**
- * Window sequences
+ * window sequences
  */
-enum {
-    ONLY_LONG_SEQUENCE = 0,
+enum WindowSequence {
+    ONLY_LONG_SEQUENCE,
     LONG_START_SEQUENCE,
     EIGHT_SHORT_SEQUENCE,
-    LONG_STOP_SEQUENCE
+    LONG_STOP_SEQUENCE,
 };
 
 /**
- * Pulse tool
+ * special codebooks
+ */
+enum Codebook {
+    ZERO_HCB       = 0,
+    FIRST_PAIR_HCB = 5,
+    ESC_HCB        = 11,
+    NOISE_HCB      = 13,
+    INTENSITY_HCB2 = 14,
+    INTENSITY_HCB  = 15,
+    ESC_FLAG       = 16,
+};
+
+/**
+ * pulse tool
  */
 typedef struct {
     int present;
-    int num_pulse_minus1;
+    int num_pulse;
     int start;
     int offset[4];
     int amp[4];
-} pulse_struct;
+} Pulse;
 
 /**
  * Individual Channel Stream
  */
 typedef struct {
     int intensity_present;
-    int max_sfb;
-    int window_sequence;
-    int window_shape;             ///< If set, use Kaiser-Bessel window, otherwise use a sinus window
-    int window_shape_prev;
+    uint8_t max_sfb;            ///< number of scalefactor bands per group
+    enum WindowSequence window_sequence;
+    enum WindowSequence window_sequence_prev;
+    uint8_t use_kb_window[2];   ///< If set, use Kaiser-Bessel window, otherwise use a sinus window.
     int num_window_groups;
     uint8_t grouping;
     uint8_t group_len[8];
@@ -71,7 +84,7 @@ typedef struct {
     int num_swb;
     int num_windows;
     int tns_max_bands;
-} ics_struct;
+} IndividualChannelStream;
 
 #define TNS_MAX_ORDER 20
 /**
@@ -88,7 +101,7 @@ typedef struct {
     int coef_len[8][4];
     const float *tmp2_map[8][4];
     int coef[8][4][TNS_MAX_ORDER];
-} tns_struct;
+} TemporalNoiseShaping;
 
 /**
  * M/S joint channel coding
@@ -96,7 +109,7 @@ typedef struct {
 typedef struct {
     int present;
     uint8_t mask[8][64];
-} ms_struct;
+} MidSideStereo;
 
 /**
  * Single Channel Element
@@ -107,27 +120,32 @@ typedef struct {
                                                *   Note that this is applied before joint stereo decoding.
                                                *   Thus, when used inside CPE elements, both channels must have equal gain.
                                                */
-    ics_struct ics;
-    pulse_struct pulse;
-    tns_struct tns;
+    IndividualChannelStream ics;
+    TemporalNoiseShaping tns;
+    Pulse pulse;
     int zeroes[8][64];
     int sf_idx[8][64];
-    int cb[8][64];                            ///< Codebooks
-    float sf[8][64];                          ///< Scalefactors
-    DECLARE_ALIGNED_16(float, coeffs[1024]);  ///< Coefficients for IMDCT
-    DECLARE_ALIGNED_16(float, saved[1024]);   ///< Overlap
+    enum Codebook cb[8][64];                  ///< codebooks
+    int cb_run_end[8][64];                    ///< codebook run end points
+    float sf[8][64];                          ///< scalefactors
+    DECLARE_ALIGNED_16(float, coeffs[1024]);  ///< coefficients for IMDCT
+    DECLARE_ALIGNED_16(float, saved[1024]);   ///< overlap
     DECLARE_ALIGNED_16(float, ret[1024]);     ///< PCM output
     DECLARE_ALIGNED_16(int,   icoefs[1024]);  ///< integer coefficients for coding
-} sce_struct;
+} SingleChannelElement;
 
 /**
- * Channel Pair Element
+ * channel element - generic struct for SCE/CPE/CCE/LFE
  */
 typedef struct {
-    int common_window;     ///< Set if channels share a common 'ics_struct' in bitstream
-    ms_struct ms;
-    sce_struct ch[2];
-} cpe_struct;
+    // CPE specific
+    int common_window;     ///< Set if channels share a common 'IndividualChannelStream' in bitstream.
+    MidSideStereo ms;
+    // shared
+    SingleChannelElement ch[2];
+    // CCE specific
+//    ChannelCoupling coup;
+} ChannelElement;
 
 // borrowing temporarily ends here
 
@@ -152,16 +170,16 @@ typedef struct AACPsyContext {
 typedef struct AACPsyModel {
     const char *name;
     int   (*init)   (AACPsyContext *apc);
-    void  (*window) (AACPsyContext *apc, int16_t *audio, int channel, cpe_struct *cpe);
-    void  (*process)(AACPsyContext *apc, int16_t *audio, int channel, cpe_struct *cpe);
+    void  (*window) (AACPsyContext *apc, int16_t *audio, int channel, ChannelElement *cpe);
+    void  (*process)(AACPsyContext *apc, int16_t *audio, int channel, ChannelElement *cpe);
     void  (*end)    (AACPsyContext *apc);
 }AACPsyModel;
 
 int ff_aac_psy_init(AACPsyContext *ctx, AVCodecContext *avctx, int model, int flags,
                     const uint8_t *bands1024, int num_bands1024,
                     const uint8_t *bands128,  int num_bands128);
-void ff_aac_psy_suggest_window(AACPsyContext *ctx, int16_t *audio, int channel, cpe_struct *cpe);
-void ff_aac_psy_analyze(AACPsyContext *ctx, int16_t *audio, int channel, cpe_struct *cpe);
+void ff_aac_psy_suggest_window(AACPsyContext *ctx, int16_t *audio, int channel, ChannelElement *cpe);
+void ff_aac_psy_analyze(AACPsyContext *ctx, int16_t *audio, int channel, ChannelElement *cpe);
 void ff_aac_psy_end(AACPsyContext *ctx);
 #endif /* FFMPEG_AACPSY_H */
 



More information about the FFmpeg-soc mailing list