On 18/04/15 00:55, Andreas Cadhalpun wrote:
> On 17.04.2015 23:39, Luca Barbato wrote:
>> On 17/04/15 16:08, Andreas Cadhalpun wrote:
>>> On 17.04.2015 02:01, Luca Barbato wrote:
>>>> is band->thr = 0.0f a valid value?
>>>
>>> Come to think of it, that's probably invalid.
> 
> I retract that, it seems band->thr = 0.0f is valid.
> 
>>> It can happen if coeffs[g].ath is not positive.
>>
>> ath() returns easily Inf and negative values...
> 
> It returns Inf for 0 and Inf, though that's not the
> problem here. Neither is that it can return negative
> values, because the minimum of the ath() function is
> (or rather should be) subtracted:
>     coeffs[g].ath = minscale - minath;
> 
> The problem is that minath is not the minimum, only close:
>     minath = ath(3410, ATH_ADD) = -5.24237967
>              ath(3407, ATH_ADD) = -5.24241638
> 
> Attached patch is fixing this. With it the minimal value
> of coeffs[g].ath is 0.0f. 
> 
>>> Attached patch errors out in this case.
> 
> Scratch that patch. It shouldn't be negative (fixed with
> attached patch), but 0.0f is possible.
> 
>>>> band->energy can be 0?
>>>
>>> Yes, it's set to 0.0f in calc_thr_3gpp if enough coefs are 0.
>>
>> and in that case the threshold? (that is calculated as a fraction of the
>> energy at least in one place).
> 
> In that case band->thr is set to coeffs[g].ath:
>     band->thr_quiet = band->thr = FFMAX(band->thr, coeffs[g].ath);
> 
> So band->thr still can be 0.0f, i.e. the patch checking for (band->thr > 0.0f)
> is still necessary.

if thr is really tiny norm_fac would be huge, not tiny. (or tiny and not
huge depending if you look it before or after norm_fac = 1/norm_fac)

Once you have a threshold 0 you could basically short circuit the whole
loop and the one below gets sort of funny since you have a 0 * Inf.

And while at it maybe it could be simplified like this (still not fully
awake).

diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
index 6c6e573..43565ff 100644
--- a/libavcodec/aacpsy.c
+++ b/libavcodec/aacpsy.c
@@ -108,7 +108,6 @@ typedef struct AacPsyBand{
     float active_lines; ///< number of active spectral lines
     float pe;           ///< perceptual entropy
     float pe_const;     ///< constant part of the PE calculation
-    float norm_fac;     ///< normalization factor for linearization
     int   avoid_holes;  ///< hole avoidance flag
 }AacPsyBand;

@@ -685,8 +684,7 @@ static void psy_3gpp_analyze_channel(FFPsyContext
*ctx, int channel,
                     if (active_lines > 0.0f)
                         band->thr = calc_reduced_thr_3gpp(band,
coeffs[g].min_snr, reduction);
                     pe += calc_pe_3gpp(band);
-                    band->norm_fac = band->active_lines / band->thr;
-                    norm_fac += band->norm_fac;
+                    norm_fac += band->active_lines / band->thr;
                 }
             }
             delta_pe = desired_pe - pe;
@@ -702,10 +700,10 @@ static void psy_3gpp_analyze_channel(FFPsyContext
*ctx, int channel,
                     AacPsyBand *band = &pch->band[w+g];

                     if (band->active_lines > 0.5f) {
-                        float delta_sfb_pe = band->norm_fac * norm_fac
* delta_pe;
+                        float delta_sfb_pe = norm_fac * delta_pe /
band->thr;
                         float thr = band->thr;

-                        thr *= powf(2.0f, delta_sfb_pe /
band->active_lines);
+                        thr *= powf(2.0f, delta_sfb_pe);
                         if (thr > coeffs[g].min_snr * band->energy &&
band->avoid_holes == PSY_3GPP_AH_IN


lu
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to