BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

Reftone.hpp (1190B)


      1 #pragma once
      2 
      3 #include "bogaudio.hpp"
      4 #include "dsp/oscillator.hpp"
      5 #include "dsp/pitch.hpp"
      6 
      7 using namespace bogaudio::dsp;
      8 
      9 extern Model* modelReftone;
     10 
     11 namespace bogaudio {
     12 
     13 struct Reftone : BGModule {
     14 	enum ParamsIds {
     15 		PITCH_PARAM,
     16 		OCTAVE_PARAM,
     17 		FINE_PARAM,
     18 		NUM_PARAMS
     19 	};
     20 
     21 	enum InputsIds {
     22 		NUM_INPUTS
     23 	};
     24 
     25 	enum OutputsIds {
     26 		CV_OUTPUT,
     27 		OUT_OUTPUT,
     28 		NUM_OUTPUTS
     29 	};
     30 
     31 	int _pitch = 9;
     32 	int _octave = 4;
     33 	float _fine = 0.0f;
     34 	float _frequency = 440.0f;
     35 	float _cv = frequencyToCV(_frequency);
     36 	SineOscillator _sine;
     37 
     38 	Reftone() {
     39 		config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS);
     40 		configParam(PITCH_PARAM, 0.0f, 11.0f, 9.0f, "Pitch");
     41 		paramQuantities[PITCH_PARAM]->snapEnabled = true;
     42 		configParam(OCTAVE_PARAM, 1.0f, 8.0f, 4.0f, "Octave");
     43 		paramQuantities[OCTAVE_PARAM]->snapEnabled = true;
     44 		configParam(FINE_PARAM, -0.99f, 0.99f, 0.0f, "Fine tune", " cents", 0.0f, 100.0f);
     45 
     46 		configOutput(CV_OUTPUT, "Pitch (1V/octave)");
     47 		configOutput(OUT_OUTPUT, "Sine signal");
     48 
     49 		sampleRateChange();
     50 	}
     51 
     52 	void sampleRateChange() override {
     53 		_sine.setSampleRate(APP->engine->getSampleRate());
     54 	}
     55 
     56 	void processAll(const ProcessArgs& args) override;
     57 };
     58 
     59 } // namespace bogaudio