From 248e4f2672d779f219c8fe3472a444596ae8110b Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 9 Jul 2012 13:59:18 +0000 Subject: [PATCH] add fmod-speaker-mode variable --- panda/src/audio/config_audio.cxx | 68 +++++++++++++++++++++- panda/src/audio/config_audio.h | 19 ++++++ panda/src/audiotraits/fmodAudioManager.cxx | 16 +++-- 3 files changed, 96 insertions(+), 7 deletions(-) diff --git a/panda/src/audio/config_audio.cxx b/panda/src/audio/config_audio.cxx index 61c34cada7..b97ce9e1ef 100644 --- a/panda/src/audio/config_audio.cxx +++ b/panda/src/audio/config_audio.cxx @@ -82,7 +82,14 @@ ConfigVariableInt fmod_number_of_sound_channels ConfigVariableBool fmod_use_surround_sound ("fmod-use-surround-sound", false, - PRC_DESC("Determines if an FMOD Flavor of PANDA use 5.1 Surround Sound or Not.") ); + PRC_DESC("Determines if an FMOD Flavor of PANDA use 5.1 Surround Sound or not. " + "This variable is deprecated and should not be used. Use the enum " + "variable fmod-speaker-mode instead.")); + +ConfigVariableEnum fmod_speaker_mode +("fmod-speaker-mode", FSM_unspecified, + PRC_DESC("Sets the speaker configuration that the FMOD sound system will use. " + "Options: raw, mono, stereo, quad, surround, 5.1, 7.1 and prologic. ")); // Config variables for Miles: @@ -116,8 +123,6 @@ ConfigVariableInt audio_output_bits ConfigVariableInt audio_output_channels ("audio-output-channels", 2); - - ConfigureFn(config_audio) { FilterProperties::init_type(); AudioLoadRequest::init_type(); @@ -127,5 +132,62 @@ ConfigureFn(config_audio) { NullAudioSound::init_type(); } +ostream & +operator << (ostream &out, FmodSpeakerMode sm) { + switch (sm) { + case FSM_raw: + return out << "raw"; + case FSM_mono: + return out << "mono"; + case FSM_stereo: + return out << "stereo"; + case FSM_quad: + return out << "quad"; + case FSM_surround: + return out << "surround"; + case FSM_5point1: + return out << "5.1"; + case FSM_7point1: + return out << "7.1"; + case FSM_prologic: + return out << "prologic"; + case FSM_unspecified: + return out; + } + return out << "**invalid FmodSpeakerMode (" << (int)sm << ")**"; +} +istream & +operator >> (istream &in, FmodSpeakerMode &sm) { + string word; + in >> word; + + if (word.size() == 0) { + sm = FSM_unspecified; + } else if (cmp_nocase(word, "raw") == 0) { + sm = FSM_raw; + } else if (cmp_nocase(word, "mono") == 0) { + sm = FSM_mono; + } else if (cmp_nocase(word, "stereo") == 0) { + sm = FSM_stereo; + } else if (cmp_nocase(word, "quad") == 0) { + sm = FSM_quad; + } else if (cmp_nocase(word, "surround") == 0) { + sm = FSM_surround; + } else if (cmp_nocase(word, "5point1") == 0 || + cmp_nocase(word, "5.1") == 0) { + sm = FSM_5point1; + } else if (cmp_nocase(word, "7point1") == 0 || + cmp_nocase(word, "7.1") == 0) { + sm = FSM_7point1; + } else if (cmp_nocase(word, "prologic") == 0) { + sm = FSM_prologic; + + } else { + gobj_cat->error() << "Invalid FmodSpeakerMode value: " << word << "\n"; + sm = FSM_unspecified; + } + + return in; +} diff --git a/panda/src/audio/config_audio.h b/panda/src/audio/config_audio.h index 1dd7c79aae..68ab186125 100644 --- a/panda/src/audio/config_audio.h +++ b/panda/src/audio/config_audio.h @@ -39,8 +39,27 @@ extern EXPCL_PANDA_AUDIO ConfigVariableString audio_library_name; // Config vars for Fmod: +// Values match FMOD_SPEAKERMODE enum. +enum FmodSpeakerMode { + FSM_raw, + FSM_mono, + FSM_stereo, + FSM_quad, + FSM_surround, + FSM_5point1, + FSM_7point1, + FSM_prologic, + + // For backward compatibility + FSM_unspecified +}; + +EXPCL_FMOD_AUDIO ostream &operator << (ostream &out, FmodSpeakerMode sm); +EXPCL_FMOD_AUDIO istream &operator >> (istream &in, FmodSpeakerMode &sm); + extern EXPCL_PANDA_AUDIO ConfigVariableInt fmod_number_of_sound_channels; extern EXPCL_PANDA_AUDIO ConfigVariableBool fmod_use_surround_sound; +extern EXPCL_PANDA_AUDIO ConfigVariableEnum fmod_speaker_mode; // Config vars for OpenAL: diff --git a/panda/src/audiotraits/fmodAudioManager.cxx b/panda/src/audiotraits/fmodAudioManager.cxx index 24f15bb84c..9fde62e0b7 100644 --- a/panda/src/audiotraits/fmodAudioManager.cxx +++ b/panda/src/audiotraits/fmodAudioManager.cxx @@ -128,10 +128,18 @@ FmodAudioManager() { audio_error("You are using an old version of FMOD. This program requires:" << FMOD_VERSION); } - //Stick Surround Sound 5.1 thing Here. - if (fmod_use_surround_sound) { - audio_debug("Setting FMOD to use 5.1 Surround Sound."); - result = _system->setSpeakerMode(FMOD_SPEAKERMODE_5POINT1); + // Set speaker mode. + if (fmod_speaker_mode.get_value() == FSM_unspecified) { + if (fmod_use_surround_sound) { + // fmod-use-surround-sound is the old variable, now replaced + // by fmod-speaker-mode. This is for backward compatibility. + result = _system->setSpeakerMode(FMOD_SPEAKERMODE_5POINT1); + fmod_audio_errcheck("_system->setSpeakerMode()", result); + } + } else { + FMOD_SPEAKERMODE speakerMode; + speakerMode = (FMOD_SPEAKERMODE) fmod_speaker_mode.get_value(); + result = _system->setSpeakerMode(speakerMode); fmod_audio_errcheck("_system->setSpeakerMode()", result); }