Skip to content

Commit

Permalink
Audio: Allow per SFX effect volume configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
julianxhokaxhiu committed Dec 17, 2024
1 parent 7f3739e commit a70844d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Commmon

- Music: Add the ability to play a custom `main_menu` music file on the new game screen.
- SFX: Allow effects volume to be customised per effect, using the new `volume` attribute.

# 1.21.3

Expand Down
5 changes: 4 additions & 1 deletion misc/FFNx.SFX.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# PLEASE NOTE: this flag will "fake a match" on the engine, to ensure silent
# playback so it will not be a "skip" in the sense of moving on to the
# next match.
# -----------------------------------------------------------------------------
# volume: Allow volume to be adjusted for a specific effect.
###############################################################################

# This entry will shuffle the SFX ID 1 ( menu cursor ) with the ID 2, 3 or 4.
Expand All @@ -35,4 +37,5 @@
#shuffle = [ 2, 3, 4 ]
#sequential = [ 2, 3, 4 ]
#loop = true
#skip = false
#skip = false
#volume = 50
11 changes: 10 additions & 1 deletion src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ bool NxAudioEngine::playSFX(const char* name, int id, int channel, float panning
bool skipPlay = false;
std::string _id(name);

options->volume = 1.0f * getSFXMasterVolume();

// If channel is known to be reusable
if (channel <= _sfxReusableChannels)
{
Expand Down Expand Up @@ -328,6 +330,13 @@ bool NxAudioEngine::playSFX(const char* name, int id, int channel, float panning
auto node = nxAudioEngineConfig[NxAudioEngineLayer::NXAUDIOENGINE_SFX][name];
if (node)
{
// Set volume for the current effect
toml::node *effectVolume = node["volume"].as_integer();
if (effectVolume)
{
options->volume = (effectVolume->value_or(100) / 100.0f) * getSFXMasterVolume();
}

// Shuffle SFX playback, if any entry found for the current id
toml::array *shuffleIds = node["shuffle"].as_array();
if (shuffleIds && !shuffleIds->empty() && shuffleIds->is_homogeneous(toml::node_type::integer))
Expand Down Expand Up @@ -388,7 +397,7 @@ bool NxAudioEngine::playSFX(const char* name, int id, int channel, float panning
{
options->handle = _engine.play(
*options->stream,
options->volume * getSFXMasterVolume(),
options->volume,
panning
);

Expand Down

0 comments on commit a70844d

Please sign in to comment.