Skip to content

Commit

Permalink
Scale and smooth samples for non-custom waveforms
Browse files Browse the repository at this point in the history
  • Loading branch information
dpw13 authored and kblaschke committed Feb 21, 2024
1 parent 07c9a8a commit 861c36e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/libprojectM/MilkdropPreset/Waveforms/WaveformMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,23 @@ auto WaveformMath::GetVertices(const PresetState& presetState,
begin(m_pcmDataR));
}

// Scale waveform data to [-1, 1] range
for (size_t i = 0; i < m_pcmDataL.size(); ++i)
// Scale and smooth waveform data
float scale = presetState.waveScale / 128.0f;
// The first sample gets scaled directly because it is not mixed with other samples.
m_pcmDataL[0] *= scale;
m_pcmDataR[0] *= scale;
/* If s[i] is output sample i and p[i] is input sample i, then:
* s[0] = waveScale*p[i];
* s[i] = waveScale*(1-waveSmoothing)*p[i] + waveSmoothing*s[i-1]
* Note that this is an IIR filter with alpha = waveSmoothing.
*/
float mix2 = presetState.waveSmoothing; // amount of previous sample to add to this sample
float mix1 = scale * (1.0f - mix2); // amount to scale this sample
// Scale and mix samples after the first one.
for (size_t i = 1; i < m_pcmDataL.size(); ++i)
{
m_pcmDataL.at(i) /= 128.0f;
m_pcmDataR.at(i) /= 128.0f;
m_pcmDataL[i] = m_pcmDataL[i]*mix1 + m_pcmDataL[i-1]*mix2;
m_pcmDataR[i] = m_pcmDataR[i]*mix1 + m_pcmDataR[i-1]*mix2;
}

// Aspect multipliers
Expand Down

0 comments on commit 861c36e

Please sign in to comment.