Cleanup lmms_math.h (#7382)
* simplified fraction and absfraction functions * removed unused fastSqrt() and fastPow() functions * unused absMin() and absMax() * move roundAt to math header * Code review from saker Co-authored-by: saker <sakertooth@gmail.com> * use std::trunc() * fixup after fixing merge conflicts * remove unused fastFma and fastFmal functions. * remove lmms_basics include, not needed * use signedPowf from lmms_math in NES * removed fastRand function, unused * remove unused sinc function * cleanup signedPowf * code review * further simplify random number math * removed static from lmms_math file --------- Co-authored-by: saker <sakertooth@gmail.com>
This commit is contained in:
@@ -31,7 +31,7 @@ namespace lmms
|
||||
|
||||
Noise::Noise()
|
||||
{
|
||||
inv_randmax = 1.0/FAST_RAND_MAX; /* for range of 0 - 1.0 */
|
||||
inv_randmax = FAST_RAND_RATIO; /* for range of 0 - 1.0 */
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ Noise::Noise()
|
||||
|
||||
float Noise::tick()
|
||||
{
|
||||
return (float) ((2.0 * fast_rand() * inv_randmax) - 1.0);
|
||||
return fastRandf(2.0f) - 1.0f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -157,17 +157,17 @@ bool GranularPitchShifterEffect::processAudioBuffer(SampleFrame* buf, const fpp_
|
||||
if (++m_timeSinceLastGrain >= m_nextWaitRandomization * waitMult)
|
||||
{
|
||||
m_timeSinceLastGrain = 0;
|
||||
double randThing = (fast_rand()/static_cast<double>(FAST_RAND_MAX) * 2. - 1.);
|
||||
double randThing = fast_rand() * static_cast<double>(FAST_RAND_RATIO) * 2. - 1.;
|
||||
m_nextWaitRandomization = std::exp2(randThing * twitch);
|
||||
double grainSpeed = 1. / std::exp2(randThing * jitter);
|
||||
|
||||
std::array<float, 2> sprayResult = {0, 0};
|
||||
if (spray > 0)
|
||||
{
|
||||
sprayResult[0] = (fast_rand() / static_cast<float>(FAST_RAND_MAX)) * spray * m_sampleRate;
|
||||
sprayResult[0] = fast_rand() * FAST_RAND_RATIO * spray * m_sampleRate;
|
||||
sprayResult[1] = linearInterpolate(
|
||||
sprayResult[0],
|
||||
(fast_rand() / static_cast<float>(FAST_RAND_MAX)) * spray * m_sampleRate,
|
||||
fast_rand() * FAST_RAND_RATIO * spray * m_sampleRate,
|
||||
spraySpread);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
{
|
||||
for( fpp_t frame = 0; frame < frames; ++frame )
|
||||
{
|
||||
const double gain = ( 1 - fastPow( ( m_counter < m_length ) ? m_counter / m_length : 1, m_env ) );
|
||||
const double gain = 1 - std::pow((m_counter < m_length) ? m_counter / m_length : 1, m_env);
|
||||
const sample_t s = ( Oscillator::sinSample( m_phase ) * ( 1 - m_noise ) ) + ( Oscillator::noiseSample( 0 ) * gain * gain * m_noise );
|
||||
buf[frame][0] = s * gain;
|
||||
buf[frame][1] = s * gain;
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
m_FX.nextSample( buf[frame][0], buf[frame][1] );
|
||||
m_phase += m_freq / sampleRate;
|
||||
|
||||
const double change = ( m_counter < m_length ) ? ( ( m_startFreq - m_endFreq ) * ( 1 - fastPow( m_counter / m_length, m_slope ) ) ) : 0;
|
||||
const double change = (m_counter < m_length) ? ((m_startFreq - m_endFreq) * (1 - std::pow(m_counter / m_length, m_slope))) : 0;
|
||||
m_freq = m_endFreq + change;
|
||||
++m_counter;
|
||||
}
|
||||
|
||||
@@ -858,7 +858,7 @@ inline sample_t MonstroSynth::calcSlope( int slope, sample_t s )
|
||||
{
|
||||
if( m_parent->m_slope[slope] == 1.0f ) return s;
|
||||
if( s == 0.0f ) return s;
|
||||
return fastPow( s, m_parent->m_slope[slope] );
|
||||
return std::pow(s, m_parent->m_slope[slope]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "Oscillator.h"
|
||||
|
||||
#include "embed.h"
|
||||
#include "lmms_math.h"
|
||||
#include "plugin_export.h"
|
||||
|
||||
namespace lmms
|
||||
@@ -392,7 +393,7 @@ void NesObject::renderOutput( SampleFrame* buf, fpp_t frames )
|
||||
pin1 *= 1.0 + ( Oscillator::noiseSample( 0.0f ) * DITHER_AMP );
|
||||
pin1 = pin1 / 30.0f;
|
||||
|
||||
pin1 = signedPow( pin1, NES_DIST );
|
||||
pin1 = signedPowf(pin1, NES_DIST);
|
||||
|
||||
pin1 = pin1 * 2.0f - 1.0f;
|
||||
|
||||
@@ -401,7 +402,7 @@ void NesObject::renderOutput( SampleFrame* buf, fpp_t frames )
|
||||
m_12Last = pin1;
|
||||
|
||||
// compensate DC offset
|
||||
pin1 += 1.0f - signedPow( static_cast<float>( ch1Level + ch2Level ) / 30.0f, NES_DIST );
|
||||
pin1 += 1.0f - signedPowf(static_cast<float>(ch1Level + ch2Level) / 30.0f, NES_DIST);
|
||||
|
||||
pin1 *= NES_MIXING_12;
|
||||
|
||||
@@ -410,7 +411,7 @@ void NesObject::renderOutput( SampleFrame* buf, fpp_t frames )
|
||||
pin2 *= 1.0 + ( Oscillator::noiseSample( 0.0f ) * DITHER_AMP );
|
||||
pin2 = pin2 / 30.0f;
|
||||
|
||||
pin2 = signedPow( pin2, NES_DIST );
|
||||
pin2 = signedPowf(pin2, NES_DIST);
|
||||
|
||||
pin2 = pin2 * 2.0f - 1.0f;
|
||||
|
||||
@@ -419,7 +420,7 @@ void NesObject::renderOutput( SampleFrame* buf, fpp_t frames )
|
||||
m_34Last = pin2;
|
||||
|
||||
// compensate DC offset
|
||||
pin2 += 1.0f - signedPow( static_cast<float>( ch3Level + ch4Level ) / 30.0f, NES_DIST );
|
||||
pin2 += 1.0f - signedPowf(static_cast<float>(ch3Level + ch4Level) / 30.0f, NES_DIST);
|
||||
|
||||
pin2 *= NES_MIXING_34;
|
||||
|
||||
|
||||
@@ -136,13 +136,6 @@ public:
|
||||
return static_cast<int>( m_samplerate / freq );
|
||||
}
|
||||
|
||||
inline float signedPow( float f, float e )
|
||||
{
|
||||
return f < 0
|
||||
? powf( qAbs( f ), e ) * -1.0f
|
||||
: powf( f, e );
|
||||
}
|
||||
|
||||
inline int nearestNoiseFreq( float f )
|
||||
{
|
||||
int n = 15;
|
||||
|
||||
Reference in New Issue
Block a user