ref: 288c2dccee44be697544639d4717dada80dafe6e
parent: 07ee64818196cbe91528e90b51ce8172d990120a
author: Clownacy <Clownacy@users.noreply.github.com>
date: Sun Apr 19 15:05:25 EDT 2020
Wii U - Use a frame callback instead of a thread
--- a/src/Backends/Audio/WiiU-Software.cpp
+++ b/src/Backends/Audio/WiiU-Software.cpp
@@ -94,58 +94,51 @@
OSUnlockMutex(&organya_mutex);
}
-static int ThreadFunction(int argc, const char *argv[])
+static void FrameCallback(void)
{
- for (;;)
- {
- OSTestThreadCancel();
+ static int last_half = 1;
- static int last_half = 1;
+ unsigned int half;
- unsigned int half;
+ AXVoiceOffsets offsets;
- AXVoiceOffsets offsets;
+ AXGetVoiceOffsets(voice, &offsets);
- AXGetVoiceOffsets(voice, &offsets);
+ if (offsets.currentOffset > (buffer_length / 2))
+ {
+ half = 1;
+ }
+ else
+ {
+ half = 0;
+ }
- if (offsets.currentOffset > (buffer_length / 2))
+ if (half != last_half)
+ {
+ for (unsigned int i = 0; i < buffer_length / 2; ++i)
{
- half = 1;
+ stream_buffer_float[i * 2 + 0] = 0.0f;
+ stream_buffer_float[i * 2 + 1] = 0.0f;
}
- else
- {
- half = 0;
- }
- if (half != last_half)
+ Callback(stream_buffer_float, buffer_length / 2);
+
+ for (unsigned int i = 0; i < buffer_length / 2; ++i)
{
- for (unsigned int i = 0; i < buffer_length / 2; ++i)
- {
- stream_buffer_float[i * 2 + 0] = 0.0f;
- stream_buffer_float[i * 2 + 1] = 0.0f;
- }
+ float sample = stream_buffer_float[i * 2];
- Callback(stream_buffer_float, buffer_length / 2);
+ if (sample < -1.0f)
+ sample = -1.0f;
+ else if (sample > 1.0f)
+ sample = 1.0f;
- for (unsigned int i = 0; i < buffer_length / 2; ++i)
- {
- float sample = stream_buffer_float[i * 2];
-
- if (sample < -1.0f)
- sample = -1.0f;
- else if (sample > 1.0f)
- sample = 1.0f;
-
- stream_buffer[((buffer_length / 2) * last_half) + i] = sample * 32767.0f;
- }
+ stream_buffer[((buffer_length / 2) * last_half) + i] = sample * 32767.0f;
+ }
- DCStoreRange(&stream_buffer[(buffer_length / 2) * last_half], buffer_length / 2 * sizeof(short));
+ DCStoreRange(&stream_buffer[(buffer_length / 2) * last_half], buffer_length / 2 * sizeof(short));
- last_half = half;
- }
+ last_half = half;
}
-
- return 0;
}
bool AudioBackend_Init(void)
@@ -207,10 +200,8 @@
AXVoiceEnd(voice);
- //AXRegisterAppFrameCallback(FrameCallback);
+ AXRegisterAppFrameCallback(FrameCallback);
- OSRunThread(OSGetDefaultThread(0), ThreadFunction, 0, NULL);
-
return true;
}
@@ -219,10 +210,6 @@
void AudioBackend_Deinit(void)
{
- OSCancelThread(OSGetDefaultThread(0));
-
- OSJoinThread(OSGetDefaultThread(0), NULL);
-
AXFreeVoice(voice);
AXQuit();