Fixed bug when APPROXNORM == 1 is used when CCEMBEDDED is not defined (ie colorchord2)

This commit is contained in:
bbkiwi 2019-07-06 14:12:37 +12:00
parent 35a4abfb50
commit cd9094e8cb
2 changed files with 13 additions and 16 deletions

View file

@ -168,33 +168,32 @@ void UpdateOutputBins32()
int32_t * ipt = &Sdatspace32BOut[0];
for( i = 0; i < FIXBINS; i++ )
{
#if APPROXNORM == 1
int32_t isps = *(ipt++); //can keep 32 bits as no need to square
int32_t isps = *(ipt++); //keep 32 bits
int32_t ispc = *(ipt++);
#else
int16_t isps = *(ipt++)>>16; //might loose some precision with this
int16_t ispc = *(ipt++)>>16;
#endif
// take absolute values
isps = isps<0? -isps : isps;
ispc = ispc<0? -ispc : ispc;
int octave = i / FIXBPERO;
//If we are running DFT32 on regular ColorChord, then we will need to
//also update goutbins[]... But if we're on embedded systems, we only
//update embeddedbins32.
#ifndef CCEMBEDDED
uint32_t mux = ( (isps) * (isps)) + ((ispc) * (ispc));
goutbins[i] = sqrtf( (float)mux );
// convert 32 bit precision isps and ispc to floating point
float mux = ( (float)isps * (float)isps) + ((float)ispc * (float)ispc);
goutbins[i] = sqrtf(mux)/65536.0; // scale by 2^16
//reasonable (but arbitrary attenuation)
goutbins[i] /= (78<<DFTIIR)*(1<<octave);
#endif
#if APPROXNORM == 1
isps = isps<0? -isps : isps;
ispc = ispc<0? -ispc : ispc;
// using full 32 bit precision for isps and ispc
uint32_t rmux = isps>ispc? isps + (ispc>>1) : ispc + (isps>>1);
rmux = rmux>>16;
rmux = rmux>>16; // keep most significant 16 bits
#else
uint32_t rmux = ( (isps) * (isps)) + ((ispc) * (ispc));
// use the most significant 16 bits of isps and ispc when squaring
// since isps and ispc are non-negative right bit shifing is well defined
uint32_t rmux = ( (isps>>16) * (isps>>16)) + ((ispc>16) * (ispc>>16));
rmux = SquareRootRounded( rmux );
#endif

View file

@ -24,9 +24,7 @@
// Will used simple approximation of norm rather than
// sum squares and approx sqrt
#ifndef APPROXNORM
//XXX CNL: BBKiwi added this feature but it seems to break stuff.
//For now, the correct behavior should be to default without approxnorm.
//#define APPROXNORM 1
#define APPROXNORM 1
#endif
#ifndef OCTAVES