Skip to content

Building your own Instrument

Phil Schatzmann edited this page Sep 13, 2022 · 15 revisions

It is very easy to build your own instrument.

The Simple Case

If you want to use your new class just in your AudioTools, just create a new subclass of Instrmnt that provides the following methods:

  • noteOn
  • noteOff
  • tick

The tick() can be created from a Generator 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 wave.tick()*adsr.tick();
    }

  protected:
    SineWave wave;
    ADSR adsr;
};

Clone this wiki locally