Skip to content

Commit

Permalink
Fix issues with speech
Browse files Browse the repository at this point in the history
  • Loading branch information
IonAgorria committed Jun 10, 2024
1 parent d9b195b commit 982476c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Source/Game/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Source/Sound/AudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Source/Sound/AudioPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class SpeechPlayer: public AudioPlayer {
void destroySample();

public:
int channel_group = SND_GROUP_SPEECH;

SpeechPlayer();
~SpeechPlayer() override;

Expand Down
8 changes: 0 additions & 8 deletions Source/Sound/Sample.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions Source/Sound/SampleParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions Source/UserInterface/HistoryScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion Source/UserInterface/HistoryScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 7 additions & 4 deletions Source/UserInterface/OptionsMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions Source/UserInterface/PerimeterShellDisp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ void CShellIconManager::Done()
SNDEnableVoices(0 < terVoiceVolume);
speechSound->Stop();
delete speechSound;
speechSound = 0;
speechSound = nullptr;
}

cutSceneModeOn = false;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 982476c

Please sign in to comment.