Skip to content

Commit

Permalink
audio: Add separate volume for voice, close #161
Browse files Browse the repository at this point in the history
This removes on/off switches as they are redundant
and now 0% volume is considered off.

The effects/sound and voices are now split and independent,
briefing voices, task voices and ingame voices use the new volume.

Movies use the highest volume value from all 3 volumes.
  • Loading branch information
IonAgorria committed Jun 9, 2024
1 parent 3bc3302 commit a2b5f4b
Show file tree
Hide file tree
Showing 36 changed files with 519 additions and 434 deletions.
9 changes: 6 additions & 3 deletions Source/Game/MusicManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class MusicClass

bool Play(PLAY play, const char* default_fname)
{
if(!terMusicEnable)
return false;
if (terMusicVolume == 0) {
return false;
}
const char* fname = gameShell->manualData().soundTracks[play].fileName();
if(fname==NULL)
fname=default_fname;
Expand All @@ -68,7 +69,9 @@ class MusicClass

void OpenWorld()
{
if(!terMusicEnable || active)return;
if (terMusicVolume == 0 || active) {
return;
}
active=true;
on_damage=on_cluster=INT_MIN;
Play(play = PLAY_CONSTRUCTION,"RESOURCE\\Music\\construction.ogg");
Expand Down
4 changes: 2 additions & 2 deletions Source/Game/PerimeterDataChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ extern int terMipMapBlur;
int terMapReflection = 0;
int terObjectReflection = 0;

int terSoundEnable = 1;
int terMusicEnable = 1;
int terAudioEnable = 1;
float terSoundVolume = 1;
float terVoiceVolume = 1;
float terMusicVolume = 1;


Expand Down
98 changes: 50 additions & 48 deletions Source/Game/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,14 @@ void HTManager::init()

allocation_tracking("PerimeterGraphicsInit");

InitSound(IniManager("Perimeter.ini").getInt("Sound","SoundEnable"), IniManager("Perimeter.ini").getInt("Sound","MusicEnable"));
InitSound();

gameShell = new GameShell(terMissionEdit);

SetVolumeMusic(terMusicVolume);
SNDSetVoiceVolume(terVoiceVolume);
SNDSetSoundVolume(terSoundVolume);

refresh_window_size(false);

allocation_tracking("PerimeterLogicInit");
Expand Down Expand Up @@ -752,64 +757,59 @@ void HTManager::finitGraphics()

//--------------------------------

void InitSound(bool sound, bool music, bool firstTime)
void InitSound()
{
terSoundEnable = sound;
terMusicEnable = music;

int mixChannels = 30; //Default SDL_mixer is 8, DirectSound has 31
int chunkSizeFactor = 12; //1056 bytes under 2 channel 22khz 16 bits
terAudioEnable = true;
terSoundVolume = 0.75f;
terVoiceVolume = 0.75f;
terMusicVolume = 0.25f;

IniManager ini_no("Perimeter.ini", false);
ini_no.getInt("Sound","MixChannels", mixChannels);
ini_no.getInt("Sound","ChunkSize", chunkSizeFactor);
ini_no.getFloat("Sound","SoundVolume", terSoundVolume);
ini_no.getFloat("Sound","VoiceVolume", terVoiceVolume);
ini_no.getFloat("Sound","MusicVolume", terMusicVolume);

IniManager ini("Perimeter.ini");
if (firstTime) {
terSoundVolume = ini.getFloat("Sound","SoundVolume");
terMusicVolume = ini.getFloat("Sound","MusicVolume");
IniManager ini_no("Perimeter.ini", false);
ini_no.getInt("Sound","MixChannels", mixChannels);
ini_no.getInt("Sound","ChunkSize", chunkSizeFactor);
} else {
ini.putInt("Sound","SoundEnable", terSoundEnable);
ini.putInt("Sound","MusicEnable", terMusicEnable);
}
if (terRenderDevice->GetRenderSelection() == DEVICE_HEADLESS
|| check_command_line("disable_sound") != nullptr) {
terSoundEnable = terMusicEnable = false;
terAudioEnable = false;
}

if(terSoundEnable || terMusicEnable){
static int inited = 0;

SNDSetLocDataDirectory(getLocDataPath().c_str());

if(!inited){
inited = 1;
SNDSetLocDataDirectory(getLocDataPath().c_str());
SNDSetSoundDirectory("RESOURCE\\SOUNDS\\EFF\\");

SNDSetSoundDirectory("RESOURCE\\SOUNDS\\EFF\\");

if(terEnableSoundLog)
SNDEnableErrorLog("sound.txt");

if(SNDInitSound(mixChannels, chunkSizeFactor)){
SNDScriptPrmEnableAll();
} else {
terMusicEnable = false;
terSoundEnable = false;
}
}

SetVolumeMusic( terMusicVolume );
SNDSetVolume( terSoundVolume );
if (terAudioEnable) {
#ifdef PERIMETER_DEBUG_ASSERT
terEnableSoundLog = 1;
#endif
SNDEnableErrorLog(terEnableSoundLog != 0);

SND2DPanByX(1, fSoundWidthPower);
snd_listener.SetZMultiple(fSoundZMultiple);
}
if (!SNDInitSound(mixChannels, chunkSizeFactor)) {
terAudioEnable = false;
}
}

SNDEnableSound(terSoundEnable);
if (terAudioEnable) {
SNDEnableSound(0 < terSoundVolume);
SNDEnableVoices(0 < terVoiceVolume);
SNDScriptPrmEnableAll();
SND2DPanByX(1, fSoundWidthPower);
snd_listener.SetZMultiple(fSoundZMultiple);
} else {
terMusicVolume = 0.0f;
terVoiceVolume = 0.0f;
terSoundVolume = 0.0f;
SNDEnableSound(false);
SNDEnableVoices(false);
}
}

void SoundQuant()
{
if(!terSoundEnable)
if(!terAudioEnable)
return;

snd_listener.SetPos(terCamera->matrix());
Expand All @@ -822,12 +822,14 @@ void SoundQuant()

void FinitSound()
{
if(!terAudioEnable) {
return;
}

IniManager ini("Perimeter.ini");
ini.putFloat("Sound","SoundVolume", terSoundVolume);
ini.putFloat("Sound","MusicVolume", terMusicVolume);

if(!terSoundEnable && !terMusicEnable)
return;
ini.putFloat("Sound","MusicVolume", terMusicVolume);
ini.putFloat("Sound","VoiceVolume", terVoiceVolume);

SNDReleaseSound();
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Game/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void setLogicFp();
void PlayMusic(const char *str);
void SetVolumeMusic(float f);
void MusicEnable(int enable);
void InitSound(bool sound, bool music, bool firstTime = true);
void InitSound();
void SoundQuant();
void FinitSound();
void request_application_restart(std::vector<std::string>* args = nullptr);
Expand Down Expand Up @@ -43,9 +43,9 @@ extern int terGrabInput;
extern int terMapReflection;
extern int terObjectReflection;

extern int terSoundEnable; // 0,1
extern int terMusicEnable; // 0,1
extern int terAudioEnable; // 0,1
extern float terSoundVolume; // 0..1
extern float terVoiceVolume; // 0..1
extern float terMusicVolume; // 0..1

extern float terGraphicsGamma; // 0.5..2.5
Expand Down
Loading

0 comments on commit a2b5f4b

Please sign in to comment.