Skip to content

Commit

Permalink
Engine: iterate through known good audio drivers before giving up
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Jun 18, 2022
1 parent 5c3a5ea commit 30b7185
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Engine/platform/base/agsplatformdriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class AGSPlatformDriver
virtual eScriptSystemOSID GetSystemOSID() = 0;
virtual void GetSystemTime(ScriptDateTime*);
virtual SetupReturnValue RunSetup(const Common::ConfigTree &cfg_in, Common::ConfigTree &cfg_out);

virtual std::vector<String> GetKnownGoodAudioDrivers() { return {}; }
// Formats message and writes to standard platform's output;
// Always adds trailing '\n' after formatted string
virtual void WriteStdOut(const char *fmt, ...);
Expand Down
9 changes: 9 additions & 0 deletions Engine/platform/base/sys_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ bool sys_audio_init(const String &driver_name)
if (!res)
Debug::Printf(kDbgMsg_Error, "Failed to initialize audio backend: %s", SDL_GetError());
}
if (!res)
{
for(const String& possible_driver : platform->GetKnownGoodAudioDrivers()) {
res = SDL_AudioInit(possible_driver.GetCStr()) == 0;
if (!res)
Debug::Printf(kDbgMsg_Error, "Failed to initialize audio driver %s; error: %s",
possible_driver.GetCStr(), SDL_GetError());
}
}
if (res)
Debug::Printf(kDbgMsg_Info, "Audio driver: %s", SDL_GetCurrentAudioDriver());
return res;
Expand Down
6 changes: 6 additions & 0 deletions Engine/platform/linux/acpllnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct AGSLinux : AGSPlatformXDGUnix {
eScriptSystemOSID GetSystemOSID() override;
int InitializeCDPlayer() override;
void ShutdownCDPlayer() override;
std::vector<String> GetKnownGoodAudioDrivers() override;
};


Expand All @@ -46,6 +47,11 @@ void AGSLinux::ShutdownCDPlayer() {
cd_exit();
}

std::vector<String> AGSLinux::GetKnownGoodAudioDrivers()
{
return {"pulseaudio", "alsa", "jack", "pipewire"};
}

AGSPlatformDriver* AGSPlatformDriver::CreateDriver()
{
return new AGSLinux();
Expand Down
6 changes: 6 additions & 0 deletions Engine/platform/windows/acplwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ struct AGSWin32 : AGSPlatformDriver {
void ResumeApplication() override;
void ValidateWindowSize(int &x, int &y, bool borderless) const override;
SDL_Surface *CreateWindowIcon() override;
std::vector<String> GetKnownGoodAudioDrivers() override;

// Returns command line argument in a UTF-8 format
String GetCommandArg(size_t arg_index) override;
Expand Down Expand Up @@ -477,6 +478,11 @@ String AGSWin32::GetCommandArg(size_t arg_index)
return arg;
}

std::vector<String> AGSWin32::GetKnownGoodAudioDrivers()
{
return {"wasapi", "directsound", "winmm"};
}

AGSPlatformDriver* AGSPlatformDriver::CreateDriver()
{
return new AGSWin32();
Expand Down

0 comments on commit 30b7185

Please sign in to comment.