shithub: cstory

Download patch

ref: 7d95fb8ea3215dbfcc2f9c9f6a182c51c33df51d
parent: 9e9b86c6e98692ed8e2ff07c740ae8bea2d790e3
author: Clownacy <Clownacy@users.noreply.github.com>
date: Sun Apr 19 09:46:10 EDT 2020

Wii U audio backend cleanup

Still bugging-out though

--- a/src/Backends/Audio/WiiU.cpp
+++ b/src/Backends/Audio/WiiU.cpp
@@ -25,7 +25,6 @@
 	unsigned short volume;
 	unsigned short pan_l;
 	unsigned short pan_r;
-	AXVoiceDeviceMixData mix_data[6];
 
 	struct AudioBackend_Sound *next;
 };
@@ -40,6 +39,28 @@
 
 static AudioBackend_Sound *sound_list_head;
 
+static void CullVoices(void)
+{
+	// Free any voices that aren't playing anymore
+	OSLockMutex(&sound_list_mutex);
+
+	for (AudioBackend_Sound *sound = sound_list_head; sound != NULL; sound = sound->next)
+	{
+		if (sound->voice != NULL)
+		{
+			if (!AXIsVoiceRunning(sound->voice))
+			{
+				AXVoiceBegin(sound->voice);
+				AXFreeVoice(sound->voice);
+				AXVoiceEnd(sound->voice);
+				sound->voice = NULL;
+			}
+		}
+	}
+
+	OSUnlockMutex(&sound_list_mutex);
+}
+
 static double MillibelToScale(long volume)
 {
 	// Volume is in hundredths of a decibel, from 0 to -10000
@@ -102,25 +123,6 @@
 			organya_callback();
 			OSUnlockMutex(&sound_list_mutex);
 		}
-
-		// Free any voices that aren't playing anymore
-		OSLockMutex(&sound_list_mutex);
-
-		for (AudioBackend_Sound *sound = sound_list_head; sound != NULL; sound = sound->next)
-		{
-			if (sound->voice != NULL)
-			{
-				if (!AXIsVoiceRunning(sound->voice))
-				{
-					AXVoiceBegin(sound->voice);
-					AXFreeVoice(sound->voice);
-					AXVoiceEnd(sound->voice);
-					sound->voice = NULL;
-				}
-			}
-		}
-
-		OSUnlockMutex(&sound_list_mutex);
 	}
 
 	return 0;
@@ -224,6 +226,8 @@
 
 void AudioBackend_PlaySound(AudioBackend_Sound *sound, bool looping)
 {
+	CullVoices();
+
 	OSLockMutex(&sound_list_mutex);
 
 	if (sound->voice == NULL)
@@ -239,13 +243,14 @@
 			AXVoiceVeData vol = {.volume = sound->volume};
 			AXSetVoiceVe(voice, &vol);
 
-			memset(sound->mix_data, 0, sizeof(sound->mix_data));
-			sound->mix_data[0].bus[0].volume = sound->pan_l;
-			sound->mix_data[1].bus[0].volume = sound->pan_r;
+			AXVoiceDeviceMixData mix_data[6];
+			memset(mix_data, 0, sizeof(mix_data));
+			mix_data[0].bus[0].volume = sound->pan_l;
+			mix_data[1].bus[0].volume = sound->pan_r;
+
+			AXSetVoiceDeviceMix(voice, AX_DEVICE_TYPE_DRC, 0, mix_data);
+			AXSetVoiceDeviceMix(voice, AX_DEVICE_TYPE_TV, 0, mix_data);
 
-			AXSetVoiceDeviceMix(voice, AX_DEVICE_TYPE_DRC, 0, sound->mix_data);
-			AXSetVoiceDeviceMix(voice, AX_DEVICE_TYPE_TV, 0, sound->mix_data);
-
 			float srcratio = (float)sound->frequency / (float)AXGetInputSamplesPerSec();
 			AXSetVoiceSrcRatio(voice, srcratio);
 			AXSetVoiceSrcType(voice, AX_VOICE_SRC_TYPE_LINEAR);
@@ -360,11 +365,13 @@
 	{
 		AXVoiceBegin(sound->voice);
 
-		sound->mix_data[0].bus[0].volume = sound->pan_l;
-		sound->mix_data[1].bus[0].volume = sound->pan_r;
+		AXVoiceDeviceMixData mix_data[6];
+		memset(mix_data, 0, sizeof(mix_data));
+		mix_data[0].bus[0].volume = sound->pan_l;
+		mix_data[1].bus[0].volume = sound->pan_r;
 
-		AXSetVoiceDeviceMix(sound->voice, AX_DEVICE_TYPE_DRC, 0, sound->mix_data);
-		AXSetVoiceDeviceMix(sound->voice, AX_DEVICE_TYPE_TV, 0, sound->mix_data);
+		AXSetVoiceDeviceMix(sound->voice, AX_DEVICE_TYPE_DRC, 0, mix_data);
+		AXSetVoiceDeviceMix(sound->voice, AX_DEVICE_TYPE_TV, 0, mix_data);
 
 		AXVoiceEnd(sound->voice);
 	}