Browse Source

Add override keyword everywhere, use engineGetSampleRate()

tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
b79530ae38
10 changed files with 39 additions and 39 deletions
  1. +4
    -4
      src/ADSR.cpp
  2. +4
    -4
      src/Delay.cpp
  3. +1
    -1
      src/Fundamental.hpp
  4. +3
    -3
      src/LFO.cpp
  5. +11
    -11
      src/SEQ3.cpp
  6. +8
    -8
      src/Scope.cpp
  7. +1
    -1
      src/VCA.cpp
  8. +1
    -1
      src/VCF.cpp
  9. +1
    -1
      src/VCMixer.cpp
  10. +5
    -5
      src/VCO.cpp

+ 4
- 4
src/ADSR.cpp View File

@@ -32,7 +32,7 @@ struct ADSR : Module {
ADSR() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { ADSR() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {
trigger.setThresholds(0.0, 1.0); trigger.setThresholds(0.0, 1.0);
} }
void step();
void step() override;
}; };




@@ -62,7 +62,7 @@ void ADSR::step() {
env = sustain; env = sustain;
} }
else { else {
env += powf(base, 1 - decay) / maxTime * (sustain - env) / gSampleRate;
env += powf(base, 1 - decay) / maxTime * (sustain - env) / engineGetSampleRate();
} }
} }
else { else {
@@ -72,7 +72,7 @@ void ADSR::step() {
env = 1.0; env = 1.0;
} }
else { else {
env += powf(base, 1 - attack) / maxTime * (1.01 - env) / gSampleRate;
env += powf(base, 1 - attack) / maxTime * (1.01 - env) / engineGetSampleRate();
} }
if (env >= 1.0) { if (env >= 1.0) {
env = 1.0; env = 1.0;
@@ -86,7 +86,7 @@ void ADSR::step() {
env = 0.0; env = 0.0;
} }
else { else {
env += powf(base, 1 - release) / maxTime * (0.0 - env) / gSampleRate;
env += powf(base, 1 - release) / maxTime * (0.0 - env) / engineGetSampleRate();
} }
decaying = false; decaying = false;
} }


+ 4
- 4
src/Delay.cpp View File

@@ -36,7 +36,7 @@ struct Delay : Module {


Delay() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {} Delay() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}


void step();
void step() override;
}; };




@@ -49,7 +49,7 @@ void Delay::step() {
// Compute delay time in seconds // Compute delay time in seconds
float delay = 1e-3 * powf(10.0 / 1e-3, clampf(params[TIME_PARAM].value + inputs[TIME_INPUT].value / 10.0, 0.0, 1.0)); float delay = 1e-3 * powf(10.0 / 1e-3, clampf(params[TIME_PARAM].value + inputs[TIME_INPUT].value / 10.0, 0.0, 1.0));
// Number of delay samples // Number of delay samples
float index = delay * gSampleRate;
float index = delay * engineGetSampleRate();


// TODO This is a horrible digital delay algorithm. Rewrite later. // TODO This is a horrible digital delay algorithm. Rewrite later.


@@ -92,11 +92,11 @@ void Delay::step() {
// TODO Make it sound better // TODO Make it sound better
float color = clampf(params[COLOR_PARAM].value + inputs[COLOR_INPUT].value / 10.0, 0.0, 1.0); float color = clampf(params[COLOR_PARAM].value + inputs[COLOR_INPUT].value / 10.0, 0.0, 1.0);
float lowpassFreq = 10000.0 * powf(10.0, clampf(2.0*color, 0.0, 1.0)); float lowpassFreq = 10000.0 * powf(10.0, clampf(2.0*color, 0.0, 1.0));
lowpassFilter.setCutoff(lowpassFreq / gSampleRate);
lowpassFilter.setCutoff(lowpassFreq / engineGetSampleRate());
lowpassFilter.process(wet); lowpassFilter.process(wet);
wet = lowpassFilter.lowpass(); wet = lowpassFilter.lowpass();
float highpassFreq = 10.0 * powf(100.0, clampf(2.0*color - 1.0, 0.0, 1.0)); float highpassFreq = 10.0 * powf(100.0, clampf(2.0*color - 1.0, 0.0, 1.0));
highpassFilter.setCutoff(highpassFreq / gSampleRate);
highpassFilter.setCutoff(highpassFreq / engineGetSampleRate());
highpassFilter.process(wet); highpassFilter.process(wet);
wet = highpassFilter.highpass(); wet = highpassFilter.highpass();




+ 1
- 1
src/Fundamental.hpp View File

@@ -52,5 +52,5 @@ struct ScopeWidget : ModuleWidget {


struct SEQ3Widget : ModuleWidget { struct SEQ3Widget : ModuleWidget {
SEQ3Widget(); SEQ3Widget();
Menu *createContextMenu();
Menu *createContextMenu() override;
}; };

+ 3
- 3
src/LFO.cpp View File

@@ -95,7 +95,7 @@ struct LFO : Module {
float lights[1] = {}; float lights[1] = {};


LFO() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {} LFO() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}
void step();
void step() override;
}; };




@@ -104,7 +104,7 @@ void LFO::step() {
generator.setPulseWidth(params[PW_PARAM].value + params[PWM_PARAM].value * inputs[PW_INPUT].value / 10.0); generator.setPulseWidth(params[PW_PARAM].value + params[PWM_PARAM].value * inputs[PW_INPUT].value / 10.0);
generator.offset = (params[OFFSET_PARAM].value > 0.0); generator.offset = (params[OFFSET_PARAM].value > 0.0);
generator.invert = (params[INVERT_PARAM].value <= 0.0); generator.invert = (params[INVERT_PARAM].value <= 0.0);
generator.step(1.0 / gSampleRate);
generator.step(1.0 / engineGetSampleRate());
generator.setReset(inputs[RESET_INPUT].value); generator.setReset(inputs[RESET_INPUT].value);


outputs[SIN_OUTPUT].value = 5.0 * generator.sin(); outputs[SIN_OUTPUT].value = 5.0 * generator.sin();
@@ -189,7 +189,7 @@ void LFO2::step() {
generator.setPitch(params[FREQ_PARAM].value + params[FM_PARAM].value * inputs[FM_INPUT].value); generator.setPitch(params[FREQ_PARAM].value + params[FM_PARAM].value * inputs[FM_INPUT].value);
generator.offset = (params[OFFSET_PARAM].value > 0.0); generator.offset = (params[OFFSET_PARAM].value > 0.0);
generator.invert = (params[INVERT_PARAM].value <= 0.0); generator.invert = (params[INVERT_PARAM].value <= 0.0);
generator.step(1.0 / gSampleRate);
generator.step(1.0 / engineGetSampleRate());
generator.setReset(inputs[RESET_INPUT].value); generator.setReset(inputs[RESET_INPUT].value);


float wave = params[WAVE_PARAM].value + inputs[WAVE_INPUT].value; float wave = params[WAVE_PARAM].value + inputs[WAVE_INPUT].value;


+ 11
- 11
src/SEQ3.cpp View File

@@ -57,9 +57,9 @@ struct SEQ3 : Module {
float gateLights[8] = {}; float gateLights[8] = {};


SEQ3() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {} SEQ3() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}
void step();
void step() override;


json_t *toJson() {
json_t *toJson() override {
json_t *rootJ = json_object(); json_t *rootJ = json_object();


// running // running
@@ -80,7 +80,7 @@ struct SEQ3 : Module {
return rootJ; return rootJ;
} }


void fromJson(json_t *rootJ) {
void fromJson(json_t *rootJ) override {
// running // running
json_t *runningJ = json_object_get(rootJ, "running"); json_t *runningJ = json_object_get(rootJ, "running");
if (runningJ) if (runningJ)
@@ -102,13 +102,13 @@ struct SEQ3 : Module {
gateMode = (GateMode)json_integer_value(gateModeJ); gateMode = (GateMode)json_integer_value(gateModeJ);
} }


void initialize() {
void initialize() override {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
gateState[i] = false; gateState[i] = false;
} }
} }


void randomize() {
void randomize() override {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
gateState[i] = (randomf() > 0.5); gateState[i] = (randomf() > 0.5);
} }
@@ -137,7 +137,7 @@ void SEQ3::step() {
else { else {
// Internal clock // Internal clock
float clockTime = powf(2.0, params[CLOCK_PARAM].value + inputs[CLOCK_INPUT].value); float clockTime = powf(2.0, params[CLOCK_PARAM].value + inputs[CLOCK_INPUT].value);
phase += clockTime / gSampleRate;
phase += clockTime / engineGetSampleRate();
if (phase >= 1.0) { if (phase >= 1.0) {
phase -= 1.0; phase -= 1.0;
nextStep = true; nextStep = true;
@@ -164,9 +164,9 @@ void SEQ3::step() {
gatePulse.trigger(1e-3); gatePulse.trigger(1e-3);
} }


resetLight -= resetLight / lightLambda / gSampleRate;
resetLight -= resetLight / lightLambda / engineGetSampleRate();


bool pulse = gatePulse.process(1.0 / gSampleRate);
bool pulse = gatePulse.process(1.0 / engineGetSampleRate());


// Gate buttons // Gate buttons
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
@@ -180,7 +180,7 @@ void SEQ3::step() {
gateOn = gateOn && !pulse; gateOn = gateOn && !pulse;


outputs[GATE_OUTPUT + i].value = gateOn ? 10.0 : 0.0; outputs[GATE_OUTPUT + i].value = gateOn ? 10.0 : 0.0;
stepLights[i] -= stepLights[i] / lightLambda / gSampleRate;
stepLights[i] -= stepLights[i] / lightLambda / engineGetSampleRate();
gateLights[i] = gateState[i] ? 1.0 - stepLights[i] : stepLights[i]; gateLights[i] = gateState[i] ? 1.0 - stepLights[i] : stepLights[i];
} }


@@ -257,10 +257,10 @@ SEQ3Widget::SEQ3Widget() {
struct SEQ3GateModeItem : MenuItem { struct SEQ3GateModeItem : MenuItem {
SEQ3 *seq3; SEQ3 *seq3;
SEQ3::GateMode gateMode; SEQ3::GateMode gateMode;
void onAction() {
void onAction() override {
seq3->gateMode = gateMode; seq3->gateMode = gateMode;
} }
void step() {
void step() override {
rightText = (seq3->gateMode == gateMode) ? "âś”" : ""; rightText = (seq3->gateMode == gateMode) ? "âś”" : "";
} }
}; };


+ 8
- 8
src/Scope.cpp View File

@@ -40,16 +40,16 @@ struct Scope : Module {
SchmittTrigger resetTrigger; SchmittTrigger resetTrigger;


Scope() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {} Scope() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}
void step();
void step() override;


json_t *toJson() {
json_t *toJson() override {
json_t *rootJ = json_object(); json_t *rootJ = json_object();
json_object_set_new(rootJ, "lissajous", json_integer((int) lissajous)); json_object_set_new(rootJ, "lissajous", json_integer((int) lissajous));
json_object_set_new(rootJ, "external", json_integer((int) external)); json_object_set_new(rootJ, "external", json_integer((int) external));
return rootJ; return rootJ;
} }


void fromJson(json_t *rootJ) {
void fromJson(json_t *rootJ) override {
json_t *sumJ = json_object_get(rootJ, "lissajous"); json_t *sumJ = json_object_get(rootJ, "lissajous");
if (sumJ) if (sumJ)
lissajous = json_integer_value(sumJ); lissajous = json_integer_value(sumJ);
@@ -59,7 +59,7 @@ struct Scope : Module {
external = json_integer_value(extJ); external = json_integer_value(extJ);
} }


void initialize() {
void initialize() override {
lissajous = false; lissajous = false;
external = false; external = false;
} }
@@ -82,7 +82,7 @@ void Scope::step() {


// Compute time // Compute time
float deltaTime = powf(2.0, params[TIME_PARAM].value); float deltaTime = powf(2.0, params[TIME_PARAM].value);
int frameCount = (int)ceilf(deltaTime * gSampleRate);
int frameCount = (int)ceilf(deltaTime * engineGetSampleRate());


// Add frame to buffer // Add frame to buffer
if (bufferIndex < BUFFER_SIZE) { if (bufferIndex < BUFFER_SIZE) {
@@ -115,12 +115,12 @@ void Scope::step() {


// Reset if triggered // Reset if triggered
float holdTime = 0.1; float holdTime = 0.1;
if (resetTrigger.process(gate) || (frameIndex >= gSampleRate * holdTime)) {
if (resetTrigger.process(gate) || (frameIndex >= engineGetSampleRate() * holdTime)) {
bufferIndex = 0; frameIndex = 0; return; bufferIndex = 0; frameIndex = 0; return;
} }


// Reset if we've waited too long // Reset if we've waited too long
if (frameIndex >= gSampleRate * holdTime) {
if (frameIndex >= engineGetSampleRate() * holdTime) {
bufferIndex = 0; frameIndex = 0; return; bufferIndex = 0; frameIndex = 0; return;
} }
} }
@@ -240,7 +240,7 @@ struct ScopeDisplay : TransparentWidget {
nvgText(vg, pos.x + 22, pos.y + 11, text, NULL); nvgText(vg, pos.x + 22, pos.y + 11, text, NULL);
} }


void draw(NVGcontext *vg) {
void draw(NVGcontext *vg) override {
float gainX = powf(2.0, roundf(module->params[Scope::X_SCALE_PARAM].value)); float gainX = powf(2.0, roundf(module->params[Scope::X_SCALE_PARAM].value));
float gainY = powf(2.0, roundf(module->params[Scope::Y_SCALE_PARAM].value)); float gainY = powf(2.0, roundf(module->params[Scope::Y_SCALE_PARAM].value));
float offsetX = module->params[Scope::X_POS_PARAM].value; float offsetX = module->params[Scope::X_POS_PARAM].value;


+ 1
- 1
src/VCA.cpp View File

@@ -23,7 +23,7 @@ struct VCA : Module {
}; };


VCA() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {} VCA() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}
void step();
void step() override;
}; };






+ 1
- 1
src/VCF.cpp View File

@@ -128,7 +128,7 @@ void VCF::step() {
filter.cutoff = minCutoff * powf(maxCutoff / minCutoff, cutoffExp); filter.cutoff = minCutoff * powf(maxCutoff / minCutoff, cutoffExp);


// Push a sample to the state filter // Push a sample to the state filter
filter.process(input, 1.0/gSampleRate);
filter.process(input, 1.0/engineGetSampleRate());


// Set outputs // Set outputs
outputs[LPF_OUTPUT].value = 5.0 * filter.state[3]; outputs[LPF_OUTPUT].value = 5.0 * filter.state[3];


+ 1
- 1
src/VCMixer.cpp View File

@@ -28,7 +28,7 @@ struct VCMixer : Module {
}; };


VCMixer() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {} VCMixer() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}
void step();
void step() override;
}; };






+ 5
- 5
src/VCO.cpp View File

@@ -60,7 +60,7 @@ struct VoltageControlledOscillator {
// Adjust pitch slew // Adjust pitch slew
if (++pitchSlewIndex > 32) { if (++pitchSlewIndex > 32) {
const float pitchSlewTau = 100.0; // Time constant for leaky integrator in seconds const float pitchSlewTau = 100.0; // Time constant for leaky integrator in seconds
pitchSlew += (randomNormal() - pitchSlew / pitchSlewTau) / gSampleRate;
pitchSlew += (randomNormal() - pitchSlew / pitchSlewTau) / engineGetSampleRate();
pitchSlewIndex = 0; pitchSlewIndex = 0;
} }
} }
@@ -192,7 +192,7 @@ struct VCO : Module {
VoltageControlledOscillator<16, 16> oscillator; VoltageControlledOscillator<16, 16> oscillator;


VCO() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {} VCO() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}
void step();
void step() override;
}; };




@@ -209,7 +209,7 @@ void VCO::step() {
oscillator.setPulseWidth(params[PW_PARAM].value + params[PWM_PARAM].value * inputs[PW_INPUT].value / 10.0); oscillator.setPulseWidth(params[PW_PARAM].value + params[PWM_PARAM].value * inputs[PW_INPUT].value / 10.0);
oscillator.syncEnabled = inputs[SYNC_INPUT].active; oscillator.syncEnabled = inputs[SYNC_INPUT].active;


oscillator.process(1.0 / gSampleRate, inputs[SYNC_INPUT].value);
oscillator.process(1.0 / engineGetSampleRate(), inputs[SYNC_INPUT].value);


// Set output // Set output
if (outputs[SIN_OUTPUT].active) if (outputs[SIN_OUTPUT].active)
@@ -289,7 +289,7 @@ struct VCO2 : Module {
VoltageControlledOscillator<8, 8> oscillator; VoltageControlledOscillator<8, 8> oscillator;


VCO2() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {} VCO2() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}
void step();
void step() override;
}; };




@@ -301,7 +301,7 @@ void VCO2::step() {
oscillator.setPitch(0.0, pitchCv); oscillator.setPitch(0.0, pitchCv);
oscillator.syncEnabled = inputs[SYNC_INPUT].active; oscillator.syncEnabled = inputs[SYNC_INPUT].active;


oscillator.process(1.0 / gSampleRate, inputs[SYNC_INPUT].value);
oscillator.process(1.0 / engineGetSampleRate(), inputs[SYNC_INPUT].value);


// Set output // Set output
float wave = clampf(params[WAVE_PARAM].value + inputs[WAVE_INPUT].value, 0.0, 3.0); float wave = clampf(params[WAVE_PARAM].value + inputs[WAVE_INPUT].value, 0.0, 3.0);


Loading…
Cancel
Save