Optimise usage of pow using fast equivalent and exp2 (#7548)
* replace std::pow with better performing equivalents * revert one instance where I swapped to fastPow10f * Negative slope instead of multiplying -1 Co-authored-by: saker <sakertooth@gmail.com> --------- Co-authored-by: saker <sakertooth@gmail.com>
This commit is contained in:
@@ -352,14 +352,14 @@ void FreeBoyInstrument::playNote(NotePlayHandle* nph, SampleFrame* workingBuffer
|
||||
// a unique frequency, we can start by guessing s = r = 0 here and then skip r = 0 in the loop.
|
||||
char clock_freq = 0;
|
||||
char div_ratio = 0;
|
||||
float closest_freq = 524288.0 / (0.5 * std::pow(2.0, clock_freq + 1.0));
|
||||
float closest_freq = 524288.0 / (0.5 * std::exp2(clock_freq + 1.0));
|
||||
// This nested for loop iterates over all possible combinations of clock frequency and dividing
|
||||
// ratio and chooses the combination whose resulting frequency is closest to the note frequency
|
||||
for (char s = 0; s < 16; ++s)
|
||||
{
|
||||
for (char r = 1; r < 8; ++r)
|
||||
{
|
||||
float f = 524288.0 / (r * std::pow(2.0, s + 1.0));
|
||||
float f = 524288.0 / (r * std::exp2(s + 1.0));
|
||||
if (std::fabs(freq - closest_freq) > std::fabs(freq - f))
|
||||
{
|
||||
closest_freq = f;
|
||||
|
||||
@@ -1462,14 +1462,14 @@ void MonstroInstrument::updateSamplerate()
|
||||
void MonstroInstrument::updateSlope1()
|
||||
{
|
||||
const float slope = m_env1Slope.value();
|
||||
m_slope[0] = std::pow(10.f, slope * -1.0f );
|
||||
m_slope[0] = fastPow10f(-slope);
|
||||
}
|
||||
|
||||
|
||||
void MonstroInstrument::updateSlope2()
|
||||
{
|
||||
const float slope = m_env2Slope.value();
|
||||
m_slope[1] = std::pow(10.f, slope * -1.0f );
|
||||
m_slope[1] = fastPow10f(-slope);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ void MultitapEchoControls::lpSamplesChanged( int begin, int end )
|
||||
const float * samples = m_lpGraph.samples();
|
||||
for( int i = begin; i <= end; ++i )
|
||||
{
|
||||
m_effect->m_lpFreq[i] = 20.0f * std::pow(10.f, samples[i] );
|
||||
m_effect->m_lpFreq[i] = 20.0f * fastPow10f(samples[i]);
|
||||
}
|
||||
m_effect->updateFilters( begin, end );
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ void SlicerT::findSlices()
|
||||
float magnitude = std::sqrt(real * real + imag * imag);
|
||||
|
||||
// using L2-norm (euclidean distance)
|
||||
float diff = std::sqrt(std::pow(magnitude - prevMags[j], 2));
|
||||
float diff = std::abs(magnitude - prevMags[j]);
|
||||
spectralFlux += diff;
|
||||
|
||||
prevMags[j] = magnitude;
|
||||
|
||||
Reference in New Issue
Block a user