Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions source/swe_wave_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ namespace olc::sound
return std::prev(m_listWaves.end());
}

void WaveEngine::PauseWaveform(const PlayingWave& w) {
w->bPaused = true;
}

void WaveEngine::ResumeWaveform(const PlayingWave& w) {
w->bPaused = false;
}

void WaveEngine::RewindWaveform(const PlayingWave& w) {
w->dInstanceTime = m_dGlobalTime;
}

void WaveEngine::StopWaveform(const PlayingWave& w)
{
w->bFlagForStop = true;
Expand Down Expand Up @@ -173,8 +185,14 @@ namespace olc::sound
}
else
{
// OR, sample the waveform from the correct channel
fSample += float(wave.pWave->vChannelView[nChannel % wave.pWave->file.channels()].GetSample(dTimeOffset * m_dSamplePerTime * wave.dSpeedModifier));
// OR, if waveform is not paused, then sample the waveform from the correct channel
if (!wave.bPaused) {
fSample += float(wave.pWave->vChannelView[nChannel % wave.pWave->file.channels()].GetSample(dTimeOffset * m_dSamplePerTime * wave.dSpeedModifier));
}
else {
// Account for paused waiting time.
wave.dInstanceTime += m_dTimePerSample;
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions source/swe_wave_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace olc::sound
bool bFinished = false;
bool bLoop = false;
bool bFlagForStop = false;
bool bPaused = false;
};

typedef std::list<WaveInstance>::iterator PlayingWave;
Expand Down Expand Up @@ -69,6 +70,9 @@ namespace olc::sound


PlayingWave PlayWaveform(Wave* pWave, bool bLoop = false, double dSpeed = 1.0);
void PauseWaveform(const PlayingWave& w);
void ResumeWaveform(const PlayingWave& w);
void RewindWaveform(const PlayingWave& w);
void StopWaveform(const PlayingWave& w);
void StopAll();

Expand Down