Skip to content

Commit

Permalink
fix(DmSynth): make sure to persist volume changes across bands
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed May 2, 2024
1 parent 7c5d1d8 commit 522dd22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ DmArray_DEFINE(DmSynthFontArray, DmSynthFont);

typedef struct DmSynth {
uint32_t rate;
float volume;
DmSynthFontArray fonts;

size_t channels_len;
Expand Down

0 comments on commit 522dd22

Please sign in to comment.