diff --git a/include/Oscillator.h b/include/Oscillator.h index 0a5e166dc..501002b8e 100644 --- a/include/Oscillator.h +++ b/include/Oscillator.h @@ -237,7 +237,7 @@ public: static inline float freqFromWaveTableBand(int band) { - return 440.0f * std::pow(2.0f, (band * OscillatorConstants::SEMITONES_PER_TABLE - 69.0f) / 12.0f); + return 440.0f * std::exp2((band * OscillatorConstants::SEMITONES_PER_TABLE - 69.0f) / 12.0f); } private: diff --git a/plugins/FreeBoy/FreeBoy.cpp b/plugins/FreeBoy/FreeBoy.cpp index e9acddeeb..c0eadf2f1 100644 --- a/plugins/FreeBoy/FreeBoy.cpp +++ b/plugins/FreeBoy/FreeBoy.cpp @@ -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; diff --git a/plugins/Monstro/Monstro.cpp b/plugins/Monstro/Monstro.cpp index ff92abbb6..c7d22edfe 100644 --- a/plugins/Monstro/Monstro.cpp +++ b/plugins/Monstro/Monstro.cpp @@ -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); } diff --git a/plugins/MultitapEcho/MultitapEchoControls.cpp b/plugins/MultitapEcho/MultitapEchoControls.cpp index 4df05afc6..81f71d460 100644 --- a/plugins/MultitapEcho/MultitapEchoControls.cpp +++ b/plugins/MultitapEcho/MultitapEchoControls.cpp @@ -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 ); } diff --git a/plugins/SlicerT/SlicerT.cpp b/plugins/SlicerT/SlicerT.cpp index 3b0602584..e510e8cb9 100644 --- a/plugins/SlicerT/SlicerT.cpp +++ b/plugins/SlicerT/SlicerT.cpp @@ -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; diff --git a/src/core/DrumSynth.cpp b/src/core/DrumSynth.cpp index f855639cb..5421886f8 100644 --- a/src/core/DrumSynth.cpp +++ b/src/core/DrumSynth.cpp @@ -30,6 +30,8 @@ #include #include +#include "lmms_math.h" + #ifdef _MSC_VER // not #if LMMS_BUILD_WIN32 because we have strncasecmp in mingw #define strcasecmp _stricmp @@ -403,13 +405,13 @@ int DrumSynth::GetDSFileSamples(QString dsfile, int16_t*& wave, int channels, sa timestretch *= Fs / 44100.f; DGain = 1.0f; // leave this here! - DGain = static_cast(std::pow(10.0, 0.05 * GetPrivateProfileFloat(sec, "Level", 0, dsfile))); + DGain = fastPow10f(0.05 * GetPrivateProfileFloat(sec, "Level", 0, dsfile)); MasterTune = GetPrivateProfileFloat(sec, "Tuning", 0.0, dsfile); - MasterTune = static_cast(std::pow(1.0594631f, MasterTune + mem_tune)); + MasterTune = std::pow(1.0594631f, MasterTune + mem_tune); MainFilter = 2 * GetPrivateProfileInt(sec, "Filter", 0, dsfile); MFres = 0.0101f * GetPrivateProfileFloat(sec, "Resonance", 0.0, dsfile); - MFres = static_cast(std::pow(MFres, 0.5f)); + MFres = std::sqrt(MFres); HighPass = GetPrivateProfileInt(sec, "HighPass", 0, dsfile); GetEnv(7, sec, "FilterEnv", dsfile); @@ -455,7 +457,7 @@ int DrumSynth::GetDSFileSamples(QString dsfile, int16_t*& wave, int channels, sa TDroopRate = GetPrivateProfileFloat(sec, "Droop", 0.f, dsfile); if (TDroopRate > 0.f) { - TDroopRate = static_cast(std::pow(10.0f, (TDroopRate - 20.0f) / 30.0f)); + TDroopRate = fastPow10f((TDroopRate - 20.0f) / 30.0f); TDroopRate = TDroopRate * -4.f / envData[1][MAX]; TDroop = 1; F2 = F1 + ((F2 - F1) / (1.f - static_cast(exp(TDroopRate * envData[1][MAX])))); @@ -482,7 +484,7 @@ int DrumSynth::GetDSFileSamples(QString dsfile, int16_t*& wave, int channels, sa OW1 = GetPrivateProfileInt(sec, "Wave1", 0, dsfile); OW2 = GetPrivateProfileInt(sec, "Wave2", 0, dsfile); OBal2 = static_cast(GetPrivateProfileInt(sec, "Param", 50, dsfile)); - ODrive = static_cast(std::pow(OBal2, 3.0f)) / std::pow(50.0f, 3.0f); + ODrive = (OBal2 * OBal2 * OBal2) / 125000.0f; OBal2 *= 0.01f; OBal1 = 1.f - OBal2; Ophi1 = Tphi; @@ -556,9 +558,8 @@ int DrumSynth::GetDSFileSamples(QString dsfile, int16_t*& wave, int channels, sa { DAtten = DGain * static_cast(LoudestEnv()); clippoint = DAtten > 32700 ? 32700 : static_cast(DAtten); - DAtten = static_cast(std::pow(2.0, 2.0 * GetPrivateProfileInt(sec, "Bits", 0, dsfile))); - DGain = DAtten * DGain - * static_cast(std::pow(10.0, 0.05 * GetPrivateProfileInt(sec, "Clipping", 0, dsfile))); + DAtten = std::exp2(2.0 * GetPrivateProfileInt(sec, "Bits", 0, dsfile)); + DGain = DAtten * DGain * fastPow10f(0.05 * GetPrivateProfileInt(sec, "Clipping", 0, dsfile)); } // prepare envelopes @@ -856,7 +857,7 @@ int DrumSynth::GetDSFileSamples(QString dsfile, int16_t*& wave, int channels, sa MFtmp = envData[7][ENV]; if (MFtmp > 0.2f) { - MFfb = 1.001f - static_cast(std::pow(10.0f, MFtmp - 1)); + MFfb = 1.001f - fastPow10f(MFtmp - 1); } else { @@ -883,7 +884,7 @@ int DrumSynth::GetDSFileSamples(QString dsfile, int16_t*& wave, int channels, sa MFtmp = envData[7][ENV]; if (MFtmp > 0.2f) { - MFfb = 1.001f - static_cast(std::pow(10.0f, MFtmp - 1)); + MFfb = 1.001f - fastPow10f(MFtmp - 1); } else {