## todB () function correction

In the mapping0_forward () function in the file mapping0.c file, while converting fft values to dB scale, a local maximum calculations are performed. In the first iteration, the max value is initialized to fft[0] (magnitude of signal) while in later on iterations, the maximum value is initialized to magnitude^2. In dB conversion of these values, a constant is subtracted in the todB () function. However, in the first iteration the constant is subtracted from the magnitude value, while in the further iterations the value is subtracted from magnitude^2.

```
logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
original todB estimation used on
IEEE 754 compliant machines had a
bug that returned dB values about
a third of a decibel too high.
The bug was harmless because
tunings implicitly took that into
account. However, fixing the bug
in the estimator requires
changing all the tunings as well.
For now, it's easier to sync
things back up here, and
recalibrate the tunings in the
next major model upgrade. */
local_ampmax[i]=logfft[0];
for(j=1;j<n-1;j+=2){
float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1]; //magnitude square calculation
temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
.345 is a hack; the original todB
estimation used on IEEE 754
compliant machines had a bug that
returned dB values about a third
of a decibel too high. The bug
was harmless because tunings
implicitly took that into
account. However, fixing the bug
in the estimator requires
changing all the tunings as well.
For now, it's easier to sync
things back up here, and
recalibrate the tunings in the
next major model upgrade. */
if(temp>local_ampmax[i])local_ampmax[i]=temp;
}
if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
```

//todB () function definition. static inline float todB(const float *x){ union { ogg_uint32_t i; float f; } ix; ix.f = *x; ix.i = ix.i&0x7fffffff; return (float)(ix.i * 7.17711438e-7f -764.6161886f); //764.6161886 is subtracted from fft[0] as well as amp^2. //The constant subtraction is not consistent over the max calculations }