5353#define WIIU_DEVICE_MIRRORED 2
5454#define WIIU_MAX_DEVICES 3
5555
56+ static int mirroredHandle ;
57+ static int tvHandle ;
58+ static int drcHandle ;
59+
5660static void _WIIUAUDIO_framecallback ();
5761static SDL_AudioDevice * wiiuDevices [WIIU_MAX_DEVICES ];
5862static int deviceType ;
@@ -85,16 +89,6 @@ static int _WIIUAUDIO_OpenDeviceFunction(_THIS) {
8589
8690 SDL_zerop (this -> hidden );
8791
88- /* Take a quick aside to init the wiiu audio */
89- if (!AXIsInit ()) {
90- /* Init the AX audio engine */
91- AXInitParams initparams = {
92- .renderer = AX_INIT_RENDERER_48KHZ ,
93- .pipeline = AX_INIT_PIPELINE_SINGLE ,
94- };
95- AXInitWithParams (& initparams );
96- } else printf ("DEBUG: AX already up?\n" );
97-
9892 if (this -> spec .channels < 1 ) this -> spec .channels = 1 ;
9993 if (this -> spec .channels > WIIU_MAX_VALID_CHANNELS )
10094 this -> spec .channels = WIIU_MAX_VALID_CHANNELS ;
@@ -262,11 +256,6 @@ static int _WIIUAUDIO_OpenDeviceFunction(_THIS) {
262256 }
263257
264258 wiiuDevices [deviceCount ] = this ;
265-
266- if (deviceCount < 1 ) {
267- AXRegisterAppFrameCallback (_WIIUAUDIO_framecallback );
268- }
269-
270259 deviceCount ++ ;
271260
272261 return 0 ;
@@ -281,10 +270,6 @@ static void _WIIUAUDIO_ThreadCleanup(OSThread *thread, void *stack) {
281270}
282271
283272static void WIIUAUDIO_DetectDevices (void ) {
284- void * drcHandle ;
285- void * tvHandle ;
286- void * mirrorHandle ;
287-
288273 /* This gets reset later anyways */
289274 SDL_AudioSpec spec ;
290275
@@ -294,7 +279,7 @@ static void WIIUAUDIO_DetectDevices(void) {
294279
295280 SDL_CalculateAudioSpec (& spec );
296281
297- SDL_AddAudioDevice (SDL_FALSE , SDL_AUDIO_DEVICE_WIIU_MIRRORED , & spec , & mirrorHandle );
282+ SDL_AddAudioDevice (SDL_FALSE , SDL_AUDIO_DEVICE_WIIU_MIRRORED , & spec , & mirroredHandle );
298283 SDL_AddAudioDevice (SDL_FALSE , SDL_AUDIO_DEVICE_WIIU_TV , & spec , & tvHandle );
299284 SDL_AddAudioDevice (SDL_FALSE , SDL_AUDIO_DEVICE_WIIU_GAMEPAD , & spec , & drcHandle );
300285}
@@ -308,13 +293,11 @@ static int WIIUAUDIO_OpenDevice(_THIS, const char *devname) {
308293
309294 deviceType = WIIU_DEVICE_MIRRORED ;
310295
311- if (devname != NULL ) {
312- if (SDL_strcmp (devname , SDL_AUDIO_DEVICE_WIIU_TV ) == 0 ) {
313- deviceType = WIIU_DEVICE_TV ;
314- }
315- else if (SDL_strcmp (devname , SDL_AUDIO_DEVICE_WIIU_GAMEPAD ) == 0 ) {
316- deviceType = WIIU_DEVICE_GAMEPAD ;
317- }
296+ if (this -> handle == & tvHandle ) {
297+ deviceType = WIIU_DEVICE_TV ;
298+ }
299+ else if (this -> handle == & drcHandle ) {
300+ deviceType = WIIU_DEVICE_GAMEPAD ;
318301 }
319302
320303 /* AX functions need to run from the same core.
@@ -498,13 +481,10 @@ static Uint8* WIIUAUDIO_GetDeviceBuf(_THIS) {
498481}
499482
500483static void WIIUAUDIO_CloseDevice (_THIS ) {
501- if ((AXIsInit ()) && (deviceCount < 1 )) {
502- AXDeregisterAppFrameCallback (_WIIUAUDIO_framecallback );
503- for (int i = 0 ; i < SIZEOF_ARR (this -> hidden -> voice ); i ++ ) {
504- if (this -> hidden -> voice [i ]) {
505- AXFreeVoice (this -> hidden -> voice [i ]);
506- this -> hidden -> voice [i ] = NULL ;
507- }
484+ for (int i = 0 ; i < SIZEOF_ARR (this -> hidden -> voice ); i ++ ) {
485+ if (this -> hidden -> voice [i ]) {
486+ AXFreeVoice (this -> hidden -> voice [i ]);
487+ this -> hidden -> voice [i ] = NULL ;
508488 }
509489 }
510490
@@ -531,6 +511,18 @@ static void WIIUAUDIO_Deinitialize(void) {
531511}
532512
533513static SDL_bool WIIUAUDIO_Init (SDL_AudioDriverImpl * impl ) {
514+ /* Take a quick aside to init the wiiu audio */
515+ if (!AXIsInit ()) {
516+ /* Init the AX audio engine */
517+ AXInitParams initparams = {
518+ .renderer = AX_INIT_RENDERER_48KHZ ,
519+ .pipeline = AX_INIT_PIPELINE_SINGLE ,
520+ };
521+ AXInitWithParams (& initparams );
522+ } else printf ("DEBUG: AX already up?\n" );
523+
524+ AXRegisterAppFrameCallback (_WIIUAUDIO_framecallback );
525+
534526 impl -> DetectDevices = WIIUAUDIO_DetectDevices ;
535527 impl -> OpenDevice = WIIUAUDIO_OpenDevice ;
536528 impl -> PlayDevice = WIIUAUDIO_PlayDevice ;
0 commit comments