Skip to content

Commit

Permalink
wiiu/audio: Restore thread affinity on early returns
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts authored and WinterMute committed Oct 27, 2023
1 parent bd5d009 commit 883dfca
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/audio/wiiu/SDL_wiiuaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static SDL_AudioDevice* cb_this;
#define next_id(id) (id + 1) % NUM_BUFFERS

static int WIIUAUDIO_OpenDevice(_THIS, const char* devname) {
int ret = 0;
AXVoiceOffsets offs;
AXVoiceVeData vol = {
.volume = 0x8000,
Expand All @@ -68,7 +69,10 @@ static int WIIUAUDIO_OpenDevice(_THIS, const char* devname) {
float srcratio;

this->hidden = (struct SDL_PrivateAudioData*)SDL_malloc(sizeof(*this->hidden));
if (this->hidden == NULL) return SDL_OutOfMemory();
if (this->hidden == NULL) {
return SDL_OutOfMemory();
}

SDL_zerop(this->hidden);

/* We *must not* change cores when setting stuff up */
Expand Down Expand Up @@ -117,7 +121,8 @@ static int WIIUAUDIO_OpenDevice(_THIS, const char* devname) {
if (this->hidden->mixbufs[i] == NULL) {
AXQuit();
printf("DEBUG: Couldn't allocate buffer");
return SDL_SetError("Couldn't allocate buffer");
ret = SDL_SetError("Couldn't allocate buffer");
goto end;
}

memset(this->hidden->mixbufs[i], 0, this->spec.size);
Expand All @@ -129,7 +134,8 @@ static int WIIUAUDIO_OpenDevice(_THIS, const char* devname) {
if (this->hidden->deintvbuf == NULL) {
AXQuit();
printf("DEBUG: Couldn't allocate deinterleave buffer");
return SDL_SetError("Couldn't allocate deinterleave buffer");
ret = SDL_SetError("Couldn't allocate deinterleave buffer");
goto end;
}


Expand All @@ -139,7 +145,8 @@ static int WIIUAUDIO_OpenDevice(_THIS, const char* devname) {
if (!this->hidden->voice[i]) {
AXQuit();
printf("DEBUG: couldn't get voice\n");
return SDL_OutOfMemory();
ret = SDL_OutOfMemory();
goto end;
}

/* Start messing with it */
Expand Down Expand Up @@ -211,9 +218,10 @@ static int WIIUAUDIO_OpenDevice(_THIS, const char* devname) {
cb_this = this; //wish there was a better way
AXRegisterAppFrameCallback(_WIIUAUDIO_framecallback);

end: ;
/* Put the thread affinity back to normal - we won't call any more AX funcs */
OSSetThreadAffinity(OSGetCurrentThread(), old_affinity);
return 0;
return ret;
}

/* Called every 3ms before a frame of audio is rendered. Keep it fast! */
Expand Down

0 comments on commit 883dfca

Please sign in to comment.