commit 403f4adb41e9023efe1dd678f8b72a2dfec87d41
parent bba382726f4f4111105fc170d50c9fc0d5d49443
Author: Matt Demanett <matt@demanett.net>
Date: Sun, 20 May 2018 21:57:15 -0500
Additator: fix interaction of high filter with with high partial count (would yield silence).
Diffstat:
4 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/Additator.cpp b/src/Additator.cpp
@@ -60,6 +60,7 @@ void Additator::step() {
float multiple = 1.0f;
_oscillator.setPartialFrequencyRatio(1, multiple);
+ _activePartials = 1;
for (int i = 2, n = _oscillator.partialCount(); i <= n; ++i) {
float ii = i;
if (i % 2 == 0) {
@@ -68,7 +69,9 @@ void Additator::step() {
else {
ii += _oddSkew;
}
- _oscillator.setPartialFrequencyRatio(i, powf(ii, _width));
+ if (_oscillator.setPartialFrequencyRatio(i, powf(ii, _width))) {
+ _activePartials = i;
+ }
}
}
@@ -94,9 +97,10 @@ void Additator::step() {
float as[maxPartials + 1];
float total = as[1] = 1.0f;
filter = log10f(_filter) + 1.0f;
+ int np = std::min(_partials, _activePartials);
for (int i = 2, n = _oscillator.partialCount(); i <= n; ++i) {
as[i] = 0.0f;
- if (i <= _partials) {
+ if (i <= np) {
as[i] = powf(i, -_decay) * powf(_filter, i);
if (i % 2 == 0) {
if (_balance > 0.0f) {
@@ -111,7 +115,7 @@ void Additator::step() {
total += as[i];
}
}
- float norm = std::max(_partials / (float)_oscillator.partialCount(), 0.1f);
+ float norm = std::max(np / (float)_oscillator.partialCount(), 0.1f);
norm = 1.0f + (_amplitudeNormalization - 1.0f) * norm;
norm = std::max(total / norm, 0.7f);
for (int i = 1, n = _oscillator.partialCount(); i <= n; ++i) {
diff --git a/src/Additator.hpp b/src/Additator.hpp
@@ -81,6 +81,7 @@ struct Additator : Module {
float _filter = 0.0f;
Phase _phase = PHASE_RESET;
float _maxFrequency = 0.0f;
+ int _activePartials = 1;
SineBankOscillator _oscillator;
PositiveZeroCrossing _syncTrigger;
SlewLimiter _widthSL;
diff --git a/src/dsp/oscillator.cpp b/src/dsp/oscillator.cpp
@@ -230,13 +230,16 @@ void SineBankOscillator::setPartial(int i, float frequencyRatio, float amplitude
setPartialAmplitude(i, amplitude);
}
-void SineBankOscillator::setPartialFrequencyRatio(int i, float frequencyRatio) {
+bool SineBankOscillator::setPartialFrequencyRatio(int i, float frequencyRatio) {
if (i <= (int)_partials.size()) {
Partial& p = _partials[i - 1];
p.frequencyRatio = frequencyRatio;
- p.frequency = _frequency * frequencyRatio;
- p.sine.setFrequency((double)_frequency * (double)frequencyRatio);
+ double f = (double)_frequency * (double)frequencyRatio;
+ p.frequency = f;
+ p.sine.setFrequency(f);
+ return f < _maxPartialFrequency;
}
+ return false;
}
void SineBankOscillator::setPartialAmplitude(int i, float amplitude, bool envelope) {
diff --git a/src/dsp/oscillator.hpp b/src/dsp/oscillator.hpp
@@ -318,7 +318,7 @@ struct SineBankOscillator : Oscillator {
// one-based indexes.
void setPartial(int i, float frequencyRatio, float amplitude);
- void setPartialFrequencyRatio(int i, float frequencyRatio);
+ bool setPartialFrequencyRatio(int i, float frequencyRatio);
void setPartialAmplitude(int i, float amplitude, bool envelope = false);
void syncToPhase(float phase);