shithub: cstory

Download patch

ref: 7abab0039ba5818e1bedaa4ac472a03b67f84346
parent: be6f46fabdb59659a051369053d06991f066b556
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Sep 3 15:12:02 EDT 2020

Pre-convert the Organya callback timer

Oh no, I used the naughty 'm' word :(

--- a/src/Backends/Audio/SoftwareMixer.cpp
+++ b/src/Backends/Audio/SoftwareMixer.cpp
@@ -10,7 +10,7 @@
 static unsigned long output_frequency;
 
 static void (*organya_callback)(void);
-static unsigned int organya_callback_milliseconds;
+static unsigned int organya_callback_timer_master;
 static unsigned int organya_sleep_timer;
 
 static void MixSoundsAndUpdateOrganya(long *stream, size_t frames_total)
@@ -17,7 +17,7 @@
 {
 	SoftwareMixerBackend_LockOrganyaMutex();
 
-	if (organya_callback_milliseconds == 0)
+	if (organya_callback_timer_master == 0)
 	{
 		SoftwareMixerBackend_LockMixerMutex();
 		Mixer_MixSounds(stream, frames_total);
@@ -47,15 +47,15 @@
 
 		while (frames_done != frames_total)
 		{
-			static unsigned long organya_countdown;
+			static unsigned long organya_callback_timer;
 
-			if (organya_countdown == 0)
+			if (organya_callback_timer == 0)
 			{
-				organya_countdown = (organya_callback_milliseconds * output_frequency) / 1000;	// organya_timer is in milliseconds, so convert it to audio frames
+				organya_callback_timer = organya_callback_timer_master;
 				organya_callback();
 			}
 
-			const unsigned int frames_to_do = MIN(organya_countdown, frames_total - frames_done);
+			const unsigned int frames_to_do = MIN(organya_callback_timer, frames_total - frames_done);
 
 			SoftwareMixerBackend_LockMixerMutex();
 			Mixer_MixSounds(stream + frames_done * 2, frames_to_do);
@@ -62,7 +62,7 @@
 			SoftwareMixerBackend_UnlockMixerMutex();
 
 			frames_done += frames_to_do;
-			organya_countdown -= frames_to_do;
+			organya_callback_timer -= frames_to_do;
 		}
 	}
 
@@ -199,7 +199,7 @@
 {
 	SoftwareMixerBackend_LockOrganyaMutex();
 
-	organya_callback_milliseconds = milliseconds;
+	organya_callback_timer_master = (milliseconds * output_frequency) / 1000; // convert milliseconds to audio frames
 
 	SoftwareMixerBackend_UnlockOrganyaMutex();
 }
@@ -208,7 +208,7 @@
 {
 	SoftwareMixerBackend_LockOrganyaMutex();
 
-	organya_sleep_timer = (milliseconds * output_frequency) / 1000;
+	organya_sleep_timer = (milliseconds * output_frequency) / 1000; // convert milliseconds to audio frames
 
 	SoftwareMixerBackend_UnlockOrganyaMutex();
 }