]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/aacpsy.c
x86: float_dsp: fix ff_vector_fmac_scalar_avx() on Win64
[ffmpeg] / libavcodec / aacpsy.c
index 79d708439cae33215de4a7573c68ec17d965229a..42db471428fda0ba14851ba442c1bb7e192c47ec 100644 (file)
@@ -216,7 +216,7 @@ static const float psy_fir_coeffs[] = {
 };
 
 /**
- * calculates the attack threshold for ABR from the above table for the LAME psy model
+ * Calculate the ABR attack threshold from the above LAME psymodel table.
  */
 static float lame_calc_attack_threshold(int bitrate)
 {
@@ -389,9 +389,8 @@ static av_unused FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx,
     AacPsyChannel *pch  = &pctx->ch[channel];
     uint8_t grouping     = 0;
     int next_type        = pch->next_window_seq;
-    FFPsyWindowInfo wi;
+    FFPsyWindowInfo wi  = { { 0 } };
 
-    memset(&wi, 0, sizeof(wi));
     if (la) {
         float s[8], v;
         int switch_to_eight = 0;
@@ -400,7 +399,7 @@ static av_unused FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx,
         int stay_short = 0;
         for (i = 0; i < 8; i++) {
             for (j = 0; j < 128; j++) {
-                v = iir_filter(la[(i*128+j)*ctx->avctx->channels], pch->iir_state);
+                v = iir_filter(la[i*128+j], pch->iir_state);
                 sum += v*v;
             }
             s[i]  = sum;
@@ -557,8 +556,8 @@ static float calc_reduced_thr_3gpp(AacPsyBand *band, float min_snr,
 /**
  * Calculate band thresholds as suggested in 3GPP TS26.403
  */
-static void psy_3gpp_analyze(FFPsyContext *ctx, int channel,
-                             const float *coefs, const FFPsyWindowInfo *wi)
+static void psy_3gpp_analyze_channel(FFPsyContext *ctx, int channel,
+                                     const float *coefs, const FFPsyWindowInfo *wi)
 {
     AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data;
     AacPsyChannel *pch  = &pctx->ch[channel];
@@ -741,6 +740,16 @@ static void psy_3gpp_analyze(FFPsyContext *ctx, int channel,
     memcpy(pch->prev_band, pch->band, sizeof(pch->band));
 }
 
+static void psy_3gpp_analyze(FFPsyContext *ctx, int channel,
+                                   const float **coeffs, const FFPsyWindowInfo *wi)
+{
+    int ch;
+    FFPsyChannelGroup *group = ff_psy_find_group(ctx, channel);
+
+    for (ch = 0; ch < group->num_ch; ch++)
+        psy_3gpp_analyze_channel(ctx, channel + ch, coeffs[ch], &wi[ch]);
+}
+
 static av_cold void psy_3gpp_end(FFPsyContext *apc)
 {
     AacPsyContext *pctx = (AacPsyContext*) apc->model_priv_data;
@@ -766,9 +775,8 @@ static void lame_apply_block_type(AacPsyChannel *ctx, FFPsyWindowInfo *wi, int u
     ctx->next_window_seq = blocktype;
 }
 
-static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx,
-                                       const int16_t *audio, const int16_t *la,
-                                       int channel, int prev_type)
+static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio,
+                                       const float *la, int channel, int prev_type)
 {
     AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data;
     AacPsyChannel *pch  = &pctx->ch[channel];
@@ -776,29 +784,28 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx,
     int uselongblock = 1;
     int attacks[AAC_NUM_BLOCKS_SHORT + 1] = { 0 };
     int i;
-    FFPsyWindowInfo wi;
+    FFPsyWindowInfo wi = { { 0 } };
 
-    memset(&wi, 0, sizeof(wi));
     if (la) {
         float hpfsmpl[AAC_BLOCK_SIZE_LONG];
         float const *pf = hpfsmpl;
         float attack_intensity[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS];
         float energy_subshort[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS];
         float energy_short[AAC_NUM_BLOCKS_SHORT + 1] = { 0 };
-        int chans = ctx->avctx->channels;
-        const int16_t *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN) * chans;
+        const float *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN);
         int j, att_sum = 0;
 
         /* LAME comment: apply high pass filter of fs/4 */
         for (i = 0; i < AAC_BLOCK_SIZE_LONG; i++) {
             float sum1, sum2;
-            sum1 = firbuf[(i + ((PSY_LAME_FIR_LEN - 1) / 2)) * chans];
+            sum1 = firbuf[i + (PSY_LAME_FIR_LEN - 1) / 2];
             sum2 = 0.0;
             for (j = 0; j < ((PSY_LAME_FIR_LEN - 1) / 2) - 1; j += 2) {
-                sum1 += psy_fir_coeffs[j] * (firbuf[(i + j) * chans] + firbuf[(i + PSY_LAME_FIR_LEN - j) * chans]);
-                sum2 += psy_fir_coeffs[j + 1] * (firbuf[(i + j + 1) * chans] + firbuf[(i + PSY_LAME_FIR_LEN - j - 1) * chans]);
+                sum1 += psy_fir_coeffs[j] * (firbuf[i + j] + firbuf[i + PSY_LAME_FIR_LEN - j]);
+                sum2 += psy_fir_coeffs[j + 1] * (firbuf[i + j + 1] + firbuf[i + PSY_LAME_FIR_LEN - j - 1]);
             }
-            hpfsmpl[i] = sum1 + sum2;
+            /* NOTE: The LAME psymodel expects it's input in the range -32768 to 32768. Tuning this for normalized floats would be difficult. */
+            hpfsmpl[i] = (sum1 + sum2) * 32768.0f;
         }
 
         /* Calculate the energies of each sub-shortblock */
@@ -813,16 +820,15 @@ static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx,
             float const *const pfe = pf + AAC_BLOCK_SIZE_LONG / (AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS);
             float p = 1.0f;
             for (; pf < pfe; pf++)
-                if (p < fabsf(*pf))
-                    p = fabsf(*pf);
+                p = FFMAX(p, fabsf(*pf));
             pch->prev_energy_subshort[i] = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS] = p;
             energy_short[1 + i / PSY_LAME_NUM_SUBBLOCKS] += p;
-            /* FIXME: The indexes below are [i + 3 - 2] in the LAME source.
-             *          Obviously the 3 and 2 have some significance, or this would be just [i + 1]
-             *          (which is what we use here). What the 3 stands for is ambigious, as it is both
-             *          number of short blocks, and the number of sub-short blocks.
-             *          It seems that LAME is comparing each sub-block to sub-block + 1 in the
-             *          previous block.
+            /* NOTE: The indexes below are [i + 3 - 2] in the LAME source.
+             *       Obviously the 3 and 2 have some significance, or this would be just [i + 1]
+             *       (which is what we use here). What the 3 stands for is ambiguous, as it is both
+             *       number of short blocks, and the number of sub-short blocks.
+             *       It seems that LAME is comparing each sub-block to sub-block + 1 in the
+             *       previous block.
              */
             if (p > energy_subshort[i + 1])
                 p = p / energy_subshort[i + 1];
@@ -921,6 +927,5 @@ const FFPsyModel ff_aac_psy_model =
     .init    = psy_3gpp_init,
     .window  = psy_lame_window,
     .analyze = psy_3gpp_analyze,
-    .analyze_group = NULL,
     .end     = psy_3gpp_end,
 };