From 855fe70255e55ac1d760151cad6fb9dbcca7d733 Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Thu, 25 Aug 2022 16:05:18 -0500 Subject: [PATCH 1/2] Update olc_swe_template.h Include compile instructions for emscripten. --- source/olc_swe_template.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/olc_swe_template.h b/source/olc_swe_template.h index 18255cd..5d426a1 100644 --- a/source/olc_swe_template.h +++ b/source/olc_swe_template.h @@ -118,6 +118,19 @@ */ +/* + + Compiling with Emscripten + ~~~~~~~~~~~~~~~~~~~~~~~~~ + When compiling with Emscripten, you will include SDL mixer in your setting flags: + Add: -s USE_SDL_MIXER=2 + + Your command should look something like: + + em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_SDL_MIXER=2 -s USE_LIBPNG=1 ./YourSource.cpp -o pge.html + +*/ + /* Using in multiple-file projects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 0343865caa5a4ce06dea07b0393ed3de77ac37b2 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 17 Apr 2023 21:53:12 -0500 Subject: [PATCH 2/2] Add in functionality for PauseWaveform, ResumeWaveform, and RewindWaveform --- source/olc_swe_template.h | 13 ------------- source/swe_wave_engine.cpp | 22 ++++++++++++++++++++-- source/swe_wave_engine.h | 4 ++++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/source/olc_swe_template.h b/source/olc_swe_template.h index 5d426a1..18255cd 100644 --- a/source/olc_swe_template.h +++ b/source/olc_swe_template.h @@ -118,19 +118,6 @@ */ -/* - - Compiling with Emscripten - ~~~~~~~~~~~~~~~~~~~~~~~~~ - When compiling with Emscripten, you will include SDL mixer in your setting flags: - Add: -s USE_SDL_MIXER=2 - - Your command should look something like: - - em++ -std=c++17 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_SDL_MIXER=2 -s USE_LIBPNG=1 ./YourSource.cpp -o pge.html - -*/ - /* Using in multiple-file projects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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();