
2 changed files with 100 additions and 0 deletions
@ -0,0 +1,67 @@ |
|||
#include "instr_fm.hh" |
|||
#include "daisysp.h" |
|||
|
|||
using namespace daisysp; |
|||
|
|||
|
|||
namespace Heck { |
|||
namespace Instrument { |
|||
|
|||
void FM::init(float samplerate) |
|||
{ |
|||
osc.Init(samplerate); |
|||
osc.SetFrequency(100); |
|||
osc.SetRatio(0.); |
|||
osc.SetIndex(0.); |
|||
|
|||
volEnv.Init(samplerate); |
|||
volEnv.SetTime(ADENV_SEG_ATTACK, .0001); |
|||
volEnv.SetTime(ADENV_SEG_DECAY, 1.); |
|||
volEnv.SetMax(1); |
|||
volEnv.SetMin(0); |
|||
|
|||
} |
|||
|
|||
void FM::trigger() |
|||
{ |
|||
volEnv.Trigger(); |
|||
return; |
|||
} |
|||
|
|||
void FM::ctl(unsigned int ctl_nr, float val) |
|||
{ |
|||
switch (ctl_nr) { |
|||
case 0: |
|||
osc.SetFrequency(val * 200.); |
|||
break; |
|||
case 1: |
|||
volEnv.SetTime(ADENV_SEG_DECAY, val * 2.); |
|||
break; |
|||
case 2: |
|||
osc.SetRatio(val * 1.); |
|||
break; |
|||
case 3: |
|||
osc.SetIndex(val * 1.); |
|||
break; |
|||
case 4: |
|||
break; |
|||
case 5: |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void FM::switch_mode(unsigned int pos) {} |
|||
void FM::swtich_variation(unsigned int pos) {} |
|||
void FM::switch_filter(unsigned int pos) {} |
|||
|
|||
float FM::nextsample() |
|||
{ |
|||
float sig{}; |
|||
sig = osc.Process(); |
|||
float volEnv_sig = volEnv.Process(); |
|||
sig *= volEnv_sig; |
|||
return sig; |
|||
} |
|||
|
|||
} // namespace Instrument
|
|||
} // namespace Heck
|
@ -0,0 +1,33 @@ |
|||
#ifndef HECK_DAISY_INSTR_FM_HH |
|||
#define HECK_DAISY_INSTR_FM_HH |
|||
|
|||
#include "perkons_instrument_interface.hh" |
|||
#include "daisy_seed.h" |
|||
#include "daisysp.h" |
|||
|
|||
namespace ld = daisy; |
|||
namespace dsp = daisysp; |
|||
|
|||
namespace Heck { |
|||
namespace Instrument { |
|||
|
|||
class FM : public PerkonsInstrumentInterface { |
|||
public: |
|||
void init(float samplerate); |
|||
|
|||
void trigger() override; |
|||
void ctl(unsigned int ctl_nr, float val) override; |
|||
void switch_mode(unsigned int pos) override; |
|||
void swtich_variation(unsigned int pos) override; |
|||
void switch_filter(unsigned int pos) override; |
|||
|
|||
float nextsample() override; |
|||
|
|||
private: |
|||
dsp::Fm2 osc; |
|||
dsp::AdEnv volEnv; |
|||
}; |
|||
|
|||
} // namespace Instrument
|
|||
} // namespace Heck
|
|||
#endif |
Loading…
Reference in new issue