From 9cf5ee54e0cf6f38ad08a4335ec3ea3fb94a6d38 Mon Sep 17 00:00:00 2001 From: Ancurio Date: Thu, 30 Sep 2021 00:28:37 +0200 Subject: [PATCH] Audio: Allow adjusting BGS and SE volumes via mkxp.conf --- src/audio.cpp | 2 ++ src/audiostream.h | 1 + src/config.cpp | 2 ++ src/config.h | 6 ++++++ src/soundemitter.cpp | 5 +++-- src/soundemitter.h | 3 +++ 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index 626d581..b83ffed 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -73,6 +73,8 @@ struct AudioPrivate meWatch.state = MeNotPlaying; meWatch.thread = createSDLThread (this, "audio_mewatch"); + + bgs.setVolume(AudioStream::Config, rtData.config.volume.bgs); } ~AudioPrivate() diff --git a/src/audiostream.h b/src/audiostream.h index 1f7927d..2233a50 100644 --- a/src/audiostream.h +++ b/src/audiostream.h @@ -49,6 +49,7 @@ struct AudioStream FadeOut, FadeIn, External, + Config, VolumeTypeCount }; diff --git a/src/config.cpp b/src/config.cpp index 43a6c8f..9742f9c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -183,6 +183,8 @@ void Config::read(int argc, char *argv[]) PO_DESC(midi.chorus, bool, false) \ PO_DESC(midi.reverb, bool, false) \ PO_DESC(SE.sourceCount, int, 6) \ + PO_DESC(volume.bgs, float, 1.0f) \ + PO_DESC(volume.se, float, 1.0f) \ PO_DESC(customScript, std::string, "") \ PO_DESC(pathCache, bool, true) \ PO_DESC(useScriptNames, bool, false) diff --git a/src/config.h b/src/config.h index 9e8f01a..967e1b0 100644 --- a/src/config.h +++ b/src/config.h @@ -84,6 +84,12 @@ struct Config int sourceCount; } SE; + struct + { + float bgs; + float se; + } volume; + bool useScriptNames; std::string customScript; diff --git a/src/soundemitter.cpp b/src/soundemitter.cpp index 18f1873..7a3abd4 100644 --- a/src/soundemitter.cpp +++ b/src/soundemitter.cpp @@ -93,7 +93,8 @@ SoundEmitter::SoundEmitter(const Config &conf) srcCount(conf.SE.sourceCount), alSrcs(srcCount), atchBufs(srcCount), - srcPrio(srcCount) + srcPrio(srcCount), + configVolume(conf.volume.se) { for (size_t i = 0; i < srcCount; ++i) { @@ -172,7 +173,7 @@ void SoundEmitter::play(const std::string &filename, if (switchBuffer) AL::Source::attachBuffer(src, buffer->alBuffer); - AL::Source::setVolume(src, _volume * GLOBAL_VOLUME); + AL::Source::setVolume(src, _volume * configVolume * GLOBAL_VOLUME); AL::Source::setPitch(src, _pitch); AL::Source::play(src); diff --git a/src/soundemitter.h b/src/soundemitter.h index 5156547..338e144 100644 --- a/src/soundemitter.h +++ b/src/soundemitter.h @@ -49,6 +49,9 @@ struct SoundEmitter /* Indices of sources, sorted by priority (lowest first) */ std::vector srcPrio; + /* Constant premultiplier */ + float configVolume; + SoundEmitter(const Config &conf); ~SoundEmitter();