mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-15 14:18:37 +00:00
AGS: Support requesting particular audio driver
From upstream 076e675a3d031cd0a9d162f914e6d94c93a10d71
This commit is contained in:
parent
e0282d5064
commit
5060848b48
@ -25,7 +25,7 @@ namespace AGS3 {
|
||||
|
||||
GameSetup::GameSetup() {
|
||||
local_user_conf = false;
|
||||
audio_backend = 1;
|
||||
audio_enabled = true;
|
||||
no_speech_pack = false;
|
||||
textheight = 0;
|
||||
enable_antialiasing = false;
|
||||
|
@ -60,8 +60,9 @@ using AGS::Shared::String;
|
||||
// that engine may use a "config" object or combo of objects to store
|
||||
// current user config, which may also be changed from script, and saved.
|
||||
struct GameSetup {
|
||||
int audio_backend; // abstract option, currently only works as on/off
|
||||
int textheight; // text height used on the certain built-in GUI // TODO: move out to game class?
|
||||
bool audio_enabled;
|
||||
String audio_driver;
|
||||
int textheight; // text height used on the certain built-in GUI // TODO: move out to game class?
|
||||
bool no_speech_pack;
|
||||
bool enable_antialiasing;
|
||||
bool disable_exception_handling;
|
||||
|
@ -101,7 +101,7 @@ void PlayVideo(const char *name, int skip, int scr_flags) {
|
||||
flags |= kVideo_EnableAudio;
|
||||
|
||||
// if game audio is disabled, then don't play any sound on the video either
|
||||
if (_GP(usetup).audio_backend == 0)
|
||||
if (!_GP(usetup).audio_enabled)
|
||||
flags &= ~kVideo_EnableAudio;
|
||||
|
||||
if (_G(loaded_game_file_version) < kGameVersion_360_16)
|
||||
|
@ -227,8 +227,6 @@ void config_defaults() {
|
||||
// Defaults for the window style are max resizing window and "fullscreen desktop"
|
||||
_GP(usetup).Screen.FsSetup = WindowSetup(kWnd_FullDesktop);
|
||||
_GP(usetup).Screen.WinSetup = WindowSetup(kWnd_Windowed);
|
||||
_GP(usetup).audio_backend = 1;
|
||||
_GP(usetup).translation = "";
|
||||
}
|
||||
|
||||
static void read_legacy_graphics_config(const ConfigTree &cfg) {
|
||||
@ -372,7 +370,8 @@ void override_config_ext(ConfigTree &cfg) {
|
||||
|
||||
void apply_config(const ConfigTree &cfg) {
|
||||
{
|
||||
_GP(usetup).audio_backend = INIreadint(cfg, "sound", "enabled", _GP(usetup).audio_backend);
|
||||
_GP(usetup).audio_enabled = INIreadint(cfg, "sound", "enabled", _GP(usetup).audio_enabled);
|
||||
_GP(usetup).audio_driver = INIreadstring(cfg, "sound", "driver");
|
||||
|
||||
// Legacy graphics settings has to be translated into new options;
|
||||
// they must be read first, to let newer options override them, if ones are present
|
||||
|
@ -326,24 +326,22 @@ void engine_init_timer() {
|
||||
|
||||
void engine_init_audio() {
|
||||
#if !AGS_PLATFORM_SCUMMVM
|
||||
if (usetup.audio_backend != 0)
|
||||
{
|
||||
Debug::Printf("Initializing audio");
|
||||
try {
|
||||
audio_core_init(); // audio core system
|
||||
} catch(std::runtime_error) {
|
||||
Debug::Printf("Failed to initialize audio, disabling.");
|
||||
usetup.audio_backend = 0;
|
||||
}
|
||||
}
|
||||
if (usetup.audio_backend != 0) {
|
||||
Debug::Printf("Initializing audio");
|
||||
try {
|
||||
audio_core_init(); // audio core system
|
||||
} catch (std::runtime_error ex) {
|
||||
Debug::Printf(kDbgMsg_Error, "Failed to initialize audio: %s", ex.what());
|
||||
usetup.audio_backend = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
_G(our_eip) = -181;
|
||||
|
||||
if (_GP(usetup).audio_backend == 0) {
|
||||
if (!_GP(usetup).audio_enabled) {
|
||||
// all audio is disabled
|
||||
_GP(play).voice_avail = false;
|
||||
_GP(play).separate_music_lib = false;
|
||||
Debug::Printf(kDbgMsg_Info, "Audio is disabled");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "ags/engine/media/audio/sound.h"
|
||||
#include "ags/engine/debugging/debug_log.h"
|
||||
#include "ags/engine/debugging/debugger.h"
|
||||
#include "ags/engine/platform/base/sys_main.h"
|
||||
#include "ags/shared/ac/common.h"
|
||||
#include "ags/engine/ac/file.h"
|
||||
#include "ags/engine/ac/global_audio.h"
|
||||
@ -189,7 +190,7 @@ static int find_free_audio_channel(ScriptAudioClip *clip, int priority, bool int
|
||||
}
|
||||
|
||||
bool is_audiotype_allowed_to_play(AudioFileType type) {
|
||||
return _GP(usetup).audio_backend != 0;
|
||||
return _GP(usetup).audio_enabled;
|
||||
}
|
||||
|
||||
SOUNDCLIP *load_sound_clip(ScriptAudioClip *audioClip, bool repeat) {
|
||||
@ -592,6 +593,8 @@ void shutdown_sound() {
|
||||
#if !AGS_PLATFORM_SCUMMVM
|
||||
audio_core_shutdown(); // audio core system
|
||||
#endif
|
||||
sys_audio_shutdown(); // backend
|
||||
_GP(usetup).audio_enabled = false;
|
||||
}
|
||||
|
||||
// the sound will only be played if there is a free channel or
|
||||
|
@ -82,6 +82,37 @@ void sys_get_desktop_modes(std::vector<AGS::Engine::DisplayMode> &dms) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// AUDIO UTILS
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool sys_audio_init(const AGS::Shared::String &driver_name) {
|
||||
#ifdef AGS_PLATFORM_SCUMMVM
|
||||
return true;
|
||||
#else
|
||||
bool res = false;
|
||||
if (!driver_name.IsEmpty()) {
|
||||
res = SDL_AudioInit(driver_name.GetCStr()) == 0;
|
||||
if (!res)
|
||||
Debug::Printf(kDbgMsg_Error, "Failed to initialize audio driver %s; error: %s",
|
||||
driver_name.GetCStr(), SDL_GetError());
|
||||
}
|
||||
if (!res) {
|
||||
res = SDL_InitSubSystem(SDL_INIT_AUDIO) == 0;
|
||||
if (!res)
|
||||
Debug::Printf(kDbgMsg_Error, "Failed to initialize audio backend: %s", SDL_GetError());
|
||||
}
|
||||
if (res)
|
||||
Debug::Printf(kDbgMsg_Info, "Audio driver: %s", SDL_GetCurrentAudioDriver());
|
||||
return res;
|
||||
#endif
|
||||
}
|
||||
|
||||
void sys_audio_shutdown() {
|
||||
#ifndef AGS_PLATFORM_SCUMMVM
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
#endif
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// WINDOW UTILS
|
||||
|
@ -28,6 +28,7 @@
|
||||
//=============================================================================
|
||||
|
||||
#include "ags/shared/core/platform.h"
|
||||
#include "ags/shared/util/string.h"
|
||||
#include "ags/lib/std/vector.h"
|
||||
#include "ags/engine/gfx/gfx_defines.h"
|
||||
|
||||
@ -51,6 +52,13 @@ int sys_get_desktop_resolution(int &width, int &height);
|
||||
// Queries supported desktop modes.
|
||||
void sys_get_desktop_modes(std::vector<AGS::Engine::DisplayMode> &dms);
|
||||
|
||||
// Audio utilities.
|
||||
//
|
||||
// Tries to init the audio backend; optionally requests particular driver
|
||||
bool sys_audio_init(const AGS::Shared::String &driver_name = "");
|
||||
// Shutdown audio backend
|
||||
void sys_audio_shutdown();
|
||||
|
||||
// Window utilities.
|
||||
//
|
||||
struct SDL_Window;
|
||||
|
@ -599,7 +599,6 @@ int IAGSEngine::IsSpriteAlphaBlended(int32 slot) {
|
||||
// disable AGS's sound engine
|
||||
void IAGSEngine::DisableSound() {
|
||||
shutdown_sound();
|
||||
_GP(usetup).audio_backend = 0;
|
||||
}
|
||||
int IAGSEngine::CanRunScriptFunctionNow() {
|
||||
if (_G(inside_script))
|
||||
|
Loading…
Reference in New Issue
Block a user