diff --git a/src/instr_kick.cc b/src/instr_kick.cc index feb8f87..c5982b1 100644 --- a/src/instr_kick.cc +++ b/src/instr_kick.cc @@ -1,51 +1,76 @@ #include "instr_kick.hh" #include "daisysp.h" +#include "utils.hh" namespace Heck { namespace Instrument { - Kick::Kick() { + Kick::Kick() + { init(); } void Kick::init() { osc.Init(samplerate); - osc.SetWaveform(dsp::Oscillator::WAVE_TRI); osc.SetAmp(1); pitchEnv.Init(samplerate); pitchEnv.SetTime(dsp::ADENV_SEG_ATTACK, .001); pitchEnv.SetTime(dsp::ADENV_SEG_DECAY, .01); - pitchEnv.SetMax(250); - pitchEnv.SetMin(20); - - volEnv.Init(samplerate); - volEnv.SetTime(dsp::ADENV_SEG_ATTACK, .0001); - volEnv.SetTime(dsp::ADENV_SEG_DECAY, 0.1); - volEnv.SetMax(1); - volEnv.SetMin(0); + + + chorus.Init(samplerate); + chorus.SetDelay(0.2); + chorus.SetFeedback(0.8); + chorus.SetLfoDepth(0.2); + chorus.SetLfoFreq(7); } void Kick::trigger() { - volEnv.Trigger(); + osc.Reset(); + // volEnv.Trigger(); pitchEnv.Trigger(); } - void Kick::ctl(unsigned int ctl_nr, float val) {} - void Kick::switch_mode1(unsigned int pos) {} - void Kick::switch_mode2(unsigned int pos) {} + void Kick::ctl(unsigned int ctl_nr, float val) + { + switch (ctl_nr) { + case 0: { + float relpitch = scalen_min_max(val, 40, 400); + osc.SetFreq(relpitch); + pitchEnv.SetMax(relpitch * 0.03); + pitchEnv.SetMin(relpitch); + } break; + case 1: { +// pitchEnv.SetTime(dsp::ADSR_SEG_DECAY, scalen_min_max(val, 0.01, 0.4)); + } break; + case 2: { + osc.SetPw(scalen_min_max(val, 0, 1)); + } break; + case 3: { + chorus.SetDelay(scalen_min_max(val, 0.1, 0.9)); + } break; + } + } + void Kick::switch_mode1(unsigned int pos) + { + mode1 = pos; + } + + void Kick::switch_mode2(unsigned int pos) + { + mode2 = pos; + } + float Kick::nextsample() { - float kck_env_out = volEnv.Process(); - - osc.SetFreq(pitchEnv.Process()); - osc.SetAmp(kck_env_out); +// osc.SetFreq(pitchEnv.Process()); float osc_out = osc.Process(); - + osc_out = chorus.Process(osc_out); return osc_out; } diff --git a/src/instr_kick.hh b/src/instr_kick.hh index 1f28584..965135b 100644 --- a/src/instr_kick.hh +++ b/src/instr_kick.hh @@ -15,17 +15,17 @@ namespace Heck { public: Kick(); void init(); - void trigger() override; void ctl(unsigned int ctl_nr, float val) override; void switch_mode1(unsigned int pos) override; void switch_mode2(unsigned int pos) override; - float nextsample() override; private: dsp::Oscillator osc; - dsp::AdEnv volEnv; dsp::AdEnv pitchEnv; + dsp::Chorus chorus; + float mode1{}; + float mode2{}; }; } // namespace Instrument diff --git a/src/main_perkons.cc b/src/main_perkons.cc index 97141b6..d5d0d32 100644 --- a/src/main_perkons.cc +++ b/src/main_perkons.cc @@ -27,7 +27,7 @@ namespace Heck { static ld::MidiUartHandler midi{}; static ld::FIFO event_log{}; - Instrument::FM instrument0{}; + Instrument::Kick instrument0{}; Instrument::Grainlet instrument1{}; Instrument::FM instrument2{}; Instrument::Grainlet instrument3{};