shithub: cstory

Download patch

ref: 873566a19eba4de94223bef50baadc26ed8fd906
parent: bbfcc48e2a0ce201fae14676bbac20cd7b152b04
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Apr 17 21:16:36 EDT 2020

Attempt 100 of trying to fix Wii U audio hangs

There's a new bug I've noticed: sometimes, an instrument will just
'disappear', and refuse to ever play again.

This stuff is practically impossible to debug, so I'm just throwing
things at the wall. This time, I'm going to make more use of the
`AXVoiceBegin` and `AXVoiceEnd` functions. I have no idea what
they're meant to do: code I found online uses it inconstently, and
Decaf doesn't have it implemented at all!

Hopefully, all of my problems have just been race conditions caused
by not using these guard functions (assuming that's what they are).

--- a/src/Backends/Audio/WiiU.cpp
+++ b/src/Backends/Audio/WiiU.cpp
@@ -261,8 +261,12 @@
 
 	if (sound->voice != NULL)
 	{
+		AXVoiceBegin(sound->voice);
+
 		AXSetVoiceLoop(sound->voice, looping ? AX_VOICE_LOOP_ENABLED : AX_VOICE_LOOP_DISABLED);
 		AXSetVoiceState(sound->voice, AX_VOICE_STATE_PLAYING);
+
+		AXVoiceEnd(sound->voice);
 	}
 
 	OSUnlockMutex(&sound_list_mutex);
@@ -273,8 +277,14 @@
 	OSLockMutex(&sound_list_mutex);
 
 	if (sound->voice != NULL)
+	{
+		AXVoiceBegin(sound->voice);
+
 		AXSetVoiceState(sound->voice, AX_VOICE_STATE_STOPPED);
 
+		AXVoiceEnd(sound->voice);
+	}
+
 	OSUnlockMutex(&sound_list_mutex);
 }
 
@@ -283,8 +293,14 @@
 	OSLockMutex(&sound_list_mutex);
 
 	if (sound->voice != NULL)
+	{
+		AXVoiceBegin(sound->voice);
+
 		AXSetVoiceCurrentOffset(sound->voice, 0);
 
+		AXVoiceEnd(sound->voice);
+	}
+
 	OSUnlockMutex(&sound_list_mutex);
 }
 
@@ -296,8 +312,12 @@
 
 	if (sound->voice != NULL)
 	{
+		AXVoiceBegin(sound->voice);
+
 		float srcratio = (float)frequency / (float)AXGetInputSamplesPerSec();
 		AXSetVoiceSrcRatio(sound->voice, srcratio);
+
+		AXVoiceEnd(sound->voice);
 	}
 
 	OSUnlockMutex(&sound_list_mutex);
@@ -311,9 +331,13 @@
 
 	if (sound->voice != NULL)
 	{
+		AXVoiceBegin(sound->voice);
+
 		AXVoiceVeData vol = {.volume = sound->volume};
 
 		AXSetVoiceVe(sound->voice, &vol);
+
+		AXVoiceEnd(sound->voice);
 	}
 
 	OSUnlockMutex(&sound_list_mutex);
@@ -328,11 +352,15 @@
 
 	if (sound->voice != NULL)
 	{
+		AXVoiceBegin(sound->voice);
+
 		sound->mix_data[0].bus[0].volume = sound->pan_l;
 		sound->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);
+
+		AXVoiceEnd(sound->voice);
 	}
 
 	OSUnlockMutex(&sound_list_mutex);