Skip to content

Commit

Permalink
Notify FX on sample rate changes
Browse files Browse the repository at this point in the history
This allows FX which cache the sample rate for various
reasons (notably Airwindows to avoid a link cycle) to
get updated correctly. This is especially important in
the standalone startup path.

Closes surge-synthesizer#5353
  • Loading branch information
baconpaul committed Nov 10, 2021
1 parent 2582176 commit 0694cb8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/common/SurgeSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,14 @@ void SurgeSynthesizer::setSamplerate(float sr)
{
storage.setSamplerate(sr);
sinus.set_rate(1000.0 * dsamplerate_inv);

for (const auto &f : fx)
{
if (f)
{
f->sampleRateReset();
}
}
}

//-------------------------------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/common/dsp/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class alignas(16) Effect
virtual void suspend() { return; }
float vu[KNumVuSlots]; // stereo pairs, just use every other when mono

// Most of the fx read the sample rate at sample time but airwindows
// keeps a cache so give loaded fx a notice when the sample rate cahnges
virtual void sampleRateReset() {}

virtual void handleStreamingMismatches(int streamingRevision, int currentSynthStreamingRevision)
{
// No-op here.
Expand Down
8 changes: 8 additions & 0 deletions src/common/dsp/effects/airwindows/AirWindowsEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ class alignas(16) AirWindowsEffect : public Effect
std::unique_ptr<AirWinBaseClass> airwin;
int lastSelected = -1;

void sampleRateReset() override
{
if (airwin)
{
airwin->sr = samplerate;
}
}

static std::vector<AirWinBaseClass::Registration> fxreg;
static std::vector<int> fxregOrdering;

Expand Down

0 comments on commit 0694cb8

Please sign in to comment.