Audio: Allow adjusting BGS and SE volumes via mkxp.conf

This commit is contained in:
Ancurio 2021-09-30 00:28:37 +02:00
parent 24efc4d2f2
commit 9cf5ee54e0
6 changed files with 17 additions and 2 deletions

View File

@ -73,6 +73,8 @@ struct AudioPrivate
meWatch.state = MeNotPlaying; meWatch.state = MeNotPlaying;
meWatch.thread = createSDLThread meWatch.thread = createSDLThread
<AudioPrivate, &AudioPrivate::meWatchFun>(this, "audio_mewatch"); <AudioPrivate, &AudioPrivate::meWatchFun>(this, "audio_mewatch");
bgs.setVolume(AudioStream::Config, rtData.config.volume.bgs);
} }
~AudioPrivate() ~AudioPrivate()

View File

@ -49,6 +49,7 @@ struct AudioStream
FadeOut, FadeOut,
FadeIn, FadeIn,
External, External,
Config,
VolumeTypeCount VolumeTypeCount
}; };

View File

@ -183,6 +183,8 @@ void Config::read(int argc, char *argv[])
PO_DESC(midi.chorus, bool, false) \ PO_DESC(midi.chorus, bool, false) \
PO_DESC(midi.reverb, bool, false) \ PO_DESC(midi.reverb, bool, false) \
PO_DESC(SE.sourceCount, int, 6) \ 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(customScript, std::string, "") \
PO_DESC(pathCache, bool, true) \ PO_DESC(pathCache, bool, true) \
PO_DESC(useScriptNames, bool, false) PO_DESC(useScriptNames, bool, false)

View File

@ -84,6 +84,12 @@ struct Config
int sourceCount; int sourceCount;
} SE; } SE;
struct
{
float bgs;
float se;
} volume;
bool useScriptNames; bool useScriptNames;
std::string customScript; std::string customScript;

View File

@ -93,7 +93,8 @@ SoundEmitter::SoundEmitter(const Config &conf)
srcCount(conf.SE.sourceCount), srcCount(conf.SE.sourceCount),
alSrcs(srcCount), alSrcs(srcCount),
atchBufs(srcCount), atchBufs(srcCount),
srcPrio(srcCount) srcPrio(srcCount),
configVolume(conf.volume.se)
{ {
for (size_t i = 0; i < srcCount; ++i) for (size_t i = 0; i < srcCount; ++i)
{ {
@ -172,7 +173,7 @@ void SoundEmitter::play(const std::string &filename,
if (switchBuffer) if (switchBuffer)
AL::Source::attachBuffer(src, buffer->alBuffer); 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::setPitch(src, _pitch);
AL::Source::play(src); AL::Source::play(src);

View File

@ -49,6 +49,9 @@ struct SoundEmitter
/* Indices of sources, sorted by priority (lowest first) */ /* Indices of sources, sorted by priority (lowest first) */
std::vector<size_t> srcPrio; std::vector<size_t> srcPrio;
/* Constant premultiplier */
float configVolume;
SoundEmitter(const Config &conf); SoundEmitter(const Config &conf);
~SoundEmitter(); ~SoundEmitter();