spu2-x: stretcher: dampen the tempo adjustment to reduce resonance

I don't have a fully scientific explanation here, but it seems that with big
buffers (~200ms and up), the stretcher adjustment can overshoot the target
equilibrium back and forth, in effect never stabilizing.

This commit makes it change slightly slower which somehow seems to improve its
behavior. Sorry for not having a better explanation, as at this stage tuning the
stretcher has become somewhat of a black magic.

But hey, if it works...

Tested with buffers from 30ms to 1000ms, and with playback speed and speed
changes between 30% and 500%, and as far as I can tell it only makes it better.

Fingers crossed.
This commit is contained in:
Avi Halachmi (:avih) 2015-12-24 23:16:59 +02:00
parent 3fc9643460
commit 22c9d882a8
1 changed files with 7 additions and 0 deletions

View File

@ -197,6 +197,13 @@ void SndBuffer::UpdateTempoChangeSoundTouch2()
float tempoAdjust=bufferFullness/dynamicTargetFullness;
float avgerage = addToAvg(tempoAdjust);
tempoAdjust = avgerage;
// Dampen the adjustment to avoid overshoots (this means the average will compensate to the other side).
// This is different than simply bigger averaging window since bigger window also has bigger "momentum",
// so it's slower to slow down when it gets close to the equilibrium state and can therefore resonate.
// The dampening (sqrt was chosen for no very good reason) manages to mostly prevent that.
tempoAdjust = sqrt(tempoAdjust);
tempoAdjust = GetClamped( tempoAdjust, 0.05f, 10.0f);
if (tempoAdjust < 1)