# [FFmpeg-devel] AAC encoder questions

Alex Converse alex.converse
Fri Apr 24 19:04:56 CEST 2009

```On Fri, Apr 24, 2009 at 9:34 AM, Kostya <kostya.shishkov at gmail.com> wrote:
> On Fri, Apr 24, 2009 at 03:51:13AM -0400, Alex Converse wrote:
>> On Fri, Apr 24, 2009 at 3:16 AM, Kostya <kostya.shishkov at gmail.com> wrote:
>> > On Fri, Apr 24, 2009 at 03:07:18AM -0400, Alex Converse wrote:
> [...]
>> >> > ?? ? ? ? ? ? ? ? ? ? ? rd = INFINITY;
>> >> > ?? ? ? ? ? ? ? ? ? ? ? break;
>> >> > ?? ? ? ? ? ? ? ? ? }
>> >> > ?? ? ? ? ? ? ? ? ? if(vec[k] == 64.0f){//FIXME: slow
>> >> > ?? ? ? ? ? ? ? ? ? ? ? if(t >= 165140.0f*IQ){ // clipped value
>> >> > ?? ? ? ? ? ? ? ? ? ? ? ? ? di = t - 165140.0f;
>> >> Shouldn't this be "di = t - 165140.0f*IQ;"
>> >
>> > I don't think so - it means quantised and unquantised value (like in else below)
>> >
>>
>> The numbers just seem really strange...
>>
>> let's say Q=0.5 this implies IQ = 2.0
>>
>> now lets look @ t == 330200:
>> the if is false -> c = 8190 -> di = 27
>> @ t == 330250:
>> the if is false -> c = 8191 -> di = 23
>> @ t == 330279:
>> the if is false -> c = 8191 -> di = 52 //Clipping is occuring here too
>> @ t == 330280:
>> the if is true -> di = 165140
>> @ a t == 330300:
>> the if is true -> di = 165110
>
> Well, my logic was:
> * we have coefficient t
> * dividing it by quantizer to compare with codebook vector is equivalent to
> ?multiplying that codebook vector by quantizer and we don't have to scale that
> ?difference back
> * 165140 ~= pow(8192, 1.33) - maximum value for unclipped output coeff
> * t >= 165140*IQ should mean that clipping will occur with that value of quantiser
> * if clipping happens, we will get maximum value instead of real one, so it will be
> ?always 165140 which is used in calculating difference.
>

Yes but in the other code path we use pow(x, 1.3333)*IQ. The t we are
comparing to is scaled by IQ. That is why the initial comparison is
scaled by IQ.

Trying to work through the logic of it:

Normally we do t - pow(clip(floor(pow(t * Q, .75)+0.4504), 8191), 1.333)*IQ
the top case is a shortcut where we know that the clip will resolve to
8191. (I'm also not sure why we are using 8192 up there, but that is a
separate issue. "The maximum allowed absolute amplitude for x_quant is
8191.")

Assuming we use this shortcut then out expression is pow(8191, 1.333)
* IQ which resolves to 165140*IQ (or 165113*IQ for 8191...).

```