Wii U audio backend cleanup
Still bugging-out though
This commit is contained in:
parent
9e9b86c6e9
commit
7d95fb8ea3
1 changed files with 36 additions and 29 deletions
|
@ -25,7 +25,6 @@ struct AudioBackend_Sound
|
||||||
unsigned short volume;
|
unsigned short volume;
|
||||||
unsigned short pan_l;
|
unsigned short pan_l;
|
||||||
unsigned short pan_r;
|
unsigned short pan_r;
|
||||||
AXVoiceDeviceMixData mix_data[6];
|
|
||||||
|
|
||||||
struct AudioBackend_Sound *next;
|
struct AudioBackend_Sound *next;
|
||||||
};
|
};
|
||||||
|
@ -40,6 +39,28 @@ static OSMutex organya_mutex;
|
||||||
|
|
||||||
static AudioBackend_Sound *sound_list_head;
|
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)
|
static double MillibelToScale(long volume)
|
||||||
{
|
{
|
||||||
// Volume is in hundredths of a decibel, from 0 to -10000
|
// Volume is in hundredths of a decibel, from 0 to -10000
|
||||||
|
@ -102,25 +123,6 @@ static int ThreadFunction(int argc, const char *argv[])
|
||||||
organya_callback();
|
organya_callback();
|
||||||
OSUnlockMutex(&sound_list_mutex);
|
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;
|
return 0;
|
||||||
|
@ -224,6 +226,8 @@ void AudioBackend_DestroySound(AudioBackend_Sound *sound)
|
||||||
|
|
||||||
void AudioBackend_PlaySound(AudioBackend_Sound *sound, bool looping)
|
void AudioBackend_PlaySound(AudioBackend_Sound *sound, bool looping)
|
||||||
{
|
{
|
||||||
|
CullVoices();
|
||||||
|
|
||||||
OSLockMutex(&sound_list_mutex);
|
OSLockMutex(&sound_list_mutex);
|
||||||
|
|
||||||
if (sound->voice == NULL)
|
if (sound->voice == NULL)
|
||||||
|
@ -239,12 +243,13 @@ void AudioBackend_PlaySound(AudioBackend_Sound *sound, bool looping)
|
||||||
AXVoiceVeData vol = {.volume = sound->volume};
|
AXVoiceVeData vol = {.volume = sound->volume};
|
||||||
AXSetVoiceVe(voice, &vol);
|
AXSetVoiceVe(voice, &vol);
|
||||||
|
|
||||||
memset(sound->mix_data, 0, sizeof(sound->mix_data));
|
AXVoiceDeviceMixData mix_data[6];
|
||||||
sound->mix_data[0].bus[0].volume = sound->pan_l;
|
memset(mix_data, 0, sizeof(mix_data));
|
||||||
sound->mix_data[1].bus[0].volume = sound->pan_r;
|
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, sound->mix_data);
|
AXSetVoiceDeviceMix(voice, AX_DEVICE_TYPE_DRC, 0, mix_data);
|
||||||
AXSetVoiceDeviceMix(voice, AX_DEVICE_TYPE_TV, 0, sound->mix_data);
|
AXSetVoiceDeviceMix(voice, AX_DEVICE_TYPE_TV, 0, mix_data);
|
||||||
|
|
||||||
float srcratio = (float)sound->frequency / (float)AXGetInputSamplesPerSec();
|
float srcratio = (float)sound->frequency / (float)AXGetInputSamplesPerSec();
|
||||||
AXSetVoiceSrcRatio(voice, srcratio);
|
AXSetVoiceSrcRatio(voice, srcratio);
|
||||||
|
@ -360,11 +365,13 @@ void AudioBackend_SetSoundPan(AudioBackend_Sound *sound, long pan)
|
||||||
{
|
{
|
||||||
AXVoiceBegin(sound->voice);
|
AXVoiceBegin(sound->voice);
|
||||||
|
|
||||||
sound->mix_data[0].bus[0].volume = sound->pan_l;
|
AXVoiceDeviceMixData mix_data[6];
|
||||||
sound->mix_data[1].bus[0].volume = sound->pan_r;
|
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_DRC, 0, mix_data);
|
||||||
AXSetVoiceDeviceMix(sound->voice, AX_DEVICE_TYPE_TV, 0, sound->mix_data);
|
AXSetVoiceDeviceMix(sound->voice, AX_DEVICE_TYPE_TV, 0, mix_data);
|
||||||
|
|
||||||
AXVoiceEnd(sound->voice);
|
AXVoiceEnd(sound->voice);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue