Skip to content

Commit

Permalink
Fixed|FluidSynth|Audio: Excessive lag on music volume setting
Browse files Browse the repository at this point in the history
Apply changes to music volume immediately if possible.

IssueID #2384
  • Loading branch information
skyjake committed Jan 5, 2020
1 parent 022839e commit a252587
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions doomsday/apps/plugins/fluidsynth/src/fluidsynth_music.cpp
Expand Up @@ -175,6 +175,11 @@ class RingBuffer
static RingBuffer* blockBuffer;
static float musicVolume = 1.0f;

static void setSynthGain(float vol)
{
fluid_synth_set_gain(DMFluid_Synth(), vol * MAX_SYNTH_GAIN);
}

/**
* Thread entry point for the synthesizer. Runs until the song is stopped.
* @param parm Not used.
Expand Down Expand Up @@ -275,8 +280,9 @@ static void startPlayer()

startWorker();

// Volume applied via synthesizer gain setting.
DMFluid_Sfx()->Set(sfxBuf, SFXBP_VOLUME, 1.0f);
// Volume applied immediately.
DMFluid_Sfx()->Set(sfxBuf, SFXBP_VOLUME, musicVolume);
setSynthGain(1.0f);

DMFluid_Sfx()->Play(sfxBuf);
}
Expand Down Expand Up @@ -382,7 +388,16 @@ void DM_Music_Set(int prop, float value)
{
case MUSIP_VOLUME:
musicVolume = value;
fluid_synth_set_gain(DMFluid_Synth(), musicVolume * MAX_SYNTH_GAIN);
if (sfxBuf)
{
// This will take effect immediately.
DMFluid_Sfx()->Set(sfxBuf, SFXBP_VOLUME, musicVolume);
}
else
{
// Effect will be heard only after buffered samples have been played.
setSynthGain(musicVolume);
}
DSFLUIDSYNTH_TRACE("Music_Set: MUSIP_VOLUME = " << musicVolume);
break;

Expand Down

0 comments on commit a252587

Please sign in to comment.