Sound: Add extension commands to pause/resume audio playback

These commands supersede Pomme_PauseAllChannels().
This commit is contained in:
Iliyas Jorio 2022-05-15 12:09:20 +02:00
parent 70acda5ce4
commit db3b81e97f
4 changed files with 16 additions and 29 deletions

View File

@ -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);

View File

@ -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
};

View File

@ -34,8 +34,6 @@ public:
bool loop;
bool interpolate;
bool temporaryPause = false;
ChannelImpl(SndChannelPtr _macChannel, bool transferMacChannelOwnership);
~ChannelImpl();

View File

@ -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