commit aeddb9f698094d2be9a39bd561408dd3a62825e6
parent 0e33dac7f99f4982aa270cf43ee9bb17d2d12a29
Author: Matt Demanett <matt@demanett.net>
Date: Wed, 7 Mar 2018 00:50:51 -0500
8FO: more work.
Diffstat:
5 files changed, 63 insertions(+), 21 deletions(-)
diff --git a/res-src/EightFO-src.svg b/res-src/EightFO-src.svg
@@ -132,25 +132,35 @@
<g transform="translate(10 0)">
<!-- <polyline points="0,19 70,19" stroke="#0f0" stroke-width="1" fill="none" /> -->
<text font-size="8pt" letter-spacing="2px" transform="translate(8 50) rotate(270)">SAM/PWM</text>
- <use id="SAMPLE_PWM_PARAM" xlink:href="#knob" transform="translate(20 0)" />
+ <use id="SAMPLE_PWM_PARAM" xlink:href="#knob-medium" transform="translate(20 0)" />
</g>
- <!-- <g transform="translate(90 0)"> -->
+ <g transform="translate(65 0)">
<!-- <polyline points="0,19 70,19" stroke="#0f0" stroke-width="1" fill="none" /> -->
- <!-- <text font-size="8pt" letter-spacing="2px" transform="translate(8 40) rotate(270)">DECAY</text> -->
- <!-- <use id="DECAY_PARAM" xlink:href="#knob" transform="translate(20 0)" /> -->
- <!-- </g> -->
+ <text font-size="8pt" letter-spacing="2px" transform="translate(8 40) rotate(270)">OFFSET</text>
+ <use id="OFFSET_PARAM" xlink:href="#knob-medium" transform="translate(20 0)" />
+ </g>
+ <g transform="translate(120 0)">
+ <!-- <polyline points="0,19 70,19" stroke="#0f0" stroke-width="1" fill="none" /> -->
+ <text font-size="8pt" letter-spacing="2px" transform="translate(8 40) rotate(270)">SCALE</text>
+ <use id="SCALE_PARAM" xlink:href="#knob-medium" transform="translate(20 0)" />
+ </g>
</g>
<g transform="translate(0 200)">
<g transform="translate(10 0)">
<rect width="30" height="40" rx="5" fill="#fafafa" />
<use id="SAMPLE_PWM_INPUT" xlink:href="#input" transform="translate(3 3)" />
- <text font-size="6pt" letter-spacing="1px" transform="translate(11.5 36)">S</text>
+ <text font-size="6pt" letter-spacing="1px" transform="translate(9 36)">SP</text>
</g>
<g transform="translate(50 0)">
- <!-- <rect width="30" height="40" rx="5" fill="#fafafa" /> -->
- <!-- <use id="WIDTH_INPUT" xlink:href="#input" transform="translate(3 3)" /> -->
- <!-- <text font-size="6pt" letter-spacing="2px" transform="translate(11.5 36)">Y</text> -->
+ <rect width="30" height="40" rx="5" fill="#fafafa" />
+ <use id="OFFSET_INPUT" xlink:href="#input" transform="translate(3 3)" />
+ <text font-size="6pt" letter-spacing="2px" transform="translate(11.5 36)">O</text>
+ </g>
+ <g transform="translate(90 0)">
+ <rect width="30" height="40" rx="5" fill="#fafafa" />
+ <use id="SCALE_INPUT" xlink:href="#input" transform="translate(3 3)" />
+ <text font-size="6pt" letter-spacing="2px" transform="translate(11.5 36)">S</text>
</g>
</g>
diff --git a/res/EightFO.svg b/res/EightFO.svg
Binary files differ.
diff --git a/src/EightFO.cpp b/src/EightFO.cpp
@@ -39,7 +39,7 @@ void EightFO::step() {
frequency = clamp(cvToFrequency(inputs[PITCH_INPUT].value), minFrequency, maxFrequency);
}
else {
- frequency = params[FREQUENCY_PARAM].value;
+ frequency = powf(params[FREQUENCY_PARAM].value, M_E) * maxFrequency;
if (_slowMode) {
frequency *= slowModeFactor;
}
@@ -55,6 +55,16 @@ void EightFO::step() {
_sampleSteps = clamp((int)(abs(params[SAMPLE_PWM_PARAM].value) * maxSampleSteps), 1, (int)maxSampleSteps);
}
+ _offset = params[OFFSET_PARAM].value;
+ if (inputs[OFFSET_INPUT].active) {
+ _offset *= clamp(inputs[OFFSET_INPUT].value / 5.0f, -1.0f, 1.0f);
+ }
+ _offset *= 5.0f;
+ _scale = params[SCALE_PARAM].value;
+ if (inputs[SCALE_INPUT].active) {
+ _scale *= clamp(inputs[SCALE_INPUT].value / 10.0f, 0.0f, 1.0f);
+ }
+
if (_resetTrigger.process(inputs[RESET_INPUT].value)) {
_phasor.setPhase(0.0f);
}
@@ -91,7 +101,7 @@ float EightFO::phaseOffset(Param& p, Input& i, float baseOffset) {
if (i.active) {
o *= clamp(i.value / 5.0f, -1.0f, 1.0f);
}
- return o + baseOffset;
+ return baseOffset - o;
}
void EightFO::updateOutput(bool useSample, Output& output, float& offset, float& sample, bool& active) {
@@ -126,7 +136,7 @@ void EightFO::updateOutput(bool useSample, Output& output, float& offset, float&
break;
}
}
- output.value = sample = amplitude * v;
+ output.value = sample = amplitude * _scale * v + _offset;
}
active = true;
}
@@ -156,6 +166,8 @@ struct EightFOWidget : ModuleWidget {
auto waveParamPosition = Vec(120.5, 50.5);
auto slowParamPosition = Vec(79.0, 94.5);
auto samplePwmParamPosition = Vec(40.5, 130.5);
+ auto offsetParamPosition = Vec(95.5, 130.5);
+ auto scaleParamPosition = Vec(150.5, 130.5);
auto phase7ParamPosition = Vec(187.0, 28.0);
auto phase6ParamPosition = Vec(187.0, 68.0);
auto phase5ParamPosition = Vec(187.0, 108.0);
@@ -166,6 +178,8 @@ struct EightFOWidget : ModuleWidget {
auto phase0ParamPosition = Vec(187.0, 308.0);
auto samplePwmInputPosition = Vec(13.0, 203.0);
+ auto offsetInputPosition = Vec(53.0, 203.0);
+ auto scaleInputPosition = Vec(93.0, 203.0);
auto phase7InputPosition = Vec(223.0, 24.0);
auto phase6InputPosition = Vec(223.0, 64.0);
auto phase5InputPosition = Vec(223.0, 104.0);
@@ -189,7 +203,14 @@ struct EightFOWidget : ModuleWidget {
auto slowLightPosition = Vec(35.0, 97.5);
// end generated by svg_widgets.rb
- addParam(ParamWidget::create<Knob38>(frequencyParamPosition, module, EightFO::FREQUENCY_PARAM, module->minFrequency, module->maxFrequency, module->maxFrequency / 10.0f));
+ addParam(ParamWidget::create<Knob38>(
+ frequencyParamPosition,
+ module,
+ EightFO::FREQUENCY_PARAM,
+ 0.0f,
+ 1.0f,
+ powf(0.1f, 1.0f/M_E)
+ ));
{
auto w = ParamWidget::create<Knob38>(waveParamPosition, module, EightFO::WAVE_PARAM, 1.0, 5.0, 5.0);
dynamic_cast<Knob*>(w)->snap = true;
@@ -197,17 +218,21 @@ struct EightFOWidget : ModuleWidget {
}
addParam(ParamWidget::create<StatefulButton9>(slowParamPosition, module, EightFO::SLOW_PARAM, 0.0, 1.0, 0.0));
addParam(ParamWidget::create<Knob26>(samplePwmParamPosition, module, EightFO::SAMPLE_PWM_PARAM, -1.0, 1.0, 0.0));
+ addParam(ParamWidget::create<Knob26>(offsetParamPosition, module, EightFO::OFFSET_PARAM, -1.0, 1.0, 0.0));
+ addParam(ParamWidget::create<Knob26>(scaleParamPosition, module, EightFO::SCALE_PARAM, 0.0, 1.0, 1.0));
- addPhaseParam(phase7ParamPosition, module, EightFO::PHASE7_PARAM, 1.75f * M_PI);
- addPhaseParam(phase6ParamPosition, module, EightFO::PHASE6_PARAM, 1.5f * M_PI);
- addPhaseParam(phase5ParamPosition, module, EightFO::PHASE5_PARAM, 1.25f * M_PI);
- addPhaseParam(phase4ParamPosition, module, EightFO::PHASE4_PARAM, M_PI);
- addPhaseParam(phase3ParamPosition, module, EightFO::PHASE3_PARAM, 0.75f * M_PI);
- addPhaseParam(phase2ParamPosition, module, EightFO::PHASE2_PARAM, 0.5f * M_PI);
- addPhaseParam(phase1ParamPosition, module, EightFO::PHASE1_PARAM, 0.25f * M_PI);
- addPhaseParam(phase0ParamPosition, module, EightFO::PHASE0_PARAM, 0.0f);
+ addPhaseParam(phase7ParamPosition, module, EightFO::PHASE7_PARAM, Phasor::phaseToRadians(module->basePhase7Offset));
+ addPhaseParam(phase6ParamPosition, module, EightFO::PHASE6_PARAM, Phasor::phaseToRadians(module->basePhase6Offset));
+ addPhaseParam(phase5ParamPosition, module, EightFO::PHASE5_PARAM, Phasor::phaseToRadians(module->basePhase5Offset));
+ addPhaseParam(phase4ParamPosition, module, EightFO::PHASE4_PARAM, Phasor::phaseToRadians(module->basePhase4Offset));
+ addPhaseParam(phase3ParamPosition, module, EightFO::PHASE3_PARAM, Phasor::phaseToRadians(module->basePhase3Offset));
+ addPhaseParam(phase2ParamPosition, module, EightFO::PHASE2_PARAM, Phasor::phaseToRadians(module->basePhase2Offset));
+ addPhaseParam(phase1ParamPosition, module, EightFO::PHASE1_PARAM, Phasor::phaseToRadians(module->basePhase1Offset));
+ addPhaseParam(phase0ParamPosition, module, EightFO::PHASE0_PARAM, Phasor::phaseToRadians(module->basePhase0Offset));
addInput(Port::create<Port24>(samplePwmInputPosition, Port::INPUT, module, EightFO::SAMPLE_PWM_INPUT));
+ addInput(Port::create<Port24>(offsetInputPosition, Port::INPUT, module, EightFO::OFFSET_INPUT));
+ addInput(Port::create<Port24>(scaleInputPosition, Port::INPUT, module, EightFO::SCALE_INPUT));
addInput(Port::create<Port24>(phase7InputPosition, Port::INPUT, module, EightFO::PHASE7_INPUT));
addInput(Port::create<Port24>(phase6InputPosition, Port::INPUT, module, EightFO::PHASE6_INPUT));
addInput(Port::create<Port24>(phase5InputPosition, Port::INPUT, module, EightFO::PHASE5_INPUT));
diff --git a/src/EightFO.hpp b/src/EightFO.hpp
@@ -23,6 +23,8 @@ struct EightFO : Module {
PHASE1_PARAM,
PHASE0_PARAM,
SLOW_PARAM,
+ OFFSET_PARAM,
+ SCALE_PARAM,
NUM_PARAMS
};
@@ -38,6 +40,8 @@ struct EightFO : Module {
PHASE0_INPUT,
PITCH_INPUT,
RESET_INPUT,
+ OFFSET_INPUT,
+ SCALE_INPUT,
NUM_INPUTS
};
@@ -86,6 +90,8 @@ struct EightFO : Module {
bool _slowMode = false;
int _sampleSteps = 1;
int _sampleStep = 0;
+ float _offset = 0.0f;
+ float _scale = 0.0f;
SchmittTrigger _resetTrigger;
Phasor _phasor;
diff --git a/src/dsp/oscillator.hpp b/src/dsp/oscillator.hpp
@@ -74,6 +74,7 @@ struct Phasor : OscillatorGenerator {
virtual float _nextForPhase(float phase);
static float radiansToPhase(float radians) { return radians / M_PI; }
+ static float phaseToRadians(float phase) { return phase * M_PI; }
};
struct SineOscillator : OscillatorGenerator {