-
Notifications
You must be signed in to change notification settings - Fork 2
Building your own Instrument
Phil Schatzmann edited this page Sep 13, 2022
·
15 revisions
It is very easy to build your own instrument: just create a new subclass of Instrmnt that provides the following methods:
- noteOn
- noteOff
- tick
To handle the noteOn and noteOff you could simply set the amplitude to 1.0 if it is on or 0.0 if it is off. It is better however to handle this dynamically e.g. with the help of some Envelope Generators: ADSR, Asymp, Envelope
The tick() can be created from Generators combined with some Effects and/or Filters.
class MyFirstInstrument public Instrmnt {
public:
//! Start a note with the given frequency and amplitude.
void noteOn( StkFloat frequency, StkFloat amplitude ) {
wave.setFrequency(frequency);
adsr.keyOn();
}
//! Stop a note with the given amplitude (speed of decay).
void noteOff( StkFloat amplitude ){
adsr.keyOff();
}
float tick() {
return echo.tick(wave.tick())*adsr.tick();
}
protected:
SineWave wave;
ADSR adsr;
Echo echo;
};