From 982476c767af3550826396ff85f23a275e634cbb Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Mon, 10 Jun 2024 18:44:23 +0200 Subject: [PATCH] Fix issues with speech --- Source/Game/Runtime.cpp | 2 +- Source/Sound/AudioPlayer.cpp | 2 +- Source/Sound/AudioPlayer.h | 2 ++ Source/Sound/Sample.h | 8 -------- Source/Sound/SampleParams.h | 8 ++++++++ Source/UserInterface/HistoryScene.cpp | 6 ------ Source/UserInterface/HistoryScene.h | 1 - Source/UserInterface/OptionsMenu.cpp | 11 +++++++---- Source/UserInterface/PerimeterShellDisp.cpp | 11 ++++------- 9 files changed, 23 insertions(+), 28 deletions(-) diff --git a/Source/Game/Runtime.cpp b/Source/Game/Runtime.cpp index f89330da..bb058ad7 100644 --- a/Source/Game/Runtime.cpp +++ b/Source/Game/Runtime.cpp @@ -832,7 +832,7 @@ void FinitSound() IniManager ini("Perimeter.ini"); ini.putFloat("Sound","SoundVolume", terSoundVolume); ini.putFloat("Sound","MusicVolume", terMusicVolume); - ini.putFloat("Sound","SpeechVolume", terVoiceVolume); + ini.putFloat("Sound","SpeechVolume", terSpeechVolume); ini.putFloat("Sound","VoiceVolume", terVoiceVolume); SNDReleaseSound(); diff --git a/Source/Sound/AudioPlayer.cpp b/Source/Sound/AudioPlayer.cpp index f05746a5..3105f36d 100644 --- a/Source/Sound/AudioPlayer.cpp +++ b/Source/Sound/AudioPlayer.cpp @@ -34,7 +34,7 @@ bool SpeechPlayer::OpenToPlay(const char* fname, bool cycled) { sample = SNDLoadSound(fname); if (!sample) return false; sample->looped = cycled; //Tecnically not need for speeches but whatever - sample->channel_group = SND_GROUP_SPEECH; + sample->channel_group = channel_group; sample->global_volume_select = global_volume_select; sample->volume = volume; sample->steal_channel = true; //Just in case another speech is playing diff --git a/Source/Sound/AudioPlayer.h b/Source/Sound/AudioPlayer.h index 7829512b..7eafbe4e 100644 --- a/Source/Sound/AudioPlayer.h +++ b/Source/Sound/AudioPlayer.h @@ -40,6 +40,8 @@ class SpeechPlayer: public AudioPlayer { void destroySample(); public: + int channel_group = SND_GROUP_SPEECH; + SpeechPlayer(); ~SpeechPlayer() override; diff --git a/Source/Sound/Sample.h b/Source/Sound/Sample.h index e9f88385..f64e4a9c 100644 --- a/Source/Sound/Sample.h +++ b/Source/Sound/Sample.h @@ -1,14 +1,6 @@ #ifndef PERIMETER_SAMPLE_H #define PERIMETER_SAMPLE_H -//Mixer channel groups -#define SND_GROUP_SPEECH 0 -#define SND_GROUP_EFFECTS 1 -#define SND_GROUP_EFFECTS_ONCE 2 -#define SND_GROUP_EFFECTS_LOOPED 3 - -#define SND_NO_CHANNEL -1 - #include "SampleParams.h" //Wrapper for chunk that will be freed once unused diff --git a/Source/Sound/SampleParams.h b/Source/Sound/SampleParams.h index c42b7880..c33c43bb 100644 --- a/Source/Sound/SampleParams.h +++ b/Source/Sound/SampleParams.h @@ -4,6 +4,14 @@ #ifndef PERIMETER_SAMPLEPARAMS_H #define PERIMETER_SAMPLEPARAMS_H +//Mixer channel groups +#define SND_GROUP_SPEECH 0 +#define SND_GROUP_EFFECTS 1 +#define SND_GROUP_EFFECTS_ONCE 2 +#define SND_GROUP_EFFECTS_LOOPED 3 + +#define SND_NO_CHANNEL -1 + //Which volume to use enum GLOBAL_VOLUME { GLOBAL_VOLUME_CHANNEL = 0, //Use voice or effects volume according to current channel diff --git a/Source/UserInterface/HistoryScene.cpp b/Source/UserInterface/HistoryScene.cpp index 2cfd6eb8..651491ad 100644 --- a/Source/UserInterface/HistoryScene.cpp +++ b/Source/UserInterface/HistoryScene.cpp @@ -541,12 +541,6 @@ void HistoryScene::postDraw() { scene->PostDraw(historyCamera->getCamera()); } -void HistoryScene::setupAudio() { - if (terSpeechVolume == 0) { - stopAudio(); - } -} - void HistoryScene::startAudio(const string& name) { if (!name.empty()) { stopAudio(); diff --git a/Source/UserInterface/HistoryScene.h b/Source/UserInterface/HistoryScene.h index e9f13104..cb58ed9c 100644 --- a/Source/UserInterface/HistoryScene.h +++ b/Source/UserInterface/HistoryScene.h @@ -16,7 +16,6 @@ class HistoryScene : public Commander { void init(cVisGeneric* visGeneric, bool bw, bool addBlendAlpha = true); void done(); - void setupAudio(); void quant(const Vect2f& mousePos, float dt); void preDraw(); void draw(); diff --git a/Source/UserInterface/OptionsMenu.cpp b/Source/UserInterface/OptionsMenu.cpp index 59c1619a..e7aac621 100644 --- a/Source/UserInterface/OptionsMenu.cpp +++ b/Source/UserInterface/OptionsMenu.cpp @@ -464,10 +464,15 @@ void OnComboGraphicsMode(CShellWindow* pWnd, InterfaceEventCode code, int param) } // sound -static SpeechPlayer* OptionSamplePlayer = new SpeechPlayer(); +static SpeechPlayer* OptionSamplePlayer = nullptr; bool OptionPlaySample(GLOBAL_VOLUME global_volume, float volume, const char* path) { bool started = false; + if (!OptionSamplePlayer) { + OptionSamplePlayer = new SpeechPlayer(); + //Avoid overlapping any running speech audios + OptionSamplePlayer->channel_group = SND_GROUP_EFFECTS; + } if (OptionSamplePlayer->GetVolumeSelection() != global_volume) { OptionSamplePlayer->Stop(); } @@ -502,16 +507,14 @@ void OnSliderSpeechVolume(CShellWindow* pWnd, InterfaceEventCode code, int param CSliderWindow *pSlider = (CSliderWindow*) pWnd; if ( code == EVENT_CREATEWND ) { pSlider->pos = terSpeechVolume; - historyScene.setupAudio(); - _shellIconManager.setupAudio(); } else if((code == EVENT_SLIDERUPDATE && pSlider->pos != terSpeechVolume) || code == EVENT_UNPRESSED) { terSpeechVolume = pSlider->pos; if (code == EVENT_UNPRESSED) { - historyScene.setupAudio(); _shellIconManager.setupAudio(); } std::string path = getLocDataPath(); static int i = 0; + //Avoid using briefing audios in GW since different languages may have different filenames //Select ET audio if only ET is selected bool et = terGameContentSelect == PERIMETER_ET; if (1 < i) i = 0; diff --git a/Source/UserInterface/PerimeterShellDisp.cpp b/Source/UserInterface/PerimeterShellDisp.cpp index a20bf46f..f9b9a890 100644 --- a/Source/UserInterface/PerimeterShellDisp.cpp +++ b/Source/UserInterface/PerimeterShellDisp.cpp @@ -912,7 +912,7 @@ void CShellIconManager::Done() SNDEnableVoices(0 < terVoiceVolume); speechSound->Stop(); delete speechSound; - speechSound = 0; + speechSound = nullptr; } cutSceneModeOn = false; @@ -1462,12 +1462,9 @@ void CShellIconManager::playGameOverSound(const char* path) { } void CShellIconManager::setupAudio() { - if (speechSound) { - if (terSpeechVolume == 0) { - speechSound->Stop(); - } - speechSound->SetVolumeSelection(GLOBAL_VOLUME_IGNORE); //We set volume here manually - speechSound->SetVolume(terVoiceVolume); + if (speechSound && speechSound->IsPlay()) { + //Set volume, a speech might be playing while user is adjusting + speechSound->SetVolume(terSpeechVolume); } }