Skip to content

Commit 982476c

Browse files
committed
Fix issues with speech
1 parent d9b195b commit 982476c

9 files changed

+23
-28
lines changed

Source/Game/Runtime.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ void FinitSound()
832832
IniManager ini("Perimeter.ini");
833833
ini.putFloat("Sound","SoundVolume", terSoundVolume);
834834
ini.putFloat("Sound","MusicVolume", terMusicVolume);
835-
ini.putFloat("Sound","SpeechVolume", terVoiceVolume);
835+
ini.putFloat("Sound","SpeechVolume", terSpeechVolume);
836836
ini.putFloat("Sound","VoiceVolume", terVoiceVolume);
837837

838838
SNDReleaseSound();

Source/Sound/AudioPlayer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool SpeechPlayer::OpenToPlay(const char* fname, bool cycled) {
3434
sample = SNDLoadSound(fname);
3535
if (!sample) return false;
3636
sample->looped = cycled; //Tecnically not need for speeches but whatever
37-
sample->channel_group = SND_GROUP_SPEECH;
37+
sample->channel_group = channel_group;
3838
sample->global_volume_select = global_volume_select;
3939
sample->volume = volume;
4040
sample->steal_channel = true; //Just in case another speech is playing

Source/Sound/AudioPlayer.h

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class SpeechPlayer: public AudioPlayer {
4040
void destroySample();
4141

4242
public:
43+
int channel_group = SND_GROUP_SPEECH;
44+
4345
SpeechPlayer();
4446
~SpeechPlayer() override;
4547

Source/Sound/Sample.h

-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
#ifndef PERIMETER_SAMPLE_H
22
#define PERIMETER_SAMPLE_H
33

4-
//Mixer channel groups
5-
#define SND_GROUP_SPEECH 0
6-
#define SND_GROUP_EFFECTS 1
7-
#define SND_GROUP_EFFECTS_ONCE 2
8-
#define SND_GROUP_EFFECTS_LOOPED 3
9-
10-
#define SND_NO_CHANNEL -1
11-
124
#include "SampleParams.h"
135

146
//Wrapper for chunk that will be freed once unused

Source/Sound/SampleParams.h

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
#ifndef PERIMETER_SAMPLEPARAMS_H
55
#define PERIMETER_SAMPLEPARAMS_H
66

7+
//Mixer channel groups
8+
#define SND_GROUP_SPEECH 0
9+
#define SND_GROUP_EFFECTS 1
10+
#define SND_GROUP_EFFECTS_ONCE 2
11+
#define SND_GROUP_EFFECTS_LOOPED 3
12+
13+
#define SND_NO_CHANNEL -1
14+
715
//Which volume to use
816
enum GLOBAL_VOLUME {
917
GLOBAL_VOLUME_CHANNEL = 0, //Use voice or effects volume according to current channel

Source/UserInterface/HistoryScene.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,6 @@ void HistoryScene::postDraw() {
541541
scene->PostDraw(historyCamera->getCamera());
542542
}
543543

544-
void HistoryScene::setupAudio() {
545-
if (terSpeechVolume == 0) {
546-
stopAudio();
547-
}
548-
}
549-
550544
void HistoryScene::startAudio(const string& name) {
551545
if (!name.empty()) {
552546
stopAudio();

Source/UserInterface/HistoryScene.h

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class HistoryScene : public Commander {
1616

1717
void init(cVisGeneric* visGeneric, bool bw, bool addBlendAlpha = true);
1818
void done();
19-
void setupAudio();
2019
void quant(const Vect2f& mousePos, float dt);
2120
void preDraw();
2221
void draw();

Source/UserInterface/OptionsMenu.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,15 @@ void OnComboGraphicsMode(CShellWindow* pWnd, InterfaceEventCode code, int param)
464464
}
465465

466466
// sound
467-
static SpeechPlayer* OptionSamplePlayer = new SpeechPlayer();
467+
static SpeechPlayer* OptionSamplePlayer = nullptr;
468468

469469
bool OptionPlaySample(GLOBAL_VOLUME global_volume, float volume, const char* path) {
470470
bool started = false;
471+
if (!OptionSamplePlayer) {
472+
OptionSamplePlayer = new SpeechPlayer();
473+
//Avoid overlapping any running speech audios
474+
OptionSamplePlayer->channel_group = SND_GROUP_EFFECTS;
475+
}
471476
if (OptionSamplePlayer->GetVolumeSelection() != global_volume) {
472477
OptionSamplePlayer->Stop();
473478
}
@@ -502,16 +507,14 @@ void OnSliderSpeechVolume(CShellWindow* pWnd, InterfaceEventCode code, int param
502507
CSliderWindow *pSlider = (CSliderWindow*) pWnd;
503508
if ( code == EVENT_CREATEWND ) {
504509
pSlider->pos = terSpeechVolume;
505-
historyScene.setupAudio();
506-
_shellIconManager.setupAudio();
507510
} else if((code == EVENT_SLIDERUPDATE && pSlider->pos != terSpeechVolume) || code == EVENT_UNPRESSED) {
508511
terSpeechVolume = pSlider->pos;
509512
if (code == EVENT_UNPRESSED) {
510-
historyScene.setupAudio();
511513
_shellIconManager.setupAudio();
512514
}
513515
std::string path = getLocDataPath();
514516
static int i = 0;
517+
//Avoid using briefing audios in GW since different languages may have different filenames
515518
//Select ET audio if only ET is selected
516519
bool et = terGameContentSelect == PERIMETER_ET;
517520
if (1 < i) i = 0;

Source/UserInterface/PerimeterShellDisp.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ void CShellIconManager::Done()
912912
SNDEnableVoices(0 < terVoiceVolume);
913913
speechSound->Stop();
914914
delete speechSound;
915-
speechSound = 0;
915+
speechSound = nullptr;
916916
}
917917

918918
cutSceneModeOn = false;
@@ -1462,12 +1462,9 @@ void CShellIconManager::playGameOverSound(const char* path) {
14621462
}
14631463

14641464
void CShellIconManager::setupAudio() {
1465-
if (speechSound) {
1466-
if (terSpeechVolume == 0) {
1467-
speechSound->Stop();
1468-
}
1469-
speechSound->SetVolumeSelection(GLOBAL_VOLUME_IGNORE); //We set volume here manually
1470-
speechSound->SetVolume(terVoiceVolume);
1465+
if (speechSound && speechSound->IsPlay()) {
1466+
//Set volume, a speech might be playing while user is adjusting
1467+
speechSound->SetVolume(terSpeechVolume);
14711468
}
14721469
}
14731470

0 commit comments

Comments
 (0)