mirror of
https://github.com/azahar-emu/soundtouch
synced 2025-11-06 23:20:03 +01:00
Refactor pow() usage
Refactor pow() usage: - use base of 0.5^k instead of 1/(2^k) - skip pow if using INTEGER_SAMPLES
This commit is contained in:
parent
e31e1715fb
commit
5dede763ff
@ -301,7 +301,7 @@ void BPMDetect::updateXCorr(int process_samples)
|
|||||||
pBuffer = buffer->ptrBegin();
|
pBuffer = buffer->ptrBegin();
|
||||||
|
|
||||||
// calculate decay factor for xcorr filtering
|
// calculate decay factor for xcorr filtering
|
||||||
float xcorr_decay = (float)pow(0.5, 1.0 / (XCORR_DECAY_TIME_CONSTANT * TARGET_SRATE / process_samples));
|
float xcorr_decay = (float)pow(0.5, process_samples / (XCORR_DECAY_TIME_CONSTANT * TARGET_SRATE));
|
||||||
|
|
||||||
// prescale pbuffer
|
// prescale pbuffer
|
||||||
float tmp[XCORR_UPDATE_SEQUENCE];
|
float tmp[XCORR_UPDATE_SEQUENCE];
|
||||||
|
|||||||
@ -56,7 +56,6 @@ using namespace soundtouch;
|
|||||||
FIRFilter::FIRFilter()
|
FIRFilter::FIRFilter()
|
||||||
{
|
{
|
||||||
resultDivFactor = 0;
|
resultDivFactor = 0;
|
||||||
resultDivider = 0;
|
|
||||||
length = 0;
|
length = 0;
|
||||||
lengthDiv8 = 0;
|
lengthDiv8 = 0;
|
||||||
filterCoeffs = nullptr;
|
filterCoeffs = nullptr;
|
||||||
@ -207,24 +206,24 @@ void FIRFilter::setCoefficients(const SAMPLETYPE *coeffs, uint newLength, uint u
|
|||||||
assert(newLength > 0);
|
assert(newLength > 0);
|
||||||
if (newLength % 8) ST_THROW_RT_ERROR("FIR filter length not divisible by 8");
|
if (newLength % 8) ST_THROW_RT_ERROR("FIR filter length not divisible by 8");
|
||||||
|
|
||||||
#ifdef SOUNDTOUCH_FLOAT_SAMPLES
|
|
||||||
// scale coefficients already here if using floating samples
|
|
||||||
double scale = 1.0 / resultDivider;
|
|
||||||
#else
|
|
||||||
short scale = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lengthDiv8 = newLength / 8;
|
lengthDiv8 = newLength / 8;
|
||||||
length = lengthDiv8 * 8;
|
length = lengthDiv8 * 8;
|
||||||
assert(length == newLength);
|
assert(length == newLength);
|
||||||
|
|
||||||
resultDivFactor = uResultDivFactor;
|
resultDivFactor = uResultDivFactor;
|
||||||
resultDivider = (SAMPLETYPE)::pow(2.0, (int)resultDivFactor);
|
|
||||||
|
|
||||||
delete[] filterCoeffs;
|
delete[] filterCoeffs;
|
||||||
filterCoeffs = new SAMPLETYPE[length];
|
filterCoeffs = new SAMPLETYPE[length];
|
||||||
delete[] filterCoeffsStereo;
|
delete[] filterCoeffsStereo;
|
||||||
filterCoeffsStereo = new SAMPLETYPE[length*2];
|
filterCoeffsStereo = new SAMPLETYPE[length*2];
|
||||||
|
|
||||||
|
#ifdef SOUNDTOUCH_FLOAT_SAMPLES
|
||||||
|
// scale coefficients already here if using floating samples
|
||||||
|
const double scale = ::pow(0.5, (int)resultDivFactor);;
|
||||||
|
#else
|
||||||
|
const short scale = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
for (uint i = 0; i < length; i ++)
|
for (uint i = 0; i < length; i ++)
|
||||||
{
|
{
|
||||||
filterCoeffs[i] = (SAMPLETYPE)(coeffs[i] * scale);
|
filterCoeffs[i] = (SAMPLETYPE)(coeffs[i] * scale);
|
||||||
|
|||||||
@ -52,9 +52,6 @@ protected:
|
|||||||
// Result divider factor in 2^k format
|
// Result divider factor in 2^k format
|
||||||
uint resultDivFactor;
|
uint resultDivFactor;
|
||||||
|
|
||||||
// Result divider value.
|
|
||||||
SAMPLETYPE resultDivider;
|
|
||||||
|
|
||||||
// Memory for filter coefficients
|
// Memory for filter coefficients
|
||||||
SAMPLETYPE *filterCoeffs;
|
SAMPLETYPE *filterCoeffs;
|
||||||
SAMPLETYPE *filterCoeffsStereo;
|
SAMPLETYPE *filterCoeffsStereo;
|
||||||
|
|||||||
@ -211,9 +211,6 @@ FIRFilterSSE::~FIRFilterSSE()
|
|||||||
// (overloaded) Calculates filter coefficients for SSE routine
|
// (overloaded) Calculates filter coefficients for SSE routine
|
||||||
void FIRFilterSSE::setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor)
|
void FIRFilterSSE::setCoefficients(const float *coeffs, uint newLength, uint uResultDivFactor)
|
||||||
{
|
{
|
||||||
uint i;
|
|
||||||
float fDivider;
|
|
||||||
|
|
||||||
FIRFilter::setCoefficients(coeffs, newLength, uResultDivFactor);
|
FIRFilter::setCoefficients(coeffs, newLength, uResultDivFactor);
|
||||||
|
|
||||||
// Scale the filter coefficients so that it won't be necessary to scale the filtering result
|
// Scale the filter coefficients so that it won't be necessary to scale the filtering result
|
||||||
@ -223,13 +220,13 @@ void FIRFilterSSE::setCoefficients(const float *coeffs, uint newLength, uint uRe
|
|||||||
filterCoeffsUnalign = new float[2 * newLength + 4];
|
filterCoeffsUnalign = new float[2 * newLength + 4];
|
||||||
filterCoeffsAlign = (float *)SOUNDTOUCH_ALIGN_POINTER_16(filterCoeffsUnalign);
|
filterCoeffsAlign = (float *)SOUNDTOUCH_ALIGN_POINTER_16(filterCoeffsUnalign);
|
||||||
|
|
||||||
fDivider = (float)resultDivider;
|
const float scale = ::pow(0.5, (int)resultDivFactor);
|
||||||
|
|
||||||
// rearrange the filter coefficients for mmx routines
|
// rearrange the filter coefficients for sse routines
|
||||||
for (i = 0; i < newLength; i ++)
|
for (auto i = 0U; i < newLength; i ++)
|
||||||
{
|
{
|
||||||
filterCoeffsAlign[2 * i + 0] =
|
filterCoeffsAlign[2 * i + 0] =
|
||||||
filterCoeffsAlign[2 * i + 1] = coeffs[i + 0] / fDivider;
|
filterCoeffsAlign[2 * i + 1] = coeffs[i] * scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user