commit a06d40e176c801c4aa44a1222d5b34babb8b54a0
parent 3135cf51017c5f9b4651c44674f02f2e59ff112b
Author: Matt Demanett <matt@demanett.net>
Date: Tue, 1 Oct 2019 18:16:00 -0400
Poly: in vcos and lfos, sync phase of new engine when created to primary engine.
Diffstat:
10 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/src/Additator.cpp b/src/Additator.cpp
@@ -44,6 +44,9 @@ void Additator::addEngine(int c) {
_engines[c] = new Engine();
_engines[c]->reset();
_engines[c]->sampleRateChange();
+ if (c > 0) {
+ _engines[c]->oscillator.syncTo(_engines[0]->oscillator);
+ }
}
void Additator::removeEngine(int c) {
diff --git a/src/EightFO.cpp b/src/EightFO.cpp
@@ -53,6 +53,9 @@ void EightFO::addEngine(int c) {
_engines[c] = new Engine();
_engines[c]->reset();
_engines[c]->sampleRateChange();
+ if (c > 0) {
+ _engines[c]->phasor.syncPhase(_engines[0]->phasor);
+ }
}
void EightFO::removeEngine(int c) {
diff --git a/src/FMOp.cpp b/src/FMOp.cpp
@@ -91,6 +91,9 @@ void FMOp::addEngine(int c) {
_engines[c] = new Engine();
_engines[c]->reset();
_engines[c]->sampleRateChange();
+ if (c > 0) {
+ _engines[c]->phasor.syncPhase(_engines[0]->phasor);
+ }
}
void FMOp::removeEngine(int c) {
diff --git a/src/LFO.cpp b/src/LFO.cpp
@@ -41,6 +41,9 @@ void LFO::addEngine(int c) {
_engines[c] = new Engine();
_engines[c]->reset();
_engines[c]->sampleRateChange();
+ if (c > 0) {
+ _engines[c]->phasor.syncPhase(_engines[0]->phasor);
+ }
}
void LFO::removeEngine(int c) {
diff --git a/src/LLFO.cpp b/src/LLFO.cpp
@@ -21,6 +21,12 @@ int LLFO::channels() {
return std::max(1, inputs[PITCH_INPUT].getChannels());
}
+void LLFO::addEngine(int c) {
+ if (c > 0) {
+ _phasor[c].syncPhase(_phasor[0]);
+ }
+}
+
void LLFO::modulate() {
_invert = false;
Wave wave = (Wave)params[WAVE_PARAM].getValue();
diff --git a/src/LLFO.hpp b/src/LLFO.hpp
@@ -83,6 +83,7 @@ struct LLFO : LFOBase {
void sampleRateChange() override;
bool active() override;
int channels() override;
+ void addEngine(int c) override;
void modulate() override;
void modulateChannel(int c) override;
void always(const ProcessArgs& args) override;
diff --git a/src/VCO.cpp b/src/VCO.cpp
@@ -62,6 +62,9 @@ void VCO::addEngine(int c) {
_engines[c] = new Engine();
_engines[c]->reset();
_engines[c]->sampleRateChange(APP->engine->getSampleRate());
+ if (c > 0) {
+ _engines[c]->phasor.syncPhase(_engines[0]->phasor);
+ }
}
void VCO::removeEngine(int c) {
diff --git a/src/XCO.cpp b/src/XCO.cpp
@@ -74,6 +74,9 @@ void XCO::addEngine(int c) {
_engines[c] = new Engine();
_engines[c]->reset();
_engines[c]->sampleRateChange(APP->engine->getSampleRate());
+ if (c > 0) {
+ _engines[c]->phasor.syncPhase(_engines[0]->phasor);
+ }
}
void XCO::removeEngine(int c) {
diff --git a/src/dsp/oscillator.cpp b/src/dsp/oscillator.cpp
@@ -29,6 +29,10 @@ void Phasor::setPhase(float radians) {
_phase = radiansToPhase(radians);
}
+void Phasor::syncPhase(const Phasor& phasor) {
+ _phase = phasor._phase;
+}
+
float Phasor::nextFromPhasor(const Phasor& phasor, phase_delta_t offset) {
offset += phasor._phase;
if (_samplePhase > 0) {
@@ -267,6 +271,12 @@ void SineBankOscillator::syncToPhase(float phase) {
}
}
+void SineBankOscillator::syncTo(const SineBankOscillator& other) {
+ for (int i = 0, n = std::min(_partials.size(), other._partials.size()); i < n; ++i) {
+ _partials[i].sine.syncPhase(other._partials[i].sine);
+ }
+}
+
void SineBankOscillator::_sampleRateChanged() {
_maxPartialFrequency = _maxPartialFrequencySRRatio * _sampleRate;
_amplitudeEnvelopeSamples = _sampleRate * (_amplitudeEnvelopeMS / 1000.0f);
diff --git a/src/dsp/oscillator.hpp b/src/dsp/oscillator.hpp
@@ -89,6 +89,7 @@ struct Phasor : OscillatorGenerator {
void setSampleWidth(float sw);
void resetPhase();
void setPhase(float radians);
+ void syncPhase(const Phasor& phasor);
float nextFromPhasor(const Phasor& phasor, phase_delta_t offset = 0);
inline float nextForPhase(phase_t phase) { return _nextForPhase(phase); }
virtual void _update();
@@ -324,6 +325,7 @@ struct SineBankOscillator : Oscillator {
void setPartialAmplitude(int i, float amplitude, bool envelope = false);
void syncToPhase(float phase);
+ void syncTo(const SineBankOscillator& other);
void _sampleRateChanged() override;
void _frequencyChanged() override;