diff --git a/source/swe_wave_engine.cpp b/source/swe_wave_engine.cpp index 27498e6..23e8efc 100644 --- a/source/swe_wave_engine.cpp +++ b/source/swe_wave_engine.cpp @@ -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; @@ -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; + } } } } diff --git a/source/swe_wave_engine.h b/source/swe_wave_engine.h index 05a39d5..6d3117b 100644 --- a/source/swe_wave_engine.h +++ b/source/swe_wave_engine.h @@ -21,6 +21,7 @@ namespace olc::sound bool bFinished = false; bool bLoop = false; bool bFlagForStop = false; + bool bPaused = false; }; typedef std::list::iterator PlayingWave; @@ -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();