Skip to content

Commit

Permalink
fix (switch): Reinitialize audio after resuming from suspend (#388) (#…
Browse files Browse the repository at this point in the history
…389)

Co-authored-by: Nicholas Nusgart <nicknusgart@gmail.com>
  • Loading branch information
briaguya-ai and nusgart committed Nov 28, 2023
1 parent dcf78dd commit 4600eed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/audio/SDLAudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace LUS {
SDLAudioPlayer::SDLAudioPlayer() : AudioPlayer() {
}

SDLAudioPlayer::~SDLAudioPlayer() {
SPDLOG_TRACE("destruct SDL audio player");
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}

bool SDLAudioPlayer::DoInit(void) {
if (SDL_Init(SDL_INIT_AUDIO) != 0) {
SPDLOG_ERROR("SDL init error: %s\n", SDL_GetError());
Expand Down
1 change: 1 addition & 0 deletions src/audio/SDLAudioPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace LUS {
class SDLAudioPlayer : public AudioPlayer {
public:
SDLAudioPlayer();
~SDLAudioPlayer();

int Buffered(void);
int GetDesiredBuffered(void);
Expand Down
13 changes: 11 additions & 2 deletions src/port/switch/SwitchImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <SDL2/SDL.h>
#include "SwitchPerformanceProfiles.h"
#include "public/bridge/consolevariablebridge.h"
#include <spdlog/spdlog.h>
#include "Context.h"
#include "audio/Audio.h"

#include <ImGui/imgui_internal.h>

Expand Down Expand Up @@ -165,8 +168,14 @@ static void on_applet_hook(AppletHookType hook, void* param) {
clkrstSetClockRate(&session, SWITCH_CPU_SPEEDS_VALUES[LUS::STOCK]);
clkrstCloseSession(&session);
}
} else
} else {
LUS::Switch::ApplyOverclock();
// reinitialize audio subsystem to fix audio problems after resuming from sleep
// see https://github.com/HarbourMasters/Shipwright/issues/3317
SPDLOG_INFO("restarting SDL audio system to work around audio problems on resume");
LUS::Context::GetInstance()->GetAudio()->SetAudioBackend(LUS::AudioBackend::SDL);
}

break;

/* Performance mode */
Expand Down Expand Up @@ -216,4 +225,4 @@ void LUS::Switch::ThrowMissingOTR(std::string OTRPath) {
"\x1b[44;2H%s.",
OTRPath.c_str(), RandomTexts[rand() % 25]);
}
#endif
#endif

0 comments on commit 4600eed

Please sign in to comment.