Skip to content

Commit

Permalink
Fix two AEG problems in oversample and 0 rate mode (#1393)
Browse files Browse the repository at this point in the history
- In 0 rate mode we would improperly skip sectinos nw I have
  fixed the exp timing blowing out the behavior. Do a variety
  of things to skip ahead properly to the first active stage

- The OS AEG had the wrong sample rate. This meant with OS on
  the AEG went twice as fast.

Fix both and close #1389
  • Loading branch information
baconpaul authored Sep 29, 2024
1 parent 02099ff commit d7fce38
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libs/sst/sst-basic-blocks
2 changes: 2 additions & 0 deletions src/engine/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ void Group::onSampleRateChanged()

for (auto &z : zones)
z->setSampleRate(getSampleRate(), getSampleRateInv());

this->setHasModulatorsSampleRate(getSampleRate(), getSampleRateInv());
}

void Group::onProcessorTypeChanged(int w, dsp::processor::ProcessorType t)
Expand Down
18 changes: 16 additions & 2 deletions src/modulation/has_modulators.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,19 @@ static_assert(egsPerGroup == egsPerZone,
"If this is false you need to template out the count below");
template <typename T> struct HasModulators
{
HasModulators(T *that) : eg{that, that}, egOS{that, that} {}
struct DoubleRate
{
double sampleRate, sampleRateInv;
T *that{nullptr};
DoubleRate(T *that) : that(that) { resetRates(); }
void resetRates()
{
sampleRate = that->sampleRate * 2;
sampleRateInv = that->sampleRateInv / 2;
}
} doubleRate;

HasModulators(T *that) : eg{that, that}, doubleRate{that}, egOS{&doubleRate, &doubleRate} {}

static constexpr uint16_t lfosPerObject{lfosPerZone};
static constexpr uint16_t egsPerObject{egsPerZone};
Expand All @@ -66,14 +78,16 @@ template <typename T> struct HasModulators
ahdsrenv_t;

typedef sst::basic_blocks::modulators::AHDSRShapedSC<
T, blockSize << 1, sst::basic_blocks::modulators::TwentyFiveSecondExp>
DoubleRate, (blockSize << 1), sst::basic_blocks::modulators::TwentyFiveSecondExp>
ahdsrenvOS_t;

ahdsrenv_t eg[egsPerObject];
ahdsrenvOS_t egOS[egsPerObject];

std::array<bool, lfosPerObject> lfosActive{};
std::array<bool, egsPerObject> egsActive{};

void setHasModulatorsSampleRate(double sr, double sri) { doubleRate.resetRates(); }
};
} // namespace scxt::modulation::shared
#endif // SHORTCIRCUITXT_HAS_MODULATORS_H
3 changes: 3 additions & 0 deletions src/voice/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,4 +794,7 @@ void Voice::updateTransportPhasors()
mul = mul / 2;
}
}

void Voice::onSampleRateChanged() { setHasModulatorsSampleRate(samplerate, samplerate_inv); }

} // namespace scxt::voice
2 changes: 2 additions & 0 deletions src/voice/voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ struct alignas(16) Voice : MoveableOnly<Voice>,
}
void release() { isGated = false; }
void cleanupVoice();

void onSampleRateChanged() override;
};
} // namespace scxt::voice

Expand Down

0 comments on commit d7fce38

Please sign in to comment.