Update math functions to C++ standard library (#7685)
* use c++ std::* math functions This updates usages of sin, cos, tan, pow, exp, log, log10, sqrt, fmod, fabs, and fabsf, excluding any usages that look like they might be part of a submodule or 3rd-party code. There's probably some std math functions not listed here that haven't been updated yet. * fix std::sqrt typo lmao one always sneaks by * Apply code review suggestions - std::pow(2, x) -> std::exp2(x) - std::pow(10, x) -> lmms::fastPow10f(x) - std::pow(x, 2) -> x * x, std::pow(x, 3) -> x * x * x, etc. - Resolve TODOs, fix typos, and so forth Co-authored-by: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> * Fix double -> float truncation, DrumSynth fix I mistakenly introduced a bug in my recent PR regarding template constants, in which a -1 that was supposed to appear outside of an abs() instead was moved inside it, screwing up the generated waveform. I fixed that and also simplified the function by factoring out the phase domain wrapping using the new `ediv()` function from this PR. It should behave how it's supposed to now... assuming all my parentheses are in the right place lol * Annotate magic numbers with TODOs for C++20 * On second thought, why wait? What else is lmms::numbers for? * begone inline Co-authored-by: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> * begone other inline Co-authored-by: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> * Re-inline function in lmms_math.h For functions, constexpr implies inline so this just re-adds inline to the one that isn't constexpr yet * Formatting fixes, readability improvements Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com> * Fix previously missed pow() calls, cleanup Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com> * Just delete ediv() entirely lmao No ediv(), no std::fmod(), no std::remainder(), just std::floor(). It should all work for negative phase inputs as well. If I end up needing ediv() in the future, I can add it then. * Simplify DrumSynth triangle waveform This reuses more work and is also a lot more easy to visualize. It's probably a meaningless micro-optimization, but it might be worth changing it back to a switch-case and just calculating ph_tau and saw01 at the beginning of the function in all code paths, even if it goes unused for the first two cases. Guess I'll see if anybody has strong opinions about it. * Move multiplication inside abs() * Clean up a few more pow(x, 2) -> x * x * Remove numbers::inv_pi, numbers::inv_tau * delete spooky leading 0 Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com> --------- Co-authored-by: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
This commit is contained in:
@@ -86,7 +86,7 @@ BSynth::BSynth( float * _shape, NotePlayHandle * _nph, bool _interpolation,
|
||||
i.e., the absolute value of all samples is <= 1.0 if _factor
|
||||
is different to the default normalization factor. If there is
|
||||
a value > 1.0, clip the sample to 1.0 to limit the range. */
|
||||
if ((_factor != defaultNormalizationFactor) && (fabsf(buf) > 1.0f))
|
||||
if ((_factor != defaultNormalizationFactor) && (std::abs(buf) > 1.0f))
|
||||
{
|
||||
buf = (buf < 0) ? -1.0f : 1.0f;
|
||||
}
|
||||
@@ -238,7 +238,7 @@ void BitInvader::normalize()
|
||||
const float* samples = m_graph.samples();
|
||||
for(int i=0; i < m_graph.length(); i++)
|
||||
{
|
||||
const float f = fabsf( samples[i] );
|
||||
const float f = std::abs(samples[i]);
|
||||
if (f > max) { max = f; }
|
||||
}
|
||||
m_normalizeFactor = 1.0 / max;
|
||||
@@ -554,4 +554,4 @@ PLUGIN_EXPORT Plugin * lmms_plugin_main( Model *m, void * )
|
||||
}
|
||||
|
||||
|
||||
} // namespace lmms
|
||||
} // namespace lmms
|
||||
|
||||
@@ -61,7 +61,7 @@ CompressorEffect::CompressorEffect(Model* parent, const Descriptor::SubPluginFea
|
||||
m_yL[0] = m_yL[1] = COMP_NOISE_FLOOR;
|
||||
|
||||
// 200 ms
|
||||
m_crestTimeConst = exp(-1.f / (0.2f * m_sampleRate));
|
||||
m_crestTimeConst = std::exp(-1.f / (0.2f * m_sampleRate));
|
||||
|
||||
connect(&m_compressorControls.m_attackModel, SIGNAL(dataChanged()), this, SLOT(calcAttack()), Qt::DirectConnection);
|
||||
connect(&m_compressorControls.m_releaseModel, SIGNAL(dataChanged()), this, SLOT(calcRelease()), Qt::DirectConnection);
|
||||
@@ -97,7 +97,7 @@ CompressorEffect::CompressorEffect(Model* parent, const Descriptor::SubPluginFea
|
||||
float CompressorEffect::msToCoeff(float ms)
|
||||
{
|
||||
// Convert time in milliseconds to applicable lowpass coefficient
|
||||
return exp(m_coeffPrecalc / ms);
|
||||
return std::exp(m_coeffPrecalc / ms);
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ void CompressorEffect::calcRange()
|
||||
void CompressorEffect::resizeRMS()
|
||||
{
|
||||
const float rmsValue = m_compressorControls.m_rmsModel.value();
|
||||
m_rmsTimeConst = (rmsValue > 0) ? exp(-1.f / (rmsValue * 0.001f * m_sampleRate)) : 0;
|
||||
m_rmsTimeConst = (rmsValue > 0) ? std::exp(-1.f / (rmsValue * 0.001f * m_sampleRate)) : 0;
|
||||
}
|
||||
|
||||
void CompressorEffect::calcLookaheadLength()
|
||||
@@ -211,14 +211,14 @@ void CompressorEffect::calcTiltCoeffs()
|
||||
{
|
||||
m_tiltVal = m_compressorControls.m_tiltModel.value();
|
||||
|
||||
const float amp = 6 / log(2);
|
||||
const float amp = 6.f / std::log(2.f);
|
||||
|
||||
const float gfactor = 5;
|
||||
const float g1 = m_tiltVal > 0 ? -gfactor * m_tiltVal : -m_tiltVal;
|
||||
const float g2 = m_tiltVal > 0 ? m_tiltVal : gfactor * m_tiltVal;
|
||||
|
||||
m_lgain = exp(g1 / amp) - 1;
|
||||
m_hgain = exp(g2 / amp) - 1;
|
||||
m_lgain = std::exp(g1 / amp) - 1;
|
||||
m_hgain = std::exp(g2 / amp) - 1;
|
||||
|
||||
const float omega = numbers::tau_v<float> * m_compressorControls.m_tiltFreqModel.value();
|
||||
const float n = 1 / (m_sampleRate * 3 + omega);
|
||||
@@ -528,20 +528,6 @@ void CompressorEffect::processBypassedImpl()
|
||||
}
|
||||
}
|
||||
|
||||
// Regular modulo doesn't handle negative numbers correctly. This does.
|
||||
inline int CompressorEffect::realmod(int k, int n)
|
||||
{
|
||||
return (k %= n) < 0 ? k+n : k;
|
||||
}
|
||||
|
||||
// Regular fmod doesn't handle negative numbers correctly. This does.
|
||||
inline float CompressorEffect::realfmod(float k, float n)
|
||||
{
|
||||
return (k = fmod(k, n)) < 0 ? k+n : k;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void CompressorEffect::calcTiltFilter(sample_t inputSample, sample_t &outputSample, int filtNum)
|
||||
{
|
||||
m_tiltOut[filtNum] = m_a0 * inputSample + m_b1 * m_tiltOut[filtNum];
|
||||
@@ -557,7 +543,7 @@ void CompressorEffect::changeSampleRate()
|
||||
m_coeffPrecalc = COMP_LOG / (m_sampleRate * 0.001f);
|
||||
|
||||
// 200 ms
|
||||
m_crestTimeConst = exp(-1.f / (0.2f * m_sampleRate));
|
||||
m_crestTimeConst = std::exp(-1.f / (0.2f * m_sampleRate));
|
||||
|
||||
m_lookBufLength = std::ceil((20.f / 1000.f) * m_sampleRate) + 2;
|
||||
for (int i = 0; i < 2; ++i)
|
||||
|
||||
@@ -78,8 +78,6 @@ private:
|
||||
float msToCoeff(float ms);
|
||||
|
||||
inline void calcTiltFilter(sample_t inputSample, sample_t &outputSample, int filtNum);
|
||||
inline int realmod(int k, int n);
|
||||
inline float realfmod(float k, float n);
|
||||
|
||||
enum class StereoLinkMode { Unlinked, Maximum, Average, Minimum, Blend };
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ Lfo::Lfo( int samplerate )
|
||||
|
||||
float Lfo::tick()
|
||||
{
|
||||
float output = sinf( m_phase );
|
||||
float output = std::sin(m_phase);
|
||||
m_phase += m_increment;
|
||||
|
||||
return output;
|
||||
|
||||
@@ -68,10 +68,10 @@ QRectF EqHandle::boundingRect() const
|
||||
float EqHandle::freqToXPixel( float freq , int w )
|
||||
{
|
||||
if (approximatelyEqual(freq, 0.0f)) { return 0.0f; }
|
||||
float min = log10f( 20 );
|
||||
float max = log10f( 20000 );
|
||||
float min = std::log10(20);
|
||||
float max = std::log10(20000);
|
||||
float range = max - min;
|
||||
return ( log10f( freq ) - min ) / range * w;
|
||||
return (std::log10(freq) - min) / range * w;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,10 +79,10 @@ float EqHandle::freqToXPixel( float freq , int w )
|
||||
|
||||
float EqHandle::xPixelToFreq( float x , int w )
|
||||
{
|
||||
float min = log10f( 20 );
|
||||
float max = log10f( 20000 );
|
||||
float min = std::log10(20);
|
||||
float max = std::log10(20000);
|
||||
float range = max - min;
|
||||
return powf( 10 , x * ( range / w ) + min );
|
||||
return fastPow10f(x * (range / w) + min);
|
||||
}
|
||||
|
||||
|
||||
@@ -202,11 +202,11 @@ float EqHandle::getPeakCurve( float x )
|
||||
{
|
||||
double freqZ = xPixelToFreq( EqHandle::x(), m_width );
|
||||
double w0 = numbers::tau * freqZ / Engine::audioEngine()->outputSampleRate();
|
||||
double c = cosf( w0 );
|
||||
double s = sinf( w0 );
|
||||
double c = std::cos(w0);
|
||||
double s = std::sin(w0);
|
||||
double Q = getResonance();
|
||||
double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) / 40 );
|
||||
double alpha = s * sinh( log( 2 ) / 2 * Q * w0 / sinf( w0 ) );
|
||||
double A = fastPow10f(yPixelToGain(EqHandle::y(), m_heigth, m_pixelsPerUnitHeight) / 40);
|
||||
double alpha = s * std::sinh(std::log(2.0) / 2 * Q * w0 / std::sin(w0));
|
||||
|
||||
//calc coefficents
|
||||
double b0 = 1 + alpha * A;
|
||||
@@ -238,10 +238,10 @@ float EqHandle::getHighShelfCurve( float x )
|
||||
{
|
||||
double freqZ = xPixelToFreq( EqHandle::x(), m_width );
|
||||
double w0 = numbers::tau * freqZ / Engine::audioEngine()->outputSampleRate();
|
||||
double c = cosf( w0 );
|
||||
double s = sinf( w0 );
|
||||
double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) * 0.025 );
|
||||
double beta = sqrt( A ) / m_resonance;
|
||||
double c = std::cos(w0);
|
||||
double s = std::sin(w0);
|
||||
double A = fastPow10f(yPixelToGain(EqHandle::y(), m_heigth, m_pixelsPerUnitHeight) * 0.025);
|
||||
double beta = std::sqrt(A) / m_resonance;
|
||||
|
||||
//calc coefficents
|
||||
double b0 = A * ((A + 1) + (A - 1) * c + beta * s);
|
||||
@@ -273,10 +273,10 @@ float EqHandle::getLowShelfCurve( float x )
|
||||
{
|
||||
double freqZ = xPixelToFreq( EqHandle::x(), m_width );
|
||||
double w0 = numbers::tau * freqZ / Engine::audioEngine()->outputSampleRate();
|
||||
double c = cosf( w0 );
|
||||
double s = sinf( w0 );
|
||||
double A = pow( 10, yPixelToGain( EqHandle::y(), m_heigth, m_pixelsPerUnitHeight ) / 40 );
|
||||
double beta = sqrt( A ) / m_resonance;
|
||||
double c = std::cos(w0);
|
||||
double s = std::sin(w0);
|
||||
double A = fastPow10f(yPixelToGain(EqHandle::y(), m_heigth, m_pixelsPerUnitHeight) / 40);
|
||||
double beta = std::sqrt(A) / m_resonance;
|
||||
|
||||
//calc coefficents
|
||||
double b0 = A * ((A + 1) - (A - 1) * c + beta * s);
|
||||
@@ -308,8 +308,8 @@ float EqHandle::getLowCutCurve( float x )
|
||||
{
|
||||
double freqZ = xPixelToFreq( EqHandle::x(), m_width );
|
||||
double w0 = numbers::tau * freqZ / Engine::audioEngine()->outputSampleRate();
|
||||
double c = cosf( w0 );
|
||||
double s = sinf( w0 );
|
||||
double c = std::cos(w0);
|
||||
double s = std::sin(w0);
|
||||
double resonance = getResonance();
|
||||
double alpha = s / (2 * resonance);
|
||||
|
||||
@@ -350,8 +350,8 @@ float EqHandle::getHighCutCurve( float x )
|
||||
{
|
||||
double freqZ = xPixelToFreq( EqHandle::x(), m_width );
|
||||
double w0 = numbers::tau * freqZ / Engine::audioEngine()->outputSampleRate();
|
||||
double c = cosf( w0 );
|
||||
double s = sinf( w0 );
|
||||
double c = std::cos(w0);
|
||||
double s = std::sin(w0);
|
||||
double resonance = getResonance();
|
||||
double alpha = s / (2 * resonance);
|
||||
|
||||
@@ -525,9 +525,10 @@ double EqHandle::calculateGain(const double freq, const double a1, const double
|
||||
const double w = std::sin(numbers::pi * freq / Engine::audioEngine()->outputSampleRate());
|
||||
const double PHI = w * w * 4;
|
||||
|
||||
double gain = 10 * log10( pow( b0 + b1 + b2 , 2 ) + ( b0 * b2 * PHI - ( b1 * ( b0 + b2 )
|
||||
+ 4 * b0 * b2 ) ) * PHI ) - 10 * log10( pow( 1 + a1 + a2, 2 )
|
||||
+ ( 1 * a2 * PHI - ( a1 * ( 1 + a2 ) + 4 * 1 * a2 ) ) * PHI );
|
||||
auto bb = b0 + b1 + b2;
|
||||
auto aa = 1 + a1 + a2;
|
||||
double gain = 10 * std::log10(bb * bb + (b0 * b2 * PHI - (b1 * (b0 + b2) + 4 * b0 * b2)) * PHI)
|
||||
- 10 * std::log10(aa * aa + (1 * a2 * PHI - (a1 * (1 + a2) + 4 * 1 * a2)) * PHI);
|
||||
return gain;
|
||||
}
|
||||
|
||||
|
||||
@@ -186,8 +186,8 @@ public :
|
||||
|
||||
// calc intermediate
|
||||
float w0 = numbers::tau_v<float> * m_freq / m_sampleRate;
|
||||
float c = cosf( w0 );
|
||||
float s = sinf( w0 );
|
||||
float c = std::cos(w0);
|
||||
float s = std::sin(w0);
|
||||
float alpha = s / ( 2 * m_res );
|
||||
|
||||
//calc coefficents
|
||||
@@ -229,8 +229,8 @@ public :
|
||||
|
||||
// calc intermediate
|
||||
float w0 = numbers::tau_v<float> * m_freq / m_sampleRate;
|
||||
float c = cosf( w0 );
|
||||
float s = sinf( w0 );
|
||||
float c = std::cos(w0);
|
||||
float s = std::sin(w0);
|
||||
float alpha = s / ( 2 * m_res );
|
||||
|
||||
//calc coefficents
|
||||
@@ -270,10 +270,10 @@ public:
|
||||
{
|
||||
// calc intermediate
|
||||
float w0 = numbers::tau_v<float> * m_freq / m_sampleRate;
|
||||
float c = cosf( w0 );
|
||||
float s = sinf( w0 );
|
||||
float A = pow( 10, m_gain * 0.025);
|
||||
float alpha = s * sinh( log( 2 ) / 2 * m_bw * w0 / sinf(w0) );
|
||||
float c = std::cos(w0);
|
||||
float s = std::sin(w0);
|
||||
float A = fastPow10f(m_gain * 0.025);
|
||||
float alpha = s * std::sinh(std::log(2.f) / 2 * m_bw * w0 / std::sin(w0));
|
||||
|
||||
//calc coefficents
|
||||
float b0 = 1 + alpha * A;
|
||||
@@ -333,11 +333,11 @@ public :
|
||||
|
||||
// calc intermediate
|
||||
float w0 = numbers::tau_v<float> * m_freq / m_sampleRate;
|
||||
float c = cosf( w0 );
|
||||
float s = sinf( w0 );
|
||||
float A = pow( 10, m_gain * 0.025);
|
||||
// float alpha = s / ( 2 * m_res );
|
||||
float beta = sqrt( A ) / m_res;
|
||||
float c = std::cos(w0);
|
||||
float s = std::sin(w0);
|
||||
float A = fastPow10f(m_gain * 0.025);
|
||||
// float alpha = s / (2 * m_res);
|
||||
float beta = std::sqrt(A) / m_res;
|
||||
|
||||
//calc coefficents
|
||||
float b0 = A * ((A + 1) - (A - 1) * c + beta * s);
|
||||
@@ -370,10 +370,10 @@ public :
|
||||
|
||||
// calc intermediate
|
||||
float w0 = numbers::tau_v<float> * m_freq / m_sampleRate;
|
||||
float c = cosf( w0 );
|
||||
float s = sinf( w0 );
|
||||
float A = pow( 10, m_gain * 0.025 );
|
||||
float beta = sqrt( A ) / m_res;
|
||||
float c = std::cos(w0);
|
||||
float s = std::sin(w0);
|
||||
float A = fastPow10f(m_gain * 0.025);
|
||||
float beta = std::sqrt(A) / m_res;
|
||||
|
||||
//calc coefficents
|
||||
float b0 = A * ((A + 1) + (A - 1) * c + beta * s);
|
||||
|
||||
@@ -193,7 +193,7 @@ EqSpectrumView::EqSpectrumView(EqAnalyser *b, QWidget *_parent) :
|
||||
connect( getGUI()->mainWindow(), SIGNAL( periodicUpdate() ), this, SLOT( periodicalUpdate() ) );
|
||||
setAttribute( Qt::WA_TranslucentBackground, true );
|
||||
m_skipBands = MAX_BANDS * 0.5;
|
||||
float totalLength = log10( 20000 );
|
||||
const float totalLength = std::log10(20000);
|
||||
m_pixelsPerUnitWidth = width() / totalLength ;
|
||||
m_scale = 1.5;
|
||||
m_color = QColor( 255, 255, 255, 255 );
|
||||
@@ -233,7 +233,7 @@ void EqSpectrumView::paintEvent(QPaintEvent *event)
|
||||
const float fallOff = 1.07f;
|
||||
for( int x = 0; x < MAX_BANDS; ++x, ++bands )
|
||||
{
|
||||
float peak = *bands != 0. ? (fh * 2.0 / 3.0 * (20. * log10(*bands / energy) - LOWER_Y) / (-LOWER_Y)) : 0.;
|
||||
float peak = *bands != 0. ? (fh * 2.0 / 3.0 * (20. * std::log10(*bands / energy) - LOWER_Y) / (-LOWER_Y)) : 0.;
|
||||
|
||||
if( peak < 0 )
|
||||
{
|
||||
|
||||
@@ -1101,9 +1101,7 @@ GigSample::GigSample( gig::Sample * pSample, gig::DimensionRegion * pDimRegion,
|
||||
if( region->PitchTrack == true )
|
||||
{
|
||||
// Calculate what frequency the provided sample is
|
||||
sampleFreq = 440.0 * powf( 2, 1.0 / 12 * (
|
||||
1.0 * region->UnityNote - 69 -
|
||||
0.01 * region->FineTune ) );
|
||||
sampleFreq = 440.0f * std::exp2((region->UnityNote - 69 - region->FineTune * 0.01) / 12.0f);
|
||||
freqFactor = sampleFreq / desiredFreq;
|
||||
}
|
||||
|
||||
@@ -1342,7 +1340,7 @@ float ADSR::value()
|
||||
{
|
||||
// Maybe not the best way of doing this, but it appears to be about right
|
||||
// Satisfies f(0) = sustain and f(releaseLength) = very small
|
||||
amplitude = ( sustain + 1e-3 ) * expf( -5.0 / releaseLength * releasePosition ) - 1e-3;
|
||||
amplitude = (sustain + 1e-3) * std::exp(-5.0f / releaseLength * releasePosition) - 1e-3;
|
||||
|
||||
// Don't have an infinite exponential decay
|
||||
if( amplitude <= 0 || releasePosition >= releaseLength )
|
||||
|
||||
@@ -82,7 +82,7 @@ void LOMMEffect::changeSampleRate()
|
||||
m_coeffPrecalc = -2.2f / (m_sampleRate * 0.001f);
|
||||
m_needsUpdate = true;
|
||||
|
||||
m_crestTimeConst = exp(-1.f / (0.2f * m_sampleRate));
|
||||
m_crestTimeConst = std::exp(-1.f / (0.2f * m_sampleRate));
|
||||
|
||||
m_lookBufLength = std::ceil((LOMM_MAX_LOOKAHEAD / 1000.f) * m_sampleRate) + 2;
|
||||
for (int i = 0; i < 2; ++i)
|
||||
@@ -171,7 +171,7 @@ Effect::ProcessStatus LOMMEffect::processImpl(SampleFrame* buf, const fpp_t fram
|
||||
float rel[3] = {relH, relM, relL};
|
||||
float relCoef[3] = {relCoefH, relCoefM, relCoefL};
|
||||
const float rmsTime = m_lommControls.m_rmsTimeModel.value();
|
||||
const float rmsTimeConst = (rmsTime == 0) ? 0 : exp(-1.f / (rmsTime * 0.001f * m_sampleRate));
|
||||
const float rmsTimeConst = (rmsTime == 0) ? 0 : std::exp(-1.f / (rmsTime * 0.001f * m_sampleRate));
|
||||
const float knee = m_lommControls.m_kneeModel.value() * 0.5f;
|
||||
const float range = m_lommControls.m_rangeModel.value();
|
||||
const float rangeAmp = dbfsToAmp(range);
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
|
||||
inline float msToCoeff(float ms)
|
||||
{
|
||||
return (ms == 0) ? 0 : exp(m_coeffPrecalc / ms);
|
||||
return (ms == 0) ? 0 : std::exp(m_coeffPrecalc / ms);
|
||||
}
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -109,20 +109,20 @@ Lb302Filter::Lb302Filter(Lb302FilterKnobState* p_fs) :
|
||||
|
||||
void Lb302Filter::recalc()
|
||||
{
|
||||
vcf_e1 = exp(6.109 + 1.5876*(fs->envmod) + 2.1553*(fs->cutoff) - 1.2*(1.0-(fs->reso)));
|
||||
vcf_e0 = exp(5.613 - 0.8*(fs->envmod) + 2.1553*(fs->cutoff) - 0.7696*(1.0-(fs->reso)));
|
||||
vcf_e1 = std::exp(6.109f + 1.5876f * fs->envmod + 2.1553f * fs->cutoff - 1.2f * (1.0f - fs->reso));
|
||||
vcf_e0 = std::exp(5.613f - 0.8f * fs->envmod + 2.1553f * fs->cutoff - 0.7696f * (1.0f - fs->reso));
|
||||
vcf_e0*=M_PI/Engine::audioEngine()->outputSampleRate();
|
||||
vcf_e1*=M_PI/Engine::audioEngine()->outputSampleRate();
|
||||
vcf_e1 -= vcf_e0;
|
||||
|
||||
vcf_rescoeff = exp(-1.20 + 3.455*(fs->reso));
|
||||
vcf_rescoeff = std::exp(-1.20f + 3.455f * fs->reso);
|
||||
};
|
||||
|
||||
|
||||
void Lb302Filter::envRecalc()
|
||||
{
|
||||
vcf_c0 *= fs->envdecay; // Filter Decay. vcf_decay is adjusted for Hz and ENVINC
|
||||
// vcf_rescoeff = exp(-1.20 + 3.455*(fs->reso)); moved above
|
||||
// vcf_rescoeff = std::exp(-1.20f + 3.455f * fs->reso); moved above
|
||||
};
|
||||
|
||||
|
||||
@@ -169,9 +169,9 @@ void Lb302FilterIIR2::envRecalc()
|
||||
Lb302Filter::envRecalc();
|
||||
|
||||
float w = vcf_e0 + vcf_c0; // e0 is adjusted for Hz and doesn't need ENVINC
|
||||
float k = exp(-w/vcf_rescoeff); // Does this mean c0 is inheritantly?
|
||||
float k = std::exp(-w / vcf_rescoeff); // Does this mean c0 is inheritantly?
|
||||
|
||||
vcf_a = 2.0*cos(2.0*w) * k;
|
||||
vcf_a = 2.0 * std::cos(2.0 * w) * k;
|
||||
vcf_b = -k*k;
|
||||
vcf_c = 1.0 - vcf_a - vcf_b;
|
||||
}
|
||||
@@ -241,7 +241,7 @@ void Lb302Filter3Pole::envRecalc()
|
||||
kp1 = kp+1.0;
|
||||
kp1h = 0.5*kp1;
|
||||
#ifdef LB_24_RES_TRICK
|
||||
k = exp(-w/vcf_rescoeff);
|
||||
k = std::exp(-w / vcf_rescoeff);
|
||||
kres = (((k))) * (((-2.7079*kp1 + 10.963)*kp1 - 14.934)*kp1 + 8.4974);
|
||||
#else
|
||||
kres = (((fs->reso))) * (((-2.7079*kp1 + 10.963)*kp1 - 14.934)*kp1 + 8.4974);
|
||||
@@ -415,7 +415,7 @@ void Lb302Synth::filterChanged()
|
||||
float d = 0.2 + (2.3*vcf_dec_knob.value());
|
||||
|
||||
d *= Engine::audioEngine()->outputSampleRate(); // d *= smpl rate
|
||||
fs.envdecay = pow(0.1, 1.0/d * ENVINC); // decay is 0.1 to the 1/d * ENVINC
|
||||
fs.envdecay = std::pow(0.1f, 1.0f / d * ENVINC); // decay is 0.1 to the 1/d * ENVINC
|
||||
// vcf_envdecay is now adjusted for both
|
||||
// sampling rate and ENVINC
|
||||
recalcFilter();
|
||||
@@ -563,7 +563,7 @@ int Lb302Synth::process(SampleFrame* outbuf, const std::size_t size)
|
||||
break;
|
||||
|
||||
case VcoShape::RoundSquare: // p0: width of round
|
||||
vco_k = (vco_c<0)?(sqrtf(1-(vco_c*vco_c*4))-0.5):-0.5;
|
||||
vco_k = (vco_c < 0.f) ? (std::sqrt(1.f - (vco_c * vco_c * 4.f)) - 0.5f) : -0.5f;
|
||||
break;
|
||||
|
||||
case VcoShape::Moog: // Maybe the fall should be exponential/sinsoidal instead of quadric.
|
||||
@@ -574,7 +574,7 @@ int Lb302Synth::process(SampleFrame* outbuf, const std::size_t size)
|
||||
}
|
||||
else if (vco_k>0.5) {
|
||||
float w = 2.0 * (vco_k - 0.5) - 1.0;
|
||||
vco_k = 0.5 - sqrtf(1.0-(w*w));
|
||||
vco_k = 0.5 - std::sqrt(1.0 - (w * w));
|
||||
}
|
||||
vco_k *= 2.0; // MOOG wave gets filtered away
|
||||
break;
|
||||
|
||||
@@ -120,7 +120,7 @@ void MonstroSynth::renderOutput( fpp_t _frames, SampleFrame* _buf )
|
||||
if( mod##_e2 != 0.0f ) modtmp += m_env[1][f] * mod##_e2; \
|
||||
if( mod##_l1 != 0.0f ) modtmp += m_lfo[0][f] * mod##_l1; \
|
||||
if( mod##_l2 != 0.0f ) modtmp += m_lfo[1][f] * mod##_l2; \
|
||||
car = qBound( MIN_FREQ, car * powf( 2.0f, modtmp ), MAX_FREQ );
|
||||
(car) = qBound( MIN_FREQ, (car) * std::exp2(modtmp), MAX_FREQ);
|
||||
|
||||
#define modulateabs( car, mod ) \
|
||||
if( mod##_e1 != 0.0f ) car += m_env[0][f] * mod##_e1; \
|
||||
@@ -1361,25 +1361,25 @@ void MonstroInstrument::updateVolume3()
|
||||
|
||||
void MonstroInstrument::updateFreq1()
|
||||
{
|
||||
m_osc1l_freq = powf( 2.0f, m_osc1Crs.value() / 12.0f ) *
|
||||
powf( 2.0f, m_osc1Ftl.value() / 1200.0f );
|
||||
m_osc1r_freq = powf( 2.0f, m_osc1Crs.value() / 12.0f ) *
|
||||
powf( 2.0f, m_osc1Ftr.value() / 1200.0f );
|
||||
m_osc1l_freq = std::exp2(m_osc1Crs.value() / 12.0f)
|
||||
* std::exp2(m_osc1Ftl.value() / 1200.0f);
|
||||
m_osc1r_freq = std::exp2(m_osc1Crs.value() / 12.0f)
|
||||
* std::exp2(m_osc1Ftr.value() / 1200.0f);
|
||||
}
|
||||
|
||||
|
||||
void MonstroInstrument::updateFreq2()
|
||||
{
|
||||
m_osc2l_freq = powf( 2.0f, m_osc2Crs.value() / 12.0f ) *
|
||||
powf( 2.0f, m_osc2Ftl.value() / 1200.0f );
|
||||
m_osc2r_freq = powf( 2.0f, m_osc2Crs.value() / 12.0f ) *
|
||||
powf( 2.0f, m_osc2Ftr.value() / 1200.0f );
|
||||
m_osc2l_freq = std::exp2(m_osc2Crs.value() / 12.0f)
|
||||
* std::exp2(m_osc2Ftl.value() / 1200.0f);
|
||||
m_osc2r_freq = std::exp2(m_osc2Crs.value() / 12.0f)
|
||||
* std::exp2(m_osc2Ftr.value() / 1200.0f);
|
||||
}
|
||||
|
||||
|
||||
void MonstroInstrument::updateFreq3()
|
||||
{
|
||||
m_osc3_freq = powf( 2.0f, m_osc3Crs.value() / 12.0f );
|
||||
m_osc3_freq = std::exp2(m_osc3Crs.value() / 12.0f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -700,19 +700,19 @@ gui::PluginView* NesInstrument::instantiateView( QWidget * parent )
|
||||
|
||||
void NesInstrument::updateFreq1()
|
||||
{
|
||||
m_freq1 = powf( 2, m_ch1Crs.value() / 12.0f );
|
||||
m_freq1 = std::exp2(m_ch1Crs.value() / 12.0f);
|
||||
}
|
||||
|
||||
|
||||
void NesInstrument::updateFreq2()
|
||||
{
|
||||
m_freq2 = powf( 2, m_ch2Crs.value() / 12.0f );
|
||||
m_freq2 = std::exp2(m_ch2Crs.value() / 12.0f);
|
||||
}
|
||||
|
||||
|
||||
void NesInstrument::updateFreq3()
|
||||
{
|
||||
m_freq3 = powf( 2, m_ch3Crs.value() / 12.0f );
|
||||
m_freq3 = std::exp2(m_ch3Crs.value() / 12.0f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -497,7 +497,7 @@ void OpulenzInstrument::loadPatch(const unsigned char inst[14]) {
|
||||
|
||||
void OpulenzInstrument::tuneEqual(int center, float Hz) {
|
||||
for(int n=0; n<128; ++n) {
|
||||
float tmp = Hz * pow(2.0, (n - center) * (1.0 / 12.0) + pitchbend * (1.0 / 1200.0));
|
||||
float tmp = Hz * std::exp2((n - center) / 12.0f + pitchbend / 1200.0f);
|
||||
fnums[n] = Hz2fnum( tmp );
|
||||
}
|
||||
}
|
||||
@@ -505,7 +505,7 @@ void OpulenzInstrument::tuneEqual(int center, float Hz) {
|
||||
// Find suitable F number in lowest possible block
|
||||
int OpulenzInstrument::Hz2fnum(float Hz) {
|
||||
for(int block=0; block<8; ++block) {
|
||||
unsigned int fnum = Hz * pow( 2.0, 20.0 - (double)block ) * ( 1.0 / 49716.0 );
|
||||
auto fnum = static_cast<unsigned>(Hz * std::exp2(20.0f - static_cast<float>(block)) / 49716.0f);
|
||||
if(fnum<1023) {
|
||||
return fnum + (block << 10);
|
||||
}
|
||||
|
||||
@@ -342,8 +342,7 @@ void OrganicInstrument::deleteNotePluginData( NotePlayHandle * _n )
|
||||
float inline OrganicInstrument::waveshape(float in, float amount)
|
||||
{
|
||||
float k = 2.0f * amount / ( 1.0f - amount );
|
||||
|
||||
return( ( 1.0f + k ) * in / ( 1.0f + k * fabs( in ) ) );
|
||||
return (1.0f + k) * in / (1.0f + k * std::abs(in));
|
||||
}
|
||||
|
||||
|
||||
@@ -603,12 +602,11 @@ void OscillatorObject::updateVolume()
|
||||
|
||||
void OscillatorObject::updateDetuning()
|
||||
{
|
||||
m_detuningLeft = powf( 2.0f, OrganicInstrument::s_harmonics[ static_cast<int>( m_harmModel.value() ) ]
|
||||
+ (float)m_detuneModel.value() * CENT ) /
|
||||
Engine::audioEngine()->outputSampleRate();
|
||||
m_detuningRight = powf( 2.0f, OrganicInstrument::s_harmonics[ static_cast<int>( m_harmModel.value() ) ]
|
||||
- (float)m_detuneModel.value() * CENT ) /
|
||||
Engine::audioEngine()->outputSampleRate();
|
||||
const auto harmonic = OrganicInstrument::s_harmonics[static_cast<int>(m_harmModel.value())];
|
||||
const auto sr = Engine::audioEngine()->outputSampleRate();
|
||||
|
||||
m_detuningLeft = std::exp2(harmonic + m_detuneModel.value() * CENT) / sr;
|
||||
m_detuningRight = std::exp2(harmonic - m_detuneModel.value() * CENT) / sr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
#include "ReverbSC.h"
|
||||
|
||||
#include "embed.h"
|
||||
#include "lmms_math.h"
|
||||
#include "plugin_export.h"
|
||||
|
||||
#define DB2LIN(X) pow(10, X / 20.0f);
|
||||
|
||||
namespace lmms
|
||||
{
|
||||
|
||||
@@ -92,10 +91,10 @@ Effect::ProcessStatus ReverbSCEffect::processImpl(SampleFrame* buf, const fpp_t
|
||||
{
|
||||
auto s = std::array{buf[f][0], buf[f][1]};
|
||||
|
||||
const auto inGain
|
||||
= (SPFLOAT)DB2LIN((inGainBuf ? inGainBuf->values()[f] : m_reverbSCControls.m_inputGainModel.value()));
|
||||
const auto outGain
|
||||
= (SPFLOAT)DB2LIN((outGainBuf ? outGainBuf->values()[f] : m_reverbSCControls.m_outputGainModel.value()));
|
||||
const auto inGain = static_cast<SPFLOAT>(fastPow10f(
|
||||
(inGainBuf ? inGainBuf->values()[f] : m_reverbSCControls.m_inputGainModel.value()) / 20.f));
|
||||
const auto outGain = static_cast<SPFLOAT>(fastPow10f(
|
||||
(outGainBuf ? outGainBuf->values()[f] : m_reverbSCControls.m_outputGainModel.value()) / 20.f));
|
||||
|
||||
s[0] *= inGain;
|
||||
s[1] *= inGain;
|
||||
|
||||
@@ -556,7 +556,7 @@ void Sf2Instrument::updateTuning()
|
||||
if (instrumentTrack()->microtuner()->enabledModel()->value())
|
||||
{
|
||||
auto centArray = std::array<double, 128>{};
|
||||
double lowestHz = pow(2., -69. / 12.) * 440.;// Frequency of MIDI note 0, which is approximately 8.175798916 Hz
|
||||
double lowestHz = std::exp2(-69. / 12.) * 440.; // Frequency of MIDI note 0, which is approximately 8.175798916 Hz
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
// Get desired Hz of note
|
||||
|
||||
@@ -97,33 +97,34 @@ void SfxrSynth::resetSample( bool restart )
|
||||
fperiod=100.0/(s->m_startFreqModel.value()*s->m_startFreqModel.value()+0.001);
|
||||
period=(int)fperiod;
|
||||
fmaxperiod=100.0/(s->m_minFreqModel.value()*s->m_minFreqModel.value()+0.001);
|
||||
fslide=1.0-pow((double)s->m_slideModel.value(), 3.0)*0.01;
|
||||
fdslide=-pow((double)s->m_dSlideModel.value(), 3.0)*0.000001;
|
||||
const auto sv = static_cast<double>(s->m_slideModel.value());
|
||||
const auto dsv = static_cast<double>(s->m_dSlideModel.value());
|
||||
fslide = 1.0 - sv * sv * sv * 0.01;
|
||||
fdslide = -dsv * dsv * dsv * 0.000001;
|
||||
square_duty=0.5f-s->m_sqrDutyModel.value()*0.5f;
|
||||
square_slide=-s->m_sqrSweepModel.value()*0.00005f;
|
||||
if(s->m_changeAmtModel.value()>=0.0f)
|
||||
arp_mod=1.0-pow((double)s->m_changeAmtModel.value(), 2.0)*0.9;
|
||||
else
|
||||
arp_mod=1.0+pow((double)s->m_changeAmtModel.value(), 2.0)*10.0;
|
||||
arp_time=0;
|
||||
arp_limit=(int)(pow(1.0f-s->m_changeSpeedModel.value(), 2.0f)*20000+32);
|
||||
if(s->m_changeSpeedModel.value()==1.0f)
|
||||
arp_limit=0;
|
||||
const auto cha = static_cast<double>(s->m_changeAmtModel.value());
|
||||
arp_mod = (cha >= 0.0)
|
||||
? 1.0 - cha * cha * 0.9
|
||||
: 1.0 + cha * cha * 10.0;
|
||||
arp_time = 0;
|
||||
const auto chs = 1.f - s->m_changeSpeedModel.value();
|
||||
arp_limit = (chs == 0.f) ? 0 : static_cast<int>(chs * chs * 20000 + 32);
|
||||
if(!restart)
|
||||
{
|
||||
// reset filter
|
||||
fltp=0.0f;
|
||||
fltdp=0.0f;
|
||||
fltw=pow(s->m_lpFilCutModel.value(), 3.0f)*0.1f;
|
||||
fltw = std::pow(s->m_lpFilCutModel.value(), 3.f) * 0.1f;
|
||||
fltw_d=1.0f+s->m_lpFilCutSweepModel.value()*0.0001f;
|
||||
fltdmp=5.0f/(1.0f+pow(s->m_lpFilResoModel.value(), 2.0f)*20.0f)*(0.01f+fltw);
|
||||
fltdmp = 5.0f / (1.0f + std::pow(s->m_lpFilResoModel.value(), 2.0f) * 20.0f) * (0.01f + fltw);
|
||||
if(fltdmp>0.8f) fltdmp=0.8f;
|
||||
fltphp=0.0f;
|
||||
flthp=pow(s->m_hpFilCutModel.value(), 2.0f)*0.1f;
|
||||
flthp = std::pow(s->m_hpFilCutModel.value(), 2.f) * 0.1f;
|
||||
flthp_d=1.0+s->m_hpFilCutSweepModel.value()*0.0003f;
|
||||
// reset vibrato
|
||||
vib_phase=0.0f;
|
||||
vib_speed=pow(s->m_vibSpeedModel.value(), 2.0f)*0.01f;
|
||||
vib_speed = std::pow(s->m_vibSpeedModel.value(), 2.f) * 0.01f;
|
||||
vib_amp=s->m_vibDepthModel.value()*0.5f;
|
||||
// reset envelope
|
||||
env_vol=0.0f;
|
||||
@@ -134,9 +135,9 @@ void SfxrSynth::resetSample( bool restart )
|
||||
env_length[1]=(int)(s->m_holdModel.value()*s->m_holdModel.value()*99999.0f)+1;
|
||||
env_length[2]=(int)(s->m_decModel.value()*s->m_decModel.value()*99999.0f)+1;
|
||||
|
||||
fphase=pow(s->m_phaserOffsetModel.value(), 2.0f)*1020.0f;
|
||||
fphase = std::pow(s->m_phaserOffsetModel.value(), 2.f) * 1020.f;
|
||||
if(s->m_phaserOffsetModel.value()<0.0f) fphase=-fphase;
|
||||
fdphase=pow(s->m_phaserSweepModel.value(), 2.0f)*1.0f;
|
||||
fdphase = std::pow(s->m_phaserSweepModel.value(), 2.f) * 1.f;
|
||||
if(s->m_phaserSweepModel.value()<0.0f) fdphase=-fdphase;
|
||||
iphase=abs((int)fphase);
|
||||
ipp=0;
|
||||
@@ -148,10 +149,10 @@ void SfxrSynth::resetSample( bool restart )
|
||||
}
|
||||
|
||||
rep_time=0;
|
||||
rep_limit=(int)(pow(1.0f-s->m_repeatSpeedModel.value(), 2.0f)*20000+32);
|
||||
rep_limit = static_cast<int>(std::pow(1.0f - s->m_repeatSpeedModel.value(), 2.0f) * 20000 + 32);
|
||||
if(s->m_repeatSpeedModel.value()==0.0f)
|
||||
rep_limit=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +196,7 @@ void SfxrSynth::update( SampleFrame* buffer, const int32_t frameNum )
|
||||
if(vib_amp>0.0f)
|
||||
{
|
||||
vib_phase+=vib_speed;
|
||||
rfperiod=fperiod*(1.0+sin(vib_phase)*vib_amp);
|
||||
rfperiod = fperiod * (1.0 + std::sin(vib_phase) * vib_amp);
|
||||
}
|
||||
period=(int)rfperiod;
|
||||
if(period<8) period=8;
|
||||
@@ -214,7 +215,7 @@ void SfxrSynth::update( SampleFrame* buffer, const int32_t frameNum )
|
||||
if(env_stage==0)
|
||||
env_vol=(float)env_time/env_length[0];
|
||||
if(env_stage==1)
|
||||
env_vol=1.0f+pow(1.0f-(float)env_time/env_length[1], 1.0f)*2.0f*s->m_susModel.value();
|
||||
{ env_vol = 1.0f + (1.0f - static_cast<float>(env_time) / env_length[1]) * 2.0f * s->m_susModel.value(); }
|
||||
if(env_stage==2)
|
||||
env_vol=1.0f-(float)env_time/env_length[2];
|
||||
|
||||
@@ -1000,13 +1001,13 @@ void SfxrInstrumentView::randomize()
|
||||
{
|
||||
auto s = castModel<SfxrInstrument>();
|
||||
|
||||
s->m_startFreqModel.setValue( pow(frnd(2.0f)-1.0f, 2.0f) );
|
||||
s->m_startFreqModel.setValue(std::pow(frnd(2.0f) - 1.0f, 2.0f));
|
||||
if(rnd(1))
|
||||
{
|
||||
s->m_startFreqModel.setValue( pow(frnd(2.0f)-1.0f, 3.0f)+0.5f );
|
||||
s->m_startFreqModel.setValue(std::pow(frnd(2.0f) - 1.0f, 3.0f) + 0.5f);
|
||||
}
|
||||
s->m_minFreqModel.setValue( 0.0f );
|
||||
s->m_slideModel.setValue( pow(frnd(2.0f)-1.0f, 5.0f) );
|
||||
s->m_slideModel.setValue(std::pow(frnd(2.0f) - 1.0f, 5.0f));
|
||||
if( s->m_startFreqModel.value()>0.7f && s->m_slideModel.value()>0.2f )
|
||||
{
|
||||
s->m_slideModel.setValue( -s->m_slideModel.value() );
|
||||
@@ -1015,19 +1016,19 @@ void SfxrInstrumentView::randomize()
|
||||
{
|
||||
s->m_slideModel.setValue( -s->m_slideModel.value() );
|
||||
}
|
||||
s->m_dSlideModel.setValue( pow(frnd(2.0f)-1.0f, 3.0f) );
|
||||
s->m_dSlideModel.setValue(std::pow(frnd(2.0f) - 1.0f, 3.0f));
|
||||
|
||||
s->m_sqrDutyModel.setValue( frnd(2.0f)-1.0f );
|
||||
s->m_sqrSweepModel.setValue( pow(frnd(2.0f)-1.0f, 3.0f) );
|
||||
s->m_sqrSweepModel.setValue(std::pow(frnd(2.0f) - 1.0f, 3.0f));
|
||||
|
||||
s->m_vibDepthModel.setValue( pow(frnd(2.0f)-1.0f, 3.0f) );
|
||||
s->m_vibDepthModel.setValue(std::pow(frnd(2.0f) - 1.0f, 3.0f));
|
||||
s->m_vibSpeedModel.setValue( frnd(2.0f)-1.0f );
|
||||
//s->m_vibDelayModel.setValue( frnd(2.0f)-1.0f );
|
||||
|
||||
s->m_attModel.setValue( pow(frnd(2.0f)-1.0f, 3.0f) );
|
||||
s->m_holdModel.setValue( pow(frnd(2.0f)-1.0f, 2.0f) );
|
||||
s->m_attModel.setValue(std::pow(frnd(2.0f) - 1.0f, 3.0f));
|
||||
s->m_holdModel.setValue(std::pow(frnd(2.0f) - 1.0f, 2.0f));
|
||||
s->m_decModel.setValue( frnd(2.0f)-1.0f );
|
||||
s->m_susModel.setValue( pow(frnd(0.8f), 2.0f) );
|
||||
s->m_susModel.setValue(std::pow(frnd(0.8f), 2.0f));
|
||||
if(s->m_attModel.value()+s->m_holdModel.value()+s->m_decModel.value()<0.2f)
|
||||
{
|
||||
s->m_holdModel.setValue( s->m_holdModel.value()+0.2f+frnd(0.3f) );
|
||||
@@ -1035,17 +1036,17 @@ void SfxrInstrumentView::randomize()
|
||||
}
|
||||
|
||||
s->m_lpFilResoModel.setValue( frnd(2.0f)-1.0f );
|
||||
s->m_lpFilCutModel.setValue( 1.0f-pow(frnd(1.0f), 3.0f) );
|
||||
s->m_lpFilCutSweepModel.setValue( pow(frnd(2.0f)-1.0f, 3.0f) );
|
||||
s->m_lpFilCutModel.setValue(1.0f - std::pow(frnd(1.0f), 3.0f));
|
||||
s->m_lpFilCutSweepModel.setValue(std::pow(frnd(2.0f) - 1.0f, 3.0f));
|
||||
if(s->m_lpFilCutModel.value()<0.1f && s->m_lpFilCutSweepModel.value()<-0.05f)
|
||||
{
|
||||
s->m_lpFilCutSweepModel.setValue( -s->m_lpFilCutSweepModel.value() );
|
||||
}
|
||||
s->m_hpFilCutModel.setValue( pow(frnd(1.0f), 5.0f) );
|
||||
s->m_hpFilCutSweepModel.setValue( pow(frnd(2.0f)-1.0f, 5.0f) );
|
||||
s->m_hpFilCutModel.setValue(std::pow(frnd(1.0f), 5.0f));
|
||||
s->m_hpFilCutSweepModel.setValue(std::pow(frnd(2.0f) - 1.0f, 5.0f));
|
||||
|
||||
s->m_phaserOffsetModel.setValue( pow(frnd(2.0f)-1.0f, 3.0f) );
|
||||
s->m_phaserSweepModel.setValue( pow(frnd(2.0f)-1.0f, 3.0f) );
|
||||
s->m_phaserOffsetModel.setValue(std::pow(frnd(2.0f) - 1.0f, 3.0f));
|
||||
s->m_phaserSweepModel.setValue(std::pow(frnd(2.0f) - 1.0f, 3.0f));
|
||||
|
||||
s->m_repeatSpeedModel.setValue( frnd(2.0f)-1.0f );
|
||||
|
||||
|
||||
@@ -341,9 +341,9 @@ void SidInstrument::playNote( NotePlayHandle * _n,
|
||||
base = i*7;
|
||||
// freq ( Fn = Fout / Fclk * 16777216 ) + coarse detuning
|
||||
freq = _n->frequency();
|
||||
note = 69.0 + 12.0 * log( freq / 440.0 ) / log( 2 );
|
||||
note = 69.0 + 12.0 * std::log2(freq / 440.0);
|
||||
note += m_voice[i]->m_coarseModel.value();
|
||||
freq = 440.0 * pow( 2.0, (note-69.0)/12.0 );
|
||||
freq = 440.0 * std::exp2((note - 69.0) / 12.0);
|
||||
data16 = int( freq / float(clockrate) * 16777216.0 );
|
||||
|
||||
sidreg[base+0] = data16&0x00FF;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "SaProcessor.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "lmms_math.h"
|
||||
#ifdef SA_DEBUG
|
||||
#include <chrono>
|
||||
#endif
|
||||
@@ -331,15 +332,15 @@ QRgb SaProcessor::makePixel(float left, float right) const
|
||||
const float gamma_correction = m_controls->m_waterfallGammaModel.value();
|
||||
if (m_controls->m_stereoModel.value())
|
||||
{
|
||||
float ampL = pow(left, gamma_correction);
|
||||
float ampR = pow(right, gamma_correction);
|
||||
float ampL = std::pow(left, gamma_correction);
|
||||
float ampR = std::pow(right, gamma_correction);
|
||||
return qRgb(m_controls->m_colorL.red() * ampL + m_controls->m_colorR.red() * ampR,
|
||||
m_controls->m_colorL.green() * ampL + m_controls->m_colorR.green() * ampR,
|
||||
m_controls->m_colorL.blue() * ampL + m_controls->m_colorR.blue() * ampR);
|
||||
}
|
||||
else
|
||||
{
|
||||
float ampL = pow(left, gamma_correction);
|
||||
float ampL = std::pow(left, gamma_correction);
|
||||
// make mono color brighter to compensate for the fact it is not summed
|
||||
return qRgb(m_controls->m_colorMonoW.red() * ampL,
|
||||
m_controls->m_colorMonoW.green() * ampL,
|
||||
@@ -576,9 +577,9 @@ float SaProcessor::freqToXPixel(float freq, unsigned int width) const
|
||||
if (m_controls->m_logXModel.value())
|
||||
{
|
||||
if (freq <= 1) {return 0;}
|
||||
float min = log10(getFreqRangeMin());
|
||||
float range = log10(getFreqRangeMax()) - min;
|
||||
return (log10(freq) - min) / range * width;
|
||||
float min = std::log10(getFreqRangeMin());
|
||||
float range = std::log10(getFreqRangeMax()) - min;
|
||||
return (std::log10(freq) - min) / range * width;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -594,10 +595,10 @@ float SaProcessor::xPixelToFreq(float x, unsigned int width) const
|
||||
{
|
||||
if (m_controls->m_logXModel.value())
|
||||
{
|
||||
float min = log10(getFreqRangeMin());
|
||||
float max = log10(getFreqRangeMax());
|
||||
float min = std::log10(getFreqRangeMin());
|
||||
float max = std::log10(getFreqRangeMax());
|
||||
float range = max - min;
|
||||
return pow(10, min + x / width * range);
|
||||
return fastPow10f(min + x / width * range);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -662,8 +663,8 @@ float SaProcessor::ampToYPixel(float amplitude, unsigned int height) const
|
||||
else
|
||||
{
|
||||
// linear scale: convert returned ranges from dB to linear scale
|
||||
float max = pow(10, getAmpRangeMax() / 10);
|
||||
float range = pow(10, getAmpRangeMin() / 10) - max;
|
||||
float max = fastPow10f(getAmpRangeMax() / 10);
|
||||
float range = fastPow10f(getAmpRangeMin() / 10) - max;
|
||||
return (amplitude - max) / range * height;
|
||||
}
|
||||
}
|
||||
@@ -683,8 +684,8 @@ float SaProcessor::yPixelToAmp(float y, unsigned int height) const
|
||||
else
|
||||
{
|
||||
// linear scale: convert returned ranges from dB to linear scale
|
||||
float max = pow(10, getAmpRangeMax() / 10);
|
||||
float range = pow(10, getAmpRangeMin() / 10) - max;
|
||||
float max = fastPow10f(getAmpRangeMax() / 10);
|
||||
float range = fastPow10f(getAmpRangeMin() / 10) - max;
|
||||
return max + range * (y / height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "MainWindow.h"
|
||||
#include "SaControls.h"
|
||||
#include "SaProcessor.h"
|
||||
#include "lmms_math.h"
|
||||
|
||||
#ifdef SA_DEBUG
|
||||
#include <chrono>
|
||||
@@ -668,7 +669,7 @@ std::vector<std::pair<int, std::string>> SaSpectrumView::makeLogFreqTics(int low
|
||||
}
|
||||
}
|
||||
// also insert denser series if high and low values are close
|
||||
if ((log10(high) - log10(low) < 2) && (i * b[j] >= low && i * b[j] <= high))
|
||||
if ((std::log10(high) - std::log10(low) < 2) && (i * b[j] >= low && i * b[j] <= high))
|
||||
{
|
||||
if (i * b[j] < 1500)
|
||||
{
|
||||
@@ -729,11 +730,11 @@ std::vector<std::pair<float, std::string>> SaSpectrumView::makeLogAmpTics(int lo
|
||||
// to the sizeHint() (denser scale for bigger window).
|
||||
if ((high - low) < 20 * ((float)height() / sizeHint().height()))
|
||||
{
|
||||
increment = pow(10, 0.3); // 3 dB steps when really zoomed in
|
||||
increment = fastPow10f(0.3f); // 3 dB steps when really zoomed in
|
||||
}
|
||||
else if (high - low < 45 * ((float)height() / sizeHint().height()))
|
||||
{
|
||||
increment = pow(10, 0.6); // 6 dB steps when sufficiently zoomed in
|
||||
increment = fastPow10f(0.6f); // 6 dB steps when sufficiently zoomed in
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -742,11 +743,11 @@ std::vector<std::pair<float, std::string>> SaSpectrumView::makeLogAmpTics(int lo
|
||||
|
||||
// Generate n dB increments, start checking at -90 dB. Limits are tweaked
|
||||
// just a little bit to make sure float comparisons do not miss edges.
|
||||
for (float i = 0.000000001f; 10 * log10(i) <= (high + 0.001); i *= increment)
|
||||
for (float i = 0.000000001f; 10 * std::log10(i) <= (high + 0.001); i *= increment)
|
||||
{
|
||||
if (10 * log10(i) >= (low - 0.001))
|
||||
if (10 * std::log10(i) >= (low - 0.001))
|
||||
{
|
||||
result.emplace_back(i, std::to_string((int)std::round(10 * log10(i))));
|
||||
result.emplace_back(i, std::to_string((int)std::round(10 * std::log10(i))));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -766,8 +767,8 @@ std::vector<std::pair<float, std::string>> SaSpectrumView::makeLinearAmpTics(int
|
||||
float split = (float)height() / sizeHint().height() >= 1.5 ? 10.0 : 5.0;
|
||||
|
||||
// convert limits to linear scale
|
||||
float lin_low = pow(10, low / 10.0);
|
||||
float lin_high = pow(10, high / 10.0);
|
||||
float lin_low = fastPow10f(low / 10.0);
|
||||
float lin_high = fastPow10f(high / 10.0);
|
||||
|
||||
// Linear scale will vary widely, so instead of trying to craft extra nice
|
||||
// multiples, just generate a few evenly spaced increments across the range,
|
||||
|
||||
@@ -175,9 +175,8 @@ void OscillatorObject::updateVolume()
|
||||
|
||||
void OscillatorObject::updateDetuningLeft()
|
||||
{
|
||||
m_detuningLeft = powf( 2.0f, ( (float)m_coarseModel.value() * 100.0f
|
||||
+ (float)m_fineLeftModel.value() ) / 1200.0f )
|
||||
/ Engine::audioEngine()->outputSampleRate();
|
||||
m_detuningLeft = std::exp2((m_coarseModel.value() * 100.0f + m_fineLeftModel.value()) / 1200.0f)
|
||||
/ Engine::audioEngine()->outputSampleRate();
|
||||
}
|
||||
|
||||
|
||||
@@ -185,9 +184,8 @@ void OscillatorObject::updateDetuningLeft()
|
||||
|
||||
void OscillatorObject::updateDetuningRight()
|
||||
{
|
||||
m_detuningRight = powf( 2.0f, ( (float)m_coarseModel.value() * 100.0f
|
||||
+ (float)m_fineRightModel.value() ) / 1200.0f )
|
||||
/ Engine::audioEngine()->outputSampleRate();
|
||||
m_detuningRight = std::exp2((m_coarseModel.value() * 100.0f + m_fineRightModel.value()) / 1200.0f)
|
||||
/ Engine::audioEngine()->outputSampleRate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -132,9 +132,9 @@ void WatsynObject::renderOutput( fpp_t _frames )
|
||||
// if phase mod, add to phases
|
||||
if( m_amod == MOD_PM )
|
||||
{
|
||||
A1_lphase = fmodf( A1_lphase + A2_L * PMOD_AMT, WAVELEN );
|
||||
A1_lphase = std::fmod(A1_lphase + A2_L * PMOD_AMT, WAVELEN);
|
||||
if( A1_lphase < 0 ) A1_lphase += WAVELEN;
|
||||
A1_rphase = fmodf( A1_rphase + A2_R * PMOD_AMT, WAVELEN );
|
||||
A1_rphase = std::fmod(A1_rphase + A2_R * PMOD_AMT, WAVELEN);
|
||||
if( A1_rphase < 0 ) A1_rphase += WAVELEN;
|
||||
}
|
||||
// A1
|
||||
@@ -166,9 +166,9 @@ void WatsynObject::renderOutput( fpp_t _frames )
|
||||
// if phase mod, add to phases
|
||||
if( m_bmod == MOD_PM )
|
||||
{
|
||||
B1_lphase = fmodf( B1_lphase + B2_L * PMOD_AMT, WAVELEN );
|
||||
B1_lphase = std::fmod(B1_lphase + B2_L * PMOD_AMT, WAVELEN);
|
||||
if( B1_lphase < 0 ) B1_lphase += WAVELEN;
|
||||
B1_rphase = fmodf( B1_rphase + B2_R * PMOD_AMT, WAVELEN );
|
||||
B1_rphase = std::fmod(B1_rphase + B2_R * PMOD_AMT, WAVELEN);
|
||||
if( B1_rphase < 0 ) B1_rphase += WAVELEN;
|
||||
}
|
||||
// B1
|
||||
@@ -222,9 +222,9 @@ void WatsynObject::renderOutput( fpp_t _frames )
|
||||
for( int i = 0; i < NUM_OSCS; i++ )
|
||||
{
|
||||
m_lphase[i] += ( static_cast<float>( WAVELEN ) / ( m_samplerate / ( m_nph->frequency() * m_parent->m_lfreq[i] ) ) );
|
||||
m_lphase[i] = fmodf( m_lphase[i], WAVELEN );
|
||||
m_lphase[i] = std::fmod(m_lphase[i], WAVELEN);
|
||||
m_rphase[i] += ( static_cast<float>( WAVELEN ) / ( m_samplerate / ( m_nph->frequency() * m_parent->m_rfreq[i] ) ) );
|
||||
m_rphase[i] = fmodf( m_rphase[i], WAVELEN );
|
||||
m_rphase[i] = std::fmod(m_rphase[i], WAVELEN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,32 +596,32 @@ void WatsynInstrument::updateVolumes()
|
||||
void WatsynInstrument::updateFreqA1()
|
||||
{
|
||||
// calculate frequencies
|
||||
m_lfreq[A1_OSC] = ( a1_mult.value() / 8 ) * powf( 2, a1_ltune.value() / 1200 );
|
||||
m_rfreq[A1_OSC] = ( a1_mult.value() / 8 ) * powf( 2, a1_rtune.value() / 1200 );
|
||||
m_lfreq[A1_OSC] = (a1_mult.value() / 8) * std::exp2(a1_ltune.value() / 1200);
|
||||
m_rfreq[A1_OSC] = (a1_mult.value() / 8) * std::exp2(a1_rtune.value() / 1200);
|
||||
}
|
||||
|
||||
|
||||
void WatsynInstrument::updateFreqA2()
|
||||
{
|
||||
// calculate frequencies
|
||||
m_lfreq[A2_OSC] = ( a2_mult.value() / 8 ) * powf( 2, a2_ltune.value() / 1200 );
|
||||
m_rfreq[A2_OSC] = ( a2_mult.value() / 8 ) * powf( 2, a2_rtune.value() / 1200 );
|
||||
m_lfreq[A2_OSC] = (a2_mult.value() / 8) * std::exp2(a2_ltune.value() / 1200);
|
||||
m_rfreq[A2_OSC] = (a2_mult.value() / 8) * std::exp2(a2_rtune.value() / 1200);
|
||||
}
|
||||
|
||||
|
||||
void WatsynInstrument::updateFreqB1()
|
||||
{
|
||||
// calculate frequencies
|
||||
m_lfreq[B1_OSC] = ( b1_mult.value() / 8 ) * powf( 2, b1_ltune.value() / 1200 );
|
||||
m_rfreq[B1_OSC] = ( b1_mult.value() / 8 ) * powf( 2, b1_rtune.value() / 1200 );
|
||||
m_lfreq[B1_OSC] = (b1_mult.value() / 8) * std::exp2(b1_ltune.value() / 1200);
|
||||
m_rfreq[B1_OSC] = (b1_mult.value() / 8) * std::exp2(b1_rtune.value() / 1200);
|
||||
}
|
||||
|
||||
|
||||
void WatsynInstrument::updateFreqB2()
|
||||
{
|
||||
// calculate frequencies
|
||||
m_lfreq[B2_OSC] = ( b2_mult.value() / 8 ) * powf( 2, b2_ltune.value() / 1200 );
|
||||
m_rfreq[B2_OSC] = ( b2_mult.value() / 8 ) * powf( 2, b2_rtune.value() / 1200 );
|
||||
m_lfreq[B2_OSC] = (b2_mult.value() / 8) * std::exp2(b2_ltune.value() / 1200);
|
||||
m_rfreq[B2_OSC] = (b2_mult.value() / 8) * std::exp2(b2_rtune.value() / 1200);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -511,7 +511,7 @@ struct harmonic_cent
|
||||
{
|
||||
static inline float process(float x)
|
||||
{
|
||||
return powf(2, x / 1200);
|
||||
return std::exp2(x / 1200);
|
||||
}
|
||||
};
|
||||
static freefunc1<float,harmonic_cent,true> harmonic_cent_func;
|
||||
@@ -519,7 +519,7 @@ struct harmonic_semitone
|
||||
{
|
||||
static inline float process(float x)
|
||||
{
|
||||
return powf(2, x / 12);
|
||||
return std::exp2(x / 12);
|
||||
}
|
||||
};
|
||||
static freefunc1<float,harmonic_semitone,true> harmonic_semitone_func;
|
||||
|
||||
Reference in New Issue
Block a user