MacLO/src/Sounds.c
Jon Thysell 50a753b35e Minor cleanup of resources
Made sure all resources are no longer marked as purgeable so they stay
in memory (not that we were running out), also cleaned up some other
code issues.
2021-12-01 10:08:07 -08:00

67 lines
1.5 KiB
C

// Copyright (c) Jon Thysell <http://jonthysell.com>
// Licensed under the MIT License.
#include "Sounds.h"
#define SndBaseResId 8192
#define ClickSndResID SndBaseResId
#define RetrySndResID (ClickSndResID + 1)
#define DoneSndResID (RetrySndResID + 1)
#define DefaultEnabled true
#define PlaySoundsAsync false
void Sounds_Init(Sounds *pSounds)
{
pSounds->Enabled = DefaultEnabled;
pSounds->ClickSnd = Get1Resource('snd ', ClickSndResID);
if (pSounds->ClickSnd == nil)
{
ShowError("\pClick snd resource missing!", true);
}
pSounds->RetrySnd = Get1Resource('snd ', RetrySndResID);
if (pSounds->RetrySnd == nil)
{
ShowError("\pRetry snd resource missing!", true);
}
pSounds->DoneSnd = Get1Resource('snd ', DoneSndResID);
if (pSounds->DoneSnd == nil)
{
ShowError("\pDone snd resource missing!", true);
}
}
void Sounds_PlayClickSnd(const Sounds *pSounds)
{
if (pSounds->Enabled)
{
HLock(pSounds->ClickSnd);
SndPlay(nil, pSounds->ClickSnd, PlaySoundsAsync);
HUnlock(pSounds->ClickSnd);
}
}
void Sounds_PlayRetrySnd(const Sounds *pSounds)
{
if (pSounds->Enabled)
{
HLock(pSounds->RetrySnd);
SndPlay(nil, pSounds->RetrySnd, PlaySoundsAsync);
HUnlock(pSounds->RetrySnd);
}
}
void Sounds_PlayDoneSnd(const Sounds *pSounds)
{
if (pSounds->Enabled)
{
HLock(pSounds->DoneSnd);
SndPlay(nil, pSounds->DoneSnd, PlaySoundsAsync);
HUnlock(pSounds->DoneSnd);
}
}