diff --git a/src/Backends/Audio.h b/src/Backends/Audio.h index 86ad6563..2d47babf 100644 --- a/src/Backends/Audio.h +++ b/src/Backends/Audio.h @@ -20,3 +20,4 @@ void AudioBackend_SetSoundPan(AudioBackend_Sound *sound, long pan); void AudioBackend_SetOrganyaCallback(void (*callback)(void)); void AudioBackend_SetOrganyaTimer(unsigned int milliseconds); +void AudioBackend_SleepOrganya(unsigned int milliseconds); diff --git a/src/Backends/Audio/miniaudio.cpp b/src/Backends/Audio/miniaudio.cpp index ced9e055..8a142857 100644 --- a/src/Backends/Audio/miniaudio.cpp +++ b/src/Backends/Audio/miniaudio.cpp @@ -27,6 +27,7 @@ static unsigned long output_frequency; static void (*organya_callback)(void); static unsigned int organya_callback_milliseconds; +static unsigned int organya_sleep_timer; static void MixSoundsAndUpdateOrganya(long *stream, size_t frames_total) { @@ -47,6 +48,19 @@ static void MixSoundsAndUpdateOrganya(long *stream, size_t frames_total) // Instead, we can just do this. unsigned int frames_done = 0; + // Don't process Organya when it's meant to be sleeping + const unsigned int frames_to_do = MIN(organya_sleep_timer, frames_total - frames_done); + + if (frames_to_do != 0) + { + ma_mutex_lock(&mutex); + Mixer_MixSounds(stream, frames_to_do); + ma_mutex_unlock(&mutex); + + frames_done += frames_to_do; + organya_sleep_timer -= frames_to_do; + } + while (frames_done != frames_total) { static unsigned long organya_countdown; @@ -307,3 +321,12 @@ void AudioBackend_SetOrganyaTimer(unsigned int milliseconds) ma_mutex_unlock(&organya_mutex); } + +void AudioBackend_SleepOrganya(unsigned int milliseconds) +{ + ma_mutex_lock(&organya_mutex); + + organya_sleep_timer = (milliseconds * output_frequency) / 1000; + + ma_mutex_unlock(&organya_mutex); +} diff --git a/src/Organya.cpp b/src/Organya.cpp index 37b5d57f..fc5064ca 100644 --- a/src/Organya.cpp +++ b/src/Organya.cpp @@ -868,7 +868,7 @@ void StopOrganyaMusic(void) memset(key_on, 0, sizeof(key_on)); memset(key_twin, 0, sizeof(key_twin)); -// Sleep(100); // TODO - Emulate this + AudioBackend_SleepOrganya(100); } void SetOrganyaFadeout(void)