From 8d67d6f1a6894da6ef6a46a30311c11026299694 Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 14 Sep 2024 01:20:15 +0200 Subject: [PATCH] Add instr_bd2 --- src/instr_bd2.cc | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ src/instr_bd2.hh | 32 ++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/instr_bd2.cc create mode 100644 src/instr_bd2.hh diff --git a/src/instr_bd2.cc b/src/instr_bd2.cc new file mode 100644 index 0000000..c96cf60 --- /dev/null +++ b/src/instr_bd2.cc @@ -0,0 +1,65 @@ +#include "instr_bd2.hh" +#include "daisysp.h" +#include "utils.hh" + +namespace Heck { + namespace Instrument { + + BD2::BD2() + { + init(); + } + + void BD2::init() + { + bd2.Init(samplerate); + bd2.SetDecay(1.); + bd2.SetTone(0.4); + bd2.SetAccent(1.); + bd2.SetSustain(true); + bd2.SetDirtiness(1.); + } + + void BD2::trigger() + { + bd2.Trig(); + + } + + void BD2::ctl(unsigned int ctl_nr, float val) + { + switch (ctl_nr) { + case 0: { + bd2.SetFreq(scalen_min_max(val, 40, 180)); + } break; + case 1: { + bd2.SetDecay(scalen_min_max(val,0,1)); + } break; + case 2: { + bd2.SetFmEnvelopeAmount(scalen_min_max(val,0,1)); + } break; + case 3: { + bd2.SetFmEnvelopeDecay(scalen_min_max(val,0,1)); + } break; + } + } + + void BD2::switch_mode1(unsigned int pos) + { + mode1 = pos; + } + + void BD2::switch_mode2(unsigned int pos) + { + mode2 = pos; + } + + float BD2::nextsample() + { + float out{}; + out = bd2.Process(); + return out; + } + + } // namespace Instrument +} // namespace Heck \ No newline at end of file diff --git a/src/instr_bd2.hh b/src/instr_bd2.hh new file mode 100644 index 0000000..ec087ac --- /dev/null +++ b/src/instr_bd2.hh @@ -0,0 +1,32 @@ +#ifndef HECK_DAISY_INSTR_BD2_HH +#define HECK_DAISY_INSTR_BD2_HH + +#include "instr_abstract.hh" +#include "daisy_seed.h" +#include "daisysp.h" + +namespace ld = daisy; +namespace dsp = daisysp; + +namespace Heck { + namespace Instrument { + + class BD2 : public AbstractInstrument { + public: + BD2(); + 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::SyntheticBassDrum bd2{}; + float mode1{}; + float mode2{}; + }; + + } // namespace Instrument +} // namespace Heck +#endif \ No newline at end of file