shithub: cstory

Download patch

ref: ab09dc67ebe3f87e6d9879979e49fe660fecf006
parent: 72eec8227cf41e9d2ad19b4b0ee6546a8a761b8e
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Sep 3 14:14:52 EDT 2020

Emulate the Organya thread pauses

Now there's a 100ms pause between songs.

Currently only the miniaudio backend supports this.

--- a/src/Backends/Audio.h
+++ b/src/Backends/Audio.h
@@ -20,3 +20,4 @@
 
 void AudioBackend_SetOrganyaCallback(void (*callback)(void));
 void AudioBackend_SetOrganyaTimer(unsigned int milliseconds);
+void AudioBackend_SleepOrganya(unsigned int milliseconds);
--- a/src/Backends/Audio/miniaudio.cpp
+++ b/src/Backends/Audio/miniaudio.cpp
@@ -27,6 +27,7 @@
 
 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 @@
 		// 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;
@@ -304,6 +318,15 @@
 	ma_mutex_lock(&organya_mutex);
 
 	organya_callback_milliseconds = 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);
 }
--- a/src/Organya.cpp
+++ b/src/Organya.cpp
@@ -868,7 +868,7 @@
 	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)