Skip to content

Commit

Permalink
Effect fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewol committed May 8, 2021
1 parent 1a26e73 commit 102ca00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Audio/src/AudioBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

uint32 DSP::GetStartSample() const
{
return static_cast<uint32>(startTime * static_cast<double>(m_sampleRate) / 1000.0);
return static_cast<uint32>(startTime * static_cast<double>(m_audioBase->GetSampleRate()) / 1000.0);
}

uint32 DSP::GetCurrentSample() const
Expand Down
15 changes: 10 additions & 5 deletions Audio/src/DSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,12 @@ void RetriggerDSP::Process(float *out, uint32 numSamples)

const uint32 startSample = GetStartSample();
const uint32 nowSample = GetCurrentSample();
const auto maxSample = m_audioBase->GetPCMCount();

float *pcmSource = m_audioBase->GetPCM();
double rateMult = (double)m_audioBase->GetSampleRate() / m_sampleRate;
uint32 pcmStartSample = static_cast<uint32>(lastTimingPoint * ((double)m_audioBase->GetSampleRate() / 1000.0));
uint32 baseStartRepeat = static_cast<uint32>(lastTimingPoint * ((double)m_sampleRate / 1000.0));
uint32 baseStartRepeat = static_cast<uint32>(lastTimingPoint * ((double)m_audioBase->GetSampleRate() / 1000.0));

for (uint32 i = 0; i < numSamples; i++)
{
Expand All @@ -370,21 +371,25 @@ void RetriggerDSP::Process(float *out, uint32 numSamples)
int startOffset = 0;
if (m_resetDuration > 0)
{
startOffset = (nowSample + i - baseStartRepeat) / (int)m_resetDuration;
startOffset = (nowSample + i - baseStartRepeat) / (int)(m_resetDuration * rateMult);
startOffset = static_cast<int>(startOffset * m_resetDuration * rateMult);
}
else
{
startOffset = static_cast<int>((startSample - baseStartRepeat) * rateMult);
startOffset = static_cast<int>((startSample - baseStartRepeat));
}

int pcmSample = static_cast<int>(pcmStartSample) + startOffset + static_cast<int>(m_currentSample * rateMult);
float gating = 1.0f;
if (m_currentSample > m_gateLength)
gating = 0;
// Sample from buffer
out[i * 2] = gating * pcmSource[pcmSample * 2] * mix + out[i * 2] * (1 - mix);
out[i * 2 + 1] = gating * pcmSource[pcmSample * 2 + 1] * mix + out[i * 2 + 1] * (1 - mix);
assert(pcmSample < maxSample);
if (pcmSample < maxSample) //TODO: Improve whatever is necessary to make sure this never happens
{
out[i * 2] = gating * pcmSource[pcmSample * 2] * mix + out[i * 2] * (1 - mix);
out[i * 2 + 1] = gating * pcmSource[pcmSample * 2 + 1] * mix + out[i * 2 + 1] * (1 - mix);
}

// Increase index
m_currentSample = (m_currentSample + 1) % m_length;
Expand Down

0 comments on commit 102ca00

Please sign in to comment.