From db3b81e97fc5c1a7966193c4ae10cc3ef50e558f Mon Sep 17 00:00:00 2001 From: Iliyas Jorio Date: Sun, 15 May 2022 12:09:20 +0200 Subject: [PATCH] Sound: Add extension commands to pause/resume audio playback These commands supersede Pomme_PauseAllChannels(). --- src/Pomme.h | 3 --- src/PommeEnums.h | 2 ++ src/SoundMixer/ChannelImpl.h | 2 -- src/SoundMixer/SoundManager.cpp | 38 ++++++++++++--------------------- 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/Pomme.h b/src/Pomme.h index 690233a..616d72e 100644 --- a/src/Pomme.h +++ b/src/Pomme.h @@ -492,9 +492,6 @@ NumVersion SndSoundManagerVersion(); // Pomme extension Boolean Pomme_DecompressSoundResource(SndListHandle* sndHandlePtr, long* offsetToHeader); -// Pomme extension -void Pomme_PauseAllChannels(Boolean pause); - // Pomme extension SndListHandle Pomme_SndLoadFileAsResource(short fRefNum); diff --git a/src/PommeEnums.h b/src/PommeEnums.h index 944b1d9..a534362 100644 --- a/src/PommeEnums.h +++ b/src/PommeEnums.h @@ -285,6 +285,8 @@ enum ESndCmds sizeCmd = 90, // obsolete command convertCmd = 91, // obsolete MACE command pommeSetLoopCmd = 0x7001, + pommePausePlaybackCmd = 0x7002, // pause playback ('pauseCmd' locks the channel, it doesn't pause playback) + pommeResumePlaybackCmd = 0x7003, // resume playback ('resumeCmd' unlocks the channel, it doesn't unpause playback) // Do not define commands above 0x7FFF -- the high bit means a 'snd ' resource has associated sound data }; diff --git a/src/SoundMixer/ChannelImpl.h b/src/SoundMixer/ChannelImpl.h index 8f3fc81..b3776b6 100644 --- a/src/SoundMixer/ChannelImpl.h +++ b/src/SoundMixer/ChannelImpl.h @@ -34,8 +34,6 @@ public: bool loop; bool interpolate; - bool temporaryPause = false; - ChannelImpl(SndChannelPtr _macChannel, bool transferMacChannelOwnership); ~ChannelImpl(); diff --git a/src/SoundMixer/SoundManager.cpp b/src/SoundMixer/SoundManager.cpp index f636577..6262d96 100644 --- a/src/SoundMixer/SoundManager.cpp +++ b/src/SoundMixer/SoundManager.cpp @@ -181,9 +181,6 @@ static void InstallSoundInChannel(SndChannelPtr chan, const Ptr sampledSoundHead // issue pommeSetLoopCmd *after* bufferCmd/soundCmd. impl.ApplyParametersToSource(kApplyParameters_All & ~kApplyParameters_Loop); - // Override systemwide audio pause. - impl.temporaryPause = false; - // Get it going! impl.source.Play(); } @@ -266,6 +263,20 @@ OSErr SndDoImmediate(SndChannelPtr chan, const SndCommand* cmd) impl.ApplyParametersToSource(kApplyParameters_Loop); break; + case pommePausePlaybackCmd: + if (impl.source.state == cmixer::CM_STATE_PLAYING) + { + impl.source.Pause(); + } + break; + + case pommeResumePlaybackCmd: + if (impl.source.state == cmixer::CM_STATE_PAUSED) // only resume paused channels -- don't resurrect stopped channels + { + impl.source.Play(); + } + break; + default: TODOMINOR2(cmd->cmd << "(" << cmd->param1 << "," << cmd->param2 << ")"); } @@ -369,27 +380,6 @@ NumVersion SndSoundManagerVersion() return v; } -//----------------------------------------------------------------------------- -// Extension: pause/unpause channels that are currently playing - -void Pomme_PauseAllChannels(Boolean pause) -{ - for (auto* chan = Pomme::Sound::gHeadChan; chan; chan = chan->GetNext()) - { - auto& source = chan->source; - if (pause && source.state == cmixer::CM_STATE_PLAYING && !chan->temporaryPause) - { - source.Pause(); - chan->temporaryPause = true; - } - else if (!pause && source.state == cmixer::CM_STATE_PAUSED && chan->temporaryPause) - { - source.Play(); - chan->temporaryPause = false; - } - } -} - //----------------------------------------------------------------------------- // Init Sound Manager