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

kostya subversion at mplayerhq.hu
Sat Aug 16 12:55:16 CEST 2008


Author: kostya
Date: Sat Aug 16 12:55:16 2008
New Revision: 3346

Log:
Synchronize aac.h with decoder and modify encoder to work with updated structures and definitions

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

Modified: aacenc/aac.h
==============================================================================
--- aacenc/aac.h	(original)
+++ aacenc/aac.h	Sat Aug 16 12:55:16 2008
@@ -47,8 +47,6 @@
 
 #include "avcodec.h"
 #include "dsputil.h"
-#include "libavutil/random.h"
-
 #include "mpeg4audio.h"
 
 #include <stdint.h>
@@ -60,11 +58,10 @@
         size);
 
 #define MAX_CHANNELS 64
-#define MAX_TAGID 16
+#define MAX_ELEM_ID 16
 
 #define TNS_MAX_ORDER 20
 #define PNS_MEAN_ENERGY 3719550720.0f // sqrt(3.0) * 1<<31
-#define IVQUANT_SIZE 1024
 
 enum AudioObjectType {
     AOT_NULL,
@@ -96,15 +93,15 @@ enum AudioObjectType {
     AOT_SSC,                   ///< N                       SinuSoidal Coding
 };
 
-enum RawDataBlockID {
-    ID_SCE,
-    ID_CPE,
-    ID_CCE,
-    ID_LFE,
-    ID_DSE,
-    ID_PCE,
-    ID_FIL,
-    ID_END,
+enum RawDataBlockType {
+    TYPE_SCE,
+    TYPE_CPE,
+    TYPE_CCE,
+    TYPE_LFE,
+    TYPE_DSE,
+    TYPE_PCE,
+    TYPE_FIL,
+    TYPE_END,
 };
 
 enum ExtensionPayloadID {
@@ -134,7 +131,7 @@ enum BandType {
 
 #define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10)
 
-enum ChannelType {
+enum ChannelPosition {
     AAC_CHANNEL_FRONT = 1,
     AAC_CHANNEL_SIDE  = 2,
     AAC_CHANNEL_BACK  = 3,
@@ -143,14 +140,12 @@ enum ChannelType {
 };
 
 /**
- * mix-down channel types
- * MIXDOWN_CENTER is the index into the mix-down arrays for a Single Channel Element with AAC_CHANNEL_FRONT.
- * MIXDOWN_(BACK|FRONT) are the indices for Channel Pair Elements with AAC_CHANNEL_(BACK|FRONT).
+ * The point during decoding at which channel coupling is applied.
  */
-enum {
-    MIXDOWN_CENTER,
-    MIXDOWN_FRONT,
-    MIXDOWN_BACK,
+enum CouplingPoint {
+    BEFORE_TNS,
+    BETWEEN_TNS_AND_IMDCT,
+    AFTER_IMDCT = 3,
 };
 
 #define SCALE_DIV_512    36    ///< scalefactor difference that corresponds to scale difference in 512 times
@@ -159,18 +154,6 @@ enum {
 #define SCALE_MAX_DIFF   60    ///< maximum scalefactor difference allowed by standard
 #define SCALE_DIFF_ZERO  60    ///< codebook index corresponding to zero scalefactor indices difference
 
-/**
- * Program configuration - describes how channels are arranged. Either read from
- * stream (ID_PCE) or created based on a default fixed channel arrangement.
- */
-typedef struct {
-    enum ChannelType che_type[4][MAX_TAGID]; ///< channel element type with the first index as the first 4 raw_data_block IDs
-    int mono_mixdown_tag;                    ///< The SCE tag to use if user requests mono   output, -1 if not available.
-    int stereo_mixdown_tag;                  ///< The CPE tag to use if user requests stereo output, -1 if not available.
-    int mixdown_coeff_index;                 ///< 0-3
-    int pseudo_surround;                     ///< Mix surround channels out of phase.
-} ProgramConfig;
-
 #ifdef AAC_LTP
 /**
  * Long Term Prediction
@@ -188,7 +171,6 @@ typedef struct {
  * Individual Channel Stream
  */
 typedef struct {
-    int intensity_present;
     uint8_t max_sfb;            ///< number of scalefactor bands per group
     enum WindowSequence window_sequence[2];
     uint8_t use_kb_window[2];   ///< If set, use Kaiser-Bessel window, otherwise use a sinus window.
@@ -222,14 +204,6 @@ typedef struct {
 } TemporalNoiseShaping;
 
 /**
- * M/S joint channel coding
- */
-typedef struct {
-    int present;
-    uint8_t mask[8][64];
-} MidSideStereo;
-
-/**
  * Dynamic Range Control - decoded from the bitstream but not processed further.
  */
 typedef struct {
@@ -237,23 +211,18 @@ typedef struct {
     int dyn_rng_sgn[17];                            ///< DRC sign information; 0 - positive, 1 - negative
     int dyn_rng_ctl[17];                            ///< DRC magnitude information
     int exclude_mask[MAX_CHANNELS];                 ///< Channels to be excluded from DRC processing.
-    int additional_excluded_chns[MAX_CHANNELS / 7]; /**< The exclude_mask bits are
-                                                        coded in groups of 7 with 1 bit preceeding each group (except the first)
-                                                        indicating that 7 more mask bits are coded. */
     int band_incr;                                  ///< Number of DRC bands greater than 1 having DRC info.
     int interpolation_scheme;                       ///< Indicates the interpolation scheme used in the SBR QMF domain.
     int band_top[17];                               ///< Indicates the top of the i-th DRC band in units of 4 spectral lines.
     int prog_ref_level;                             /**< A reference level for the long-term program audio level for all
-                                                        channels combined. */
+                                                     *   channels combined.
+                                                     */
 } DynamicRangeControl;
 
-/**
- * pulse tool
- */
 typedef struct {
     int num_pulse;
     int start;
-    int offset[4];
+    int pos[4];
     int amp[4];
 } Pulse;
 
@@ -283,33 +252,28 @@ typedef struct {
  * coupling parameters
  */
 typedef struct {
-    int is_indep_coup;     ///< Set if independent coupling (i.e. after IMDCT).
-    int domain;            ///< Controls if coupling is performed before (0) or after (1) the TNS decoding of the target channels.
+    enum CouplingPoint coupling_point;  ///< The point during decoding at which coupling is applied.
     int num_coupled;       ///< number of target elements
-    int is_cpe[9];         ///< Set if target is an CPE (otherwise it's an SCE).
-    int tag_select[9];     ///< element tag index
-    int l[9];              ///< Apply gain to left channel of a CPE.
-    int r[9];              ///< Apply gain to right channel of a CPE.
-    float gain[18][8][64];
+    enum RawDataBlockType type[8];   ///< Type of channel element to be coupled - SCE or CPE.
+    int id_select[8];      ///< element id
+    int ch_select[8];      /**< [0] shared list of gains; [1] list of gains for left channel;
+                            *   [2] list of gains for right channel; [3] lists of gains for both channels
+                            */
+    float gain[16][120];
 } ChannelCoupling;
 
-
 /**
  * Single Channel Element - used for both SCE and LFE elements.
  */
 typedef struct {
-    float mixing_gain;                        /**< Channel gain (not used by AAC bitstream).
-                                               *   Note that this is applied before joint stereo decoding.
-                                               *   Thus, when used inside CPE elements, both channels must have equal gain.
-                                               */
     IndividualChannelStream ics;
     TemporalNoiseShaping tns;
     Pulse pulse;
-    enum BandType band_type[8][64];           ///< band types
-    int band_type_run_end[8][64];             ///< band type run end points
-    float sf[8][64];                          ///< scalefactors
-    int sf_idx[8][64];                        ///< scalefactor indices (used by encoder)
-    int zeroes[8][64];                        ///< band is not coded (used by encoder)
+    enum BandType band_type[128];             ///< band types
+    int band_type_run_end[128];               ///< band type run end points
+    float sf[128];                            ///< scalefactors
+    int sf_idx[128];                          ///< scalefactor indices (used by encoder)
+    int zeroes[128];                          ///< band is not coded (used by encoder)
     DECLARE_ALIGNED_16(float, coeffs[1024]);  ///< coefficients for IMDCT
     DECLARE_ALIGNED_16(float, saved[1024]);   ///< overlap
     DECLARE_ALIGNED_16(float, ret[1024]);     ///< PCM output
@@ -327,8 +291,9 @@ typedef struct {
  */
 typedef struct {
     // CPE specific
-    int common_window;     ///< Set if channels share a common 'IndividualChannelStream' in bitstream.
-    MidSideStereo ms;
+    int common_window;        ///< Set if channels share a common 'IndividualChannelStream' in bitstream.
+    int     ms_mode;          ///< Signals mid/side stereo flags coding mode (used by encoder)
+    uint8_t ms_mask[120];     ///< Set if mid/side stereo is used for each scalefactor window band
     // shared
     SingleChannelElement ch[2];
     // CCE specific
@@ -350,8 +315,10 @@ typedef struct {
      * @defgroup elements
      * @{
      */
-    ProgramConfig pcs;
-    ChannelElement * che[4][MAX_TAGID];
+    enum ChannelPosition che_pos[4][MAX_ELEM_ID]; /**< channel element channel mapping with the
+                                                   *   first index as the first 4 raw data block types
+                                                   */
+    ChannelElement * che[4][MAX_ELEM_ID];
     /** @} */
 
     /**
@@ -375,16 +342,14 @@ typedef struct {
 #ifdef AAC_SSR
     ssr_context ssrctx;
 #endif /* AAC_SSR */
-    AVRandomState random_state;
+    int random_state;
     /** @} */
 
     /**
-     * @defgroup output   Members used for output interleaving and down-mixing.
+     * @defgroup output   Members used for output interleaving.
      * @{
      */
-    float *interleaved_output;                        ///< Interim buffer for interleaving PCM samples.
     float *output_data[MAX_CHANNELS];                 ///< Points to each element's 'ret' buffer (PCM output).
-    ChannelElement *mm[3];                            ///< Center/Front/Back channel elements to use for matrix mix-down.
     float add_bias;                                   ///< offset for dsp.float_to_int16
     float sf_scale;                                   ///< Pre-scale for correct IMDCT and dsp.float_to_int16.
     int sf_offset;                                    ///< offset into pow2sf_tab as appropriate for dsp.float_to_int16

Modified: aacenc/aacenc.c
==============================================================================
--- aacenc/aacenc.c	(original)
+++ aacenc/aacenc.c	Sat Aug 16 12:55:16 2008
@@ -164,12 +164,12 @@ static const uint8_t* run_value_bits[2] 
 
 /** default channel configurations */
 static const uint8_t aac_chan_configs[6][5] = {
- {1, ID_SCE},                         // 1 channel  - single channel element
- {1, ID_CPE},                         // 2 channels - channel pair
- {2, ID_SCE, ID_CPE},                 // 3 channels - center + stereo
- {3, ID_SCE, ID_CPE, ID_SCE},         // 4 channels - front center + stereo + back center
- {3, ID_SCE, ID_CPE, ID_CPE},         // 5 channels - front center + stereo + back stereo
- {4, ID_SCE, ID_CPE, ID_CPE, ID_LFE}, // 6 channels - front center + stereo + back stereo + LFE
+ {1, TYPE_SCE},                               // 1 channel  - single channel element
+ {1, TYPE_CPE},                               // 2 channels - channel pair
+ {2, TYPE_SCE, TYPE_CPE},                     // 3 channels - center + stereo
+ {3, TYPE_SCE, TYPE_CPE, TYPE_SCE},           // 4 channels - front center + stereo + back center
+ {3, TYPE_SCE, TYPE_CPE, TYPE_CPE},           // 5 channels - front center + stereo + back stereo
+ {4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_LFE}, // 6 channels - front center + stereo + back stereo + LFE
 };
 
 /**
@@ -353,13 +353,13 @@ static void encode_ms_info(PutBitContext
 {
     int i, w, wg;
 
-    put_bits(pb, 2, cpe->ms.present);
-    if(cpe->ms.present == 1){
+    put_bits(pb, 2, cpe->ms_mode);
+    if(cpe->ms_mode == 1){
         w = 0;
         for(wg = 0; wg < cpe->ch[0].ics.num_window_groups; wg++){
             for(i = 0; i < cpe->ch[0].ics.max_sfb; i++)
-                put_bits(pb, 1, cpe->ms.mask[w][i]);
-            w += cpe->ch[0].ics.group_len[wg];
+                put_bits(pb, 1, cpe->ms_mask[w + i]);
+            w += cpe->ch[0].ics.group_len[wg]*16;
         }
     }
 }
@@ -452,7 +452,7 @@ static void encode_window_bands_info(AAC
         maxval = 0;
         start2 = start;
         size = cpe->ch[channel].ics.swb_sizes[swb];
-        if(cpe->ch[channel].zeroes[win][swb])
+        if(cpe->ch[channel].zeroes[win*16 + swb])
             maxval = 0;
         else{
             for(w = win; w < win + group_len; w++){
@@ -515,8 +515,8 @@ static void encode_window_bands_info(AAC
         put_bits(&s->pb, 4, s->path[stack[i]].codebook);
         count = stack[i] - s->path[stack[i]].prev_idx;
         for(j = 0; j < count; j++){
-            cpe->ch[channel].band_type[win][start] =  s->path[stack[i]].codebook;
-            cpe->ch[channel].zeroes[win][start]    = !s->path[stack[i]].codebook;
+            cpe->ch[channel].band_type[win*16 + start] =  s->path[stack[i]].codebook;
+            cpe->ch[channel].zeroes[win*16 + start]    = !s->path[stack[i]].codebook;
             start++;
         }
         while(count >= run_esc){
@@ -611,16 +611,16 @@ static void encode_scale_factors(AVCodec
     w = 0;
     for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){
         for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
-            if(!cpe->ch[channel].zeroes[w][i]){
+            if(!cpe->ch[channel].zeroes[w*16 + i]){
                 /* if we have encountered scale=256 it means empty band
                  * which was decided to be coded by encoder, so assign it
                  * last scalefactor value for compression efficiency
                  */
-                if(cpe->ch[channel].sf_idx[w][i] == 256)
-                    cpe->ch[channel].sf_idx[w][i] = off;
-                diff = cpe->ch[channel].sf_idx[w][i] - off + SCALE_DIFF_ZERO;
+                if(cpe->ch[channel].sf_idx[w*16 + i] == 256)
+                    cpe->ch[channel].sf_idx[w*16 + i] = off;
+                diff = cpe->ch[channel].sf_idx[w*16 + i] - off + SCALE_DIFF_ZERO;
                 if(diff < 0 || diff > 120) av_log(avctx, AV_LOG_ERROR, "Scalefactor difference is too big to be coded\n");
-                off = cpe->ch[channel].sf_idx[w][i];
+                off = cpe->ch[channel].sf_idx[w*16 + i];
                 put_bits(&s->pb, ff_aac_scalefactor_bits[diff], ff_aac_scalefactor_code[diff]);
             }
         }
@@ -641,7 +641,7 @@ static void encode_pulses(AVCodecContext
     put_bits(&s->pb, 2, pulse->num_pulse - 1);
     put_bits(&s->pb, 6, pulse->start);
     for(i = 0; i < pulse->num_pulse; i++){
-        put_bits(&s->pb, 5, pulse->offset[i]);
+        put_bits(&s->pb, 5, pulse->pos[i]);
         put_bits(&s->pb, 4, pulse->amp[i]);
     }
 }
@@ -697,12 +697,12 @@ static void encode_spectral_coeffs(AVCod
     for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){
         start = 0;
         for(i = 0; i < cpe->ch[channel].ics.max_sfb; i++){
-            if(cpe->ch[channel].zeroes[w][i]){
+            if(cpe->ch[channel].zeroes[w*16 + i]){
                 start += cpe->ch[channel].ics.swb_sizes[i];
                 continue;
             }
             for(w2 = w; w2 < w + cpe->ch[channel].ics.group_len[wg]; w2++){
-                encode_band_coeffs(s, cpe, channel, start + w2*128, cpe->ch[channel].ics.swb_sizes[i], cpe->ch[channel].band_type[w][i]);
+                encode_band_coeffs(s, cpe, channel, start + w2*128, cpe->ch[channel].ics.swb_sizes[i], cpe->ch[channel].band_type[w*16 + i]);
             }
             start += cpe->ch[channel].ics.swb_sizes[i];
         }
@@ -723,13 +723,13 @@ static int encode_individual_channel(AVC
     w = 0;
     for(wg = 0; wg < cpe->ch[channel].ics.num_window_groups; wg++){
         for(g = 0; g < cpe->ch[channel].ics.max_sfb; g++){
-            if(!cpe->ch[channel].zeroes[w][g]){
-                global_gain = cpe->ch[channel].sf_idx[w][g];
+            if(!cpe->ch[channel].zeroes[w + g]){
+                global_gain = cpe->ch[channel].sf_idx[w + g];
                 break;
             }
         }
         if(global_gain) break;
-        w += cpe->ch[channel].ics.group_len[wg];
+        w += cpe->ch[channel].ics.group_len[wg]*16;
     }
 
     put_bits(&s->pb, 8, global_gain);
@@ -751,7 +751,7 @@ static void put_bitstream_info(AVCodecCo
     int i, namelen, padbits;
 
     namelen = strlen(name) + 2;
-    put_bits(&s->pb, 3, ID_FIL);
+    put_bits(&s->pb, 3, TYPE_FIL);
     put_bits(&s->pb, 4, FFMIN(namelen, 15));
     if(namelen >= 15)
         put_bits(&s->pb, 8, namelen - 16);
@@ -783,7 +783,7 @@ static int aac_encode_frame(AVCodecConte
             samples2 = s->samples + 1024 * avctx->channels;
             for(i = 0; i < chan_map[0]; i++){
                 tag = chan_map[i+1];
-                chans = tag == ID_CPE ? 2 : 1;
+                chans = tag == TYPE_CPE ? 2 : 1;
                 ff_aac_psy_preprocess(&s->psy, (uint16_t*)data + start_ch, samples2 + start_ch, i, tag);
                 start_ch += chans;
             }
@@ -802,7 +802,7 @@ static int aac_encode_frame(AVCodecConte
     memset(chan_el_counter, 0, sizeof(chan_el_counter));
     for(i = 0; i < chan_map[0]; i++){
         tag = chan_map[i+1];
-        chans = tag == ID_CPE ? 2 : 1;
+        chans = tag == TYPE_CPE ? 2 : 1;
         cpe = &s->cpe[i];
         samples2 = samples + start_ch;
         la = samples2 + 1024 * avctx->channels + start_ch;
@@ -827,7 +827,7 @@ static int aac_encode_frame(AVCodecConte
         start_ch += chans;
     }
 
-    put_bits(&s->pb, 3, ID_END);
+    put_bits(&s->pb, 3, TYPE_END);
     flush_put_bits(&s->pb);
     avctx->frame_bits = put_bits_count(&s->pb);
 

Modified: aacenc/aacpsy.c
==============================================================================
--- aacenc/aacpsy.c	(original)
+++ aacenc/aacpsy.c	Sat Aug 16 12:55:16 2008
@@ -95,24 +95,24 @@ static void psy_create_output(AACPsyCont
         start = 0;
         maxsfb = 0;
         cpe->ch[ch].pulse.num_pulse = 0;
-        for(w = 0; w < cpe->ch[ch].ics.num_windows; w++){
+        for(w = 0; w < cpe->ch[ch].ics.num_windows*16; w += 16){
             for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
                 sum = 0;
                 //apply M/S
-                if(!ch && cpe->ms.mask[w][g]){
+                if(!ch && cpe->ms_mask[w + g]){
                     for(i = 0; i < cpe->ch[ch].ics.swb_sizes[g]; i++){
                         cpe->ch[0].coeffs[start+i] = (cpe->ch[0].coeffs[start+i] + cpe->ch[1].coeffs[start+i]) / 2.0;
                         cpe->ch[1].coeffs[start+i] =  cpe->ch[0].coeffs[start+i] - cpe->ch[1].coeffs[start+i];
                     }
                 }
-                if(!cpe->ch[ch].zeroes[w][g])
-                    sum = quantize_coeffs(cpe->ch[ch].coeffs + start, cpe->ch[ch].icoefs + start, cpe->ch[ch].ics.swb_sizes[g], cpe->ch[ch].sf_idx[w][g]);
+                if(!cpe->ch[ch].zeroes[w + g])
+                    sum = quantize_coeffs(cpe->ch[ch].coeffs + start, cpe->ch[ch].icoefs + start, cpe->ch[ch].ics.swb_sizes[g], cpe->ch[ch].sf_idx[w + g]);
                 else
                     memset(cpe->ch[ch].icoefs + start, 0, cpe->ch[ch].ics.swb_sizes[g] * sizeof(cpe->ch[0].icoefs[0]));
-                cpe->ch[ch].zeroes[w][g] = !sum;
+                cpe->ch[ch].zeroes[w + g] = !sum;
                 start += cpe->ch[ch].ics.swb_sizes[g];
             }
-            for(cmaxsfb = cpe->ch[ch].ics.num_swb; cmaxsfb > 0 && cpe->ch[ch].zeroes[w][cmaxsfb-1]; cmaxsfb--);
+            for(cmaxsfb = cpe->ch[ch].ics.num_swb; cmaxsfb > 0 && cpe->ch[ch].zeroes[w+cmaxsfb-1]; cmaxsfb--);
             maxsfb = FFMAX(maxsfb, cmaxsfb);
         }
         cpe->ch[ch].ics.max_sfb = maxsfb;
@@ -122,15 +122,15 @@ static void psy_create_output(AACPsyCont
         for(wg = 0; wg < cpe->ch[ch].ics.num_window_groups; wg++){
             for(g = 0; g < cpe->ch[ch].ics.max_sfb; g++){
                 i = 1;
-                for(w2 = 0; w2 < cpe->ch[ch].ics.group_len[wg]; w2++){
-                    if(!cpe->ch[ch].zeroes[w + w2][g]){
+                for(w2 = 0; w2 < cpe->ch[ch].ics.group_len[wg]*16; w2 += 16){
+                    if(!cpe->ch[ch].zeroes[w + w2 + g]){
                         i = 0;
                         break;
                     }
                 }
-                cpe->ch[ch].zeroes[w][g] = i;
+                cpe->ch[ch].zeroes[w + g] = i;
             }
-            w += cpe->ch[ch].ics.group_len[wg];
+            w += cpe->ch[ch].ics.group_len[wg] * 16;
         }
     }
 
@@ -138,18 +138,18 @@ static void psy_create_output(AACPsyCont
         int msc = 0;
         cpe->ch[0].ics.max_sfb = FFMAX(cpe->ch[0].ics.max_sfb, cpe->ch[1].ics.max_sfb);
         cpe->ch[1].ics.max_sfb = cpe->ch[0].ics.max_sfb;
-        for(w = 0; w < cpe->ch[0].ics.num_windows; w++)
+        for(w = 0; w < cpe->ch[0].ics.num_windows*16; w += 16)
             for(i = 0; i < cpe->ch[0].ics.max_sfb; i++)
-                if(cpe->ms.mask[w][i]) msc++;
-        if(msc == 0 || cpe->ch[0].ics.max_sfb == 0) cpe->ms.present = 0;
-        else cpe->ms.present = msc < cpe->ch[0].ics.max_sfb ? 1 : 2;
+                if(cpe->ms_mask[w+i]) msc++;
+        if(msc == 0 || cpe->ch[0].ics.max_sfb == 0) cpe->ms_mode = 0;
+        else cpe->ms_mode = msc < cpe->ch[0].ics.max_sfb ? 1 : 2;
     }
 }
 
 static void psy_null_window(AACPsyContext *apc, int16_t *audio, int16_t *la, int tag, int type, ChannelElement *cpe)
 {
     int ch;
-    int chans = type == ID_CPE ? 2 : 1;
+    int chans = type == TYPE_CPE ? 2 : 1;
 
     for(ch = 0; ch < chans; ch++){
         cpe->ch[ch].ics.window_sequence[0] = ONLY_LONG_SEQUENCE;
@@ -168,7 +168,7 @@ static void psy_null_process(AACPsyConte
     int start;
     int ch, g, i;
     int minscale;
-    int chans = type == ID_CPE ? 2 : 1;
+    int chans = type == TYPE_CPE ? 2 : 1;
 
     for(ch = 0; ch < chans; ch++){
         start = 0;
@@ -180,26 +180,26 @@ static void psy_null_process(AACPsyConte
                 ffac += sqrt(FFABS(cpe->ch[ch].coeffs[start+i]));
             }
             thr = energy * 0.001258925f;
-            cpe->ch[ch].sf_idx[ch][g] = 136;
-            cpe->ch[ch].zeroes[ch][g] = (energy == 0.0);
-            if(cpe->ch[ch].zeroes[ch][g]) continue;
+            cpe->ch[ch].sf_idx[g] = 136;
+            cpe->ch[ch].zeroes[g] = (energy == 0.0);
+            if(cpe->ch[ch].zeroes[g]) continue;
             minscale = (int)(2.66667 * (log2(6.75*thr) - log2(ffac)));
-            cpe->ch[ch].sf_idx[ch][g] = SCALE_ONE_POS - minscale;
-            while(cpe->ch[ch].sf_idx[ch][g] > 3){
-                dist = calc_distortion(cpe->ch[ch].coeffs + start, apc->bands1024[g], cpe->ch[ch].sf_idx[ch][g]);
+            cpe->ch[ch].sf_idx[g] = SCALE_ONE_POS - minscale;
+            while(cpe->ch[ch].sf_idx[g] > 3){
+                dist = calc_distortion(cpe->ch[ch].coeffs + start, apc->bands1024[g], cpe->ch[ch].sf_idx[g]);
                 if(dist < thr) break;
-                cpe->ch[ch].sf_idx[ch][g] -= 3;
+                cpe->ch[ch].sf_idx[g] -= 3;
             }
         }
     }
     for(ch = 0; ch < chans; ch++){
         minscale = 255;
         for(g = 0; g < apc->num_bands1024; g++)
-            if(!cpe->ch[ch].zeroes[0][g])
-                minscale = FFMIN(minscale, cpe->ch[ch].sf_idx[0][g]);
+            if(!cpe->ch[ch].zeroes[g])
+                minscale = FFMIN(minscale, cpe->ch[ch].sf_idx[g]);
         for(g = 0; g < apc->num_bands1024; g++)
-            if(!cpe->ch[ch].zeroes[0][g])
-                cpe->ch[ch].sf_idx[0][g] = FFMIN(minscale + SCALE_MAX_DIFF, cpe->ch[ch].sf_idx[0][g]);
+            if(!cpe->ch[ch].zeroes[g])
+                cpe->ch[ch].sf_idx[g] = FFMIN(minscale + SCALE_MAX_DIFF, cpe->ch[ch].sf_idx[g]);
     }
     psy_create_output(apc, cpe, chans);
 }
@@ -207,7 +207,7 @@ static void psy_null_process(AACPsyConte
 static void psy_null8_window(AACPsyContext *apc, int16_t *audio, int16_t *la, int tag, int type, ChannelElement *cpe)
 {
     int ch, i;
-    int chans = type == ID_CPE ? 2 : 1;
+    int chans = type == TYPE_CPE ? 2 : 1;
 
     for(ch = 0; ch < chans; ch++){
         int prev_seq = cpe->ch[ch].ics.window_sequence[1];
@@ -244,26 +244,26 @@ static void psy_null8_process(AACPsyCont
 {
     int start;
     int w, ch, g, i;
-    int chans = type == ID_CPE ? 2 : 1;
+    int chans = type == TYPE_CPE ? 2 : 1;
 
     //detect M/S
     if(chans > 1 && cpe->common_window){
         start = 0;
-        for(w = 0; w < cpe->ch[0].ics.num_windows; w++){
+        for(w = 0; w < cpe->ch[0].ics.num_windows*16; w += 16){
             for(g = 0; g < cpe->ch[0].ics.num_swb; g++){
                 float diff = 0.0f;
 
                 for(i = 0; i < cpe->ch[0].ics.swb_sizes[g]; i++)
                     diff += fabs(cpe->ch[0].coeffs[start+i] - cpe->ch[1].coeffs[start+i]);
-                cpe->ms.mask[w][g] = diff == 0.0;
+                cpe->ms_mask[w + g] = diff == 0.0;
             }
         }
     }
     for(ch = 0; ch < chans; ch++){
-        for(w = 0; w < cpe->ch[ch].ics.num_windows; w++){
+        for(w = 0; w < cpe->ch[ch].ics.num_windows*16; w += 16){
             for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
-                cpe->ch[ch].sf_idx[w][g] = SCALE_ONE_POS;
-                cpe->ch[ch].zeroes[w][g] = 0;
+                cpe->ch[ch].sf_idx[w + g] = SCALE_ONE_POS;
+                cpe->ch[ch].zeroes[w + g] = 0;
             }
         }
     }
@@ -443,7 +443,7 @@ static const uint8_t window_grouping[9] 
 static void psy_3gpp_window(AACPsyContext *apc, int16_t *audio, int16_t *la, int tag, int type, ChannelElement *cpe)
 {
     int ch;
-    int chans = type == ID_CPE ? 2 : 1;
+    int chans = type == TYPE_CPE ? 2 : 1;
     int i, j;
     int br = apc->avctx->bit_rate / apc->avctx->channels;
     int attack_ratio = (br <= 16000 + 8000*chans) ? 18 : 10;
@@ -584,7 +584,7 @@ static void psy_3gpp_process(AACPsyConte
     Psy3gppContext *pctx = (Psy3gppContext*) apc->model_priv_data;
     float pe_target;
     int bits_avail;
-    int chans = type == ID_CPE ? 2 : 1;
+    int chans = type == TYPE_CPE ? 2 : 1;
     Psy3gppChannel *pch = &pctx->ch[tag];
 
     //calculate energies, initial thresholds and related values - 5.4.2 "Threshold Calculation"
@@ -648,7 +648,7 @@ static void psy_3gpp_process(AACPsyConte
                 float m, s;
 
                 g2 = w*16 + g;
-                cpe->ms.mask[w][g] = 0;
+                cpe->ms_mask[g2] = 0;
                 if(pch->band[0][g2].energy == 0.0 || pch->band[1][g2].energy == 0.0)
                     continue;
                 for(i = 0; i < cpe->ch[0].ics.swb_sizes[g]; i++){
@@ -665,7 +665,7 @@ static void psy_3gpp_process(AACPsyConte
                 ff_s /= sqrt(512.0);
                 l1 = FFMIN(pch->band[0][g2].thr, pch->band[1][g2].thr);
                 if(en_m == 0.0 || en_s == 0.0 || l1*l1 / (en_m * en_s) >= (pch->band[0][g2].thr * pch->band[1][g2].thr / (pch->band[0][g2].energy * pch->band[1][g2].energy))){
-                    cpe->ms.mask[w][g] = 1;
+                    cpe->ms_mask[g2] = 1;
                     pch->band[0][g2].energy = en_m;
                     pch->band[1][g2].energy = en_s;
                     pch->band[0][g2].ffac = ff_m;
@@ -743,13 +743,13 @@ static void psy_3gpp_process(AACPsyConte
             for(w = 0; w < cpe->ch[ch].ics.num_windows; w++){
                 for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
                     g2 = w*16 + g;
-                    cpe->ch[ch].zeroes[w][g] = pch->band[ch][g2].thr >= pch->band[ch][g2].energy;
-                    if(cpe->ch[ch].zeroes[w][g]) continue;
+                    cpe->ch[ch].zeroes[g2] = pch->band[ch][g2].thr >= pch->band[ch][g2].energy;
+                    if(cpe->ch[ch].zeroes[g2]) continue;
                     //spec gives constant for lg() but we scaled it for log2()
-                    cpe->ch[ch].sf_idx[w][g] = (int)(2.66667 * (log2(6.75*pch->band[ch][g2].thr) - log2(pch->band[ch][g2].ffac)));
+                    cpe->ch[ch].sf_idx[g2] = (int)(2.66667 * (log2(6.75*pch->band[ch][g2].thr) - log2(pch->band[ch][g2].ffac)));
                     if(prev_scale != -1)
-                        cpe->ch[ch].sf_idx[w][g] = av_clip(cpe->ch[ch].sf_idx[w][g], prev_scale - SCALE_MAX_DIFF, prev_scale + SCALE_MAX_DIFF);
-                    prev_scale = cpe->ch[ch].sf_idx[w][g];
+                        cpe->ch[ch].sf_idx[g2] = av_clip(cpe->ch[ch].sf_idx[g2], prev_scale - SCALE_MAX_DIFF, prev_scale + SCALE_MAX_DIFF);
+                    prev_scale = cpe->ch[ch].sf_idx[g2];
                 }
             }
         }
@@ -761,15 +761,15 @@ static void psy_3gpp_process(AACPsyConte
                 for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
                     g2 = w*16 + g;
                     if(pch->band[ch][g2].thr >= pch->band[ch][g2].energy){
-                        cpe->ch[ch].sf_idx[w][g] = 0;
-                        cpe->ch[ch].zeroes[w][g] = 1;
+                        cpe->ch[ch].sf_idx[g2] = 0;
+                        cpe->ch[ch].zeroes[g2] = 1;
                     }else{
-                        cpe->ch[ch].zeroes[w][g] = 0;
-                        cpe->ch[ch].sf_idx[w][g] = (int)(2.66667 * (log2(6.75*pch->band[ch][g2].thr) - log2(pch->band[ch][g2].ffac)));
-                        while(cpe->ch[ch].sf_idx[ch][g] > 3){
-                            float dist = calc_distortion(cpe->ch[ch].coeffs + start, cpe->ch[ch].ics.swb_sizes[g], SCALE_ONE_POS + cpe->ch[ch].sf_idx[ch][g]);
+                        cpe->ch[ch].zeroes[g2] = 0;
+                        cpe->ch[ch].sf_idx[g2] = (int)(2.66667 * (log2(6.75*pch->band[ch][g2].thr) - log2(pch->band[ch][g2].ffac)));
+                        while(cpe->ch[ch].sf_idx[g2] > 3){
+                            float dist = calc_distortion(cpe->ch[ch].coeffs + start, cpe->ch[ch].ics.swb_sizes[g], SCALE_ONE_POS + cpe->ch[ch].sf_idx[g2]);
                             if(dist < pch->band[ch][g2].thr) break;
-                            cpe->ch[ch].sf_idx[ch][g] -= 3;
+                            cpe->ch[ch].sf_idx[g2] -= 3;
                         }
                     }
                     start += cpe->ch[ch].ics.swb_sizes[g];
@@ -782,22 +782,22 @@ static void psy_3gpp_process(AACPsyConte
     //limit scalefactors
     for(ch = 0; ch < chans; ch++){
         int min_scale = 256;
-        for(w = 0; w < cpe->ch[ch].ics.num_windows; w++)
+        for(w = 0; w < cpe->ch[ch].ics.num_windows*16; w += 16)
             for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
-                if(cpe->ch[ch].zeroes[w][g]) continue;
-                min_scale = FFMIN(min_scale, cpe->ch[ch].sf_idx[w][g]);
+                if(cpe->ch[ch].zeroes[w + g]) continue;
+                min_scale = FFMIN(min_scale, cpe->ch[ch].sf_idx[w + g]);
             }
-        for(w = 0; w < cpe->ch[ch].ics.num_windows; w++)
+        for(w = 0; w < cpe->ch[ch].ics.num_windows*16; w += 16)
             for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
-                if(cpe->ch[ch].zeroes[w][g]) continue;
-                cpe->ch[ch].sf_idx[w][g] = FFMIN(cpe->ch[ch].sf_idx[w][g], min_scale + SCALE_MAX_DIFF);
+                if(cpe->ch[ch].zeroes[w + g]) continue;
+                cpe->ch[ch].sf_idx[w + g] = FFMIN(cpe->ch[ch].sf_idx[w + g], min_scale + SCALE_MAX_DIFF);
             }
-        for(w = 0; w < cpe->ch[ch].ics.num_windows; w++)
+        for(w = 0; w < cpe->ch[ch].ics.num_windows*16; w += 16)
             for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
-                if(cpe->ch[ch].zeroes[w][g])
-                    cpe->ch[ch].sf_idx[w][g] = 256;
+                if(cpe->ch[ch].zeroes[w + g])
+                    cpe->ch[ch].sf_idx[w + g] = 256;
                 else
-                    cpe->ch[ch].sf_idx[w][g] = av_clip(SCALE_ONE_POS + cpe->ch[ch].sf_idx[w][g], 0, SCALE_MAX_POS);
+                    cpe->ch[ch].sf_idx[w + g] = av_clip(SCALE_ONE_POS + cpe->ch[ch].sf_idx[w + g], 0, SCALE_MAX_POS);
             }
 
         //adjust scalefactors for window groups
@@ -806,14 +806,14 @@ static void psy_3gpp_process(AACPsyConte
             int min_scale = 256;
 
             for(g = 0; g < cpe->ch[ch].ics.num_swb; g++){
-                for(i = w; i < w + cpe->ch[ch].ics.group_len[wg]; i++){
-                    if(cpe->ch[ch].zeroes[i][g]) continue;
-                    min_scale = FFMIN(min_scale, cpe->ch[ch].sf_idx[i][g]);
+                for(i = w; i < w + cpe->ch[ch].ics.group_len[wg]*16; i += 16){
+                    if(cpe->ch[ch].zeroes[i + g]) continue;
+                    min_scale = FFMIN(min_scale, cpe->ch[ch].sf_idx[i + g]);
                 }
-                for(i = w; i < w + cpe->ch[ch].ics.group_len[wg]; i++)
-                    cpe->ch[ch].sf_idx[i][g] = min_scale;
+                for(i = w; i < w + cpe->ch[ch].ics.group_len[wg]*16; i += 16)
+                    cpe->ch[ch].sf_idx[i + g] = min_scale;
             }
-            w += cpe->ch[ch].ics.group_len[wg];
+            w += cpe->ch[ch].ics.group_len[wg] * 16;
         }
     }
 
@@ -919,7 +919,7 @@ void av_cold ff_aac_psy_end(AACPsyContex
 
 void ff_aac_psy_preprocess(AACPsyContext *ctx, int16_t *audio, int16_t *dest, int tag, int type)
 {
-    int chans = type == ID_CPE ? 2 : 1;
+    int chans = type == TYPE_CPE ? 2 : 1;
     const int chstride = ctx->avctx->channels;
     int i, ch;
     float t[2];



More information about the FFmpeg-soc mailing list