diff --git a/src/Synth.c b/src/Synth.c index 6ae9a21..e5f34be 100644 --- a/src/Synth.c +++ b/src/Synth.c @@ -22,6 +22,8 @@ void DmSynth_init(DmSynth* slf, uint32_t sample_rate) { memset(slf, 0, sizeof *slf); slf->rate = sample_rate; + slf->volume = 1; + DmSynthFontArray_init(&slf->fonts); } @@ -82,6 +84,7 @@ static DmResult DmSynth_updateFonts(DmSynth* slf, DmBand* band) { } tsf_set_output(new_fnt.syn, TSF_STEREO_INTERLEAVED, slf->rate, 0); + tsf_set_volume(new_fnt.syn, slf->volume); rv = DmSynthFontArray_add(&slf->fonts, new_fnt); if (rv != DmResult_SUCCESS) { @@ -151,6 +154,7 @@ static DmResult DmSynth_assignInstrumentChannels(DmSynth* slf, DmBand* band) { uint32_t bank = (ins->patch & 0xFF00U) >> 8; uint32_t patch = ins->patch & 0xFFU; + tsf_set_volume(fnt->syn, slf->volume); tsf_channel_set_bank_preset(fnt->syn, ins->channel, bank, patch); // Update the instrument's properties @@ -319,6 +323,7 @@ void DmSynth_setVolume(DmSynth* slf, float vol) { return; } + slf->volume = vol; for (size_t i = 0; i < slf->fonts.length; ++i) { tsf_set_volume(slf->fonts.data[i].syn, vol); } diff --git a/src/_Internal.h b/src/_Internal.h index c6b9853..0af466d 100644 --- a/src/_Internal.h +++ b/src/_Internal.h @@ -473,6 +473,7 @@ DmArray_DEFINE(DmSynthFontArray, DmSynthFont); typedef struct DmSynth { uint32_t rate; + float volume; DmSynthFontArray fonts; size_t channels_len;