Wii U - Use a frame callback instead of a thread
This commit is contained in:
parent
07ee648181
commit
288c2dccee
1 changed files with 42 additions and 55 deletions
|
@ -94,58 +94,51 @@ static void Callback(void *output_stream, size_t frames_total)
|
||||||
OSUnlockMutex(&organya_mutex);
|
OSUnlockMutex(&organya_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ThreadFunction(int argc, const char *argv[])
|
static void FrameCallback(void)
|
||||||
{
|
{
|
||||||
for (;;)
|
static int last_half = 1;
|
||||||
|
|
||||||
|
unsigned int half;
|
||||||
|
|
||||||
|
AXVoiceOffsets offsets;
|
||||||
|
|
||||||
|
AXGetVoiceOffsets(voice, &offsets);
|
||||||
|
|
||||||
|
if (offsets.currentOffset > (buffer_length / 2))
|
||||||
{
|
{
|
||||||
OSTestThreadCancel();
|
half = 1;
|
||||||
|
}
|
||||||
static int last_half = 1;
|
else
|
||||||
|
{
|
||||||
unsigned int half;
|
half = 0;
|
||||||
|
|
||||||
AXVoiceOffsets offsets;
|
|
||||||
|
|
||||||
AXGetVoiceOffsets(voice, &offsets);
|
|
||||||
|
|
||||||
if (offsets.currentOffset > (buffer_length / 2))
|
|
||||||
{
|
|
||||||
half = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
half = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (half != last_half)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Callback(stream_buffer_float, buffer_length / 2);
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
DCStoreRange(&stream_buffer[(buffer_length / 2) * last_half], buffer_length / 2 * sizeof(short));
|
|
||||||
|
|
||||||
last_half = half;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (half != last_half)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Callback(stream_buffer_float, buffer_length / 2);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
DCStoreRange(&stream_buffer[(buffer_length / 2) * last_half], buffer_length / 2 * sizeof(short));
|
||||||
|
|
||||||
|
last_half = half;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioBackend_Init(void)
|
bool AudioBackend_Init(void)
|
||||||
|
@ -207,9 +200,7 @@ bool AudioBackend_Init(void)
|
||||||
|
|
||||||
AXVoiceEnd(voice);
|
AXVoiceEnd(voice);
|
||||||
|
|
||||||
//AXRegisterAppFrameCallback(FrameCallback);
|
AXRegisterAppFrameCallback(FrameCallback);
|
||||||
|
|
||||||
OSRunThread(OSGetDefaultThread(0), ThreadFunction, 0, NULL);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -219,10 +210,6 @@ bool AudioBackend_Init(void)
|
||||||
|
|
||||||
void AudioBackend_Deinit(void)
|
void AudioBackend_Deinit(void)
|
||||||
{
|
{
|
||||||
OSCancelThread(OSGetDefaultThread(0));
|
|
||||||
|
|
||||||
OSJoinThread(OSGetDefaultThread(0), NULL);
|
|
||||||
|
|
||||||
AXFreeVoice(voice);
|
AXFreeVoice(voice);
|
||||||
|
|
||||||
AXQuit();
|
AXQuit();
|
||||||
|
|
Loading…
Add table
Reference in a new issue