CSL  5.2
BasicFMInstrument.h
Go to the documentation of this file.
1 ///
2 /// BasicFMInstrument.h -- Simple and fancy FM example instrument classes.
3 /// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 ///
5 /// This instrument implements single-operator FM with ADSR envelopes for the
6 /// amplitude and modulation index envelopes; it provides 13 parameter accessors
7 /// for use by OSC.
8 ///
9 /// Accessors
10 /// "du", set_duration_f
11 /// "am", set_amplitude_f
12 /// "in", set_index_f
13 /// "cf", set_c_freq_f
14 /// "mf", set_m_freq_f
15 /// "po", set_position_f
16 /// "aa", set_attack_f -- amplitude envelope ADSR
17 /// "ad", set_decay_f
18 /// "as", set_sustain_f
19 /// "ar", set_release_f
20 /// "ia", set_iattack_f -- mod. index envelope ADSR
21 /// "id", set_idecay_f
22 /// "is", set_isustain_f
23 /// "ir", set_irelease_f
24 ///
25 /// OSC note formats (6 or 14 arguments):
26 /// dur, ampl, c_fr, m_fr, ind, pos
27 /// dur, ampl, c_fr, m_fr, ind, pos, att, dec, sus, rel, i_att, i_dec, i_sus, i_rel
28 
29 #ifndef INCLUDE_Basic_FM_Instrument_H
30 #define INCLUDE_Basic_FM_Instrument_H
31 
32 #include "Instrument.h"
33 #include "Mixer.h"
34 
35 namespace csl {
36 
37 ///
38 /// FMInstrument
39 ///
40 class FMInstrument : public Instrument {
41 public:
42  FMInstrument(); ///< Constructor
43  FMInstrument(FMInstrument&); ///< copy constructor
44  ~FMInstrument();
45  /// Plug functions
46  virtual void setParameter(unsigned selector, int argc, void **argv, const char *types);
47  /// Play functions
48  void parseArgs(int argc, void **argv, const char *types);
49  virtual void playOSC(int argc, void **argv, const char *types);
50 
51  void playNote(float dur = 1, float ampl = 1,
52  float c_fr = 110, float m_fr = 110, float ind = 1, float pos = 0,
53  float att = 0.1, float dec = 0.1, float sus = 0.5, float rel = 0.1,
54  float i_att = 0.1, float i_dec = 0.1, float i_sus = 0.5, float i_rel = 0.1);
55  void playMIDI(float dur, int chan, int key, int vel);
56 
57  ///< These are the UGens of the DSP graph (i.e., the FM instrument)
58  ADSR mAEnv, mIEnv; ///< amplitude & modulation index envelopes
59  Osc mCar, mMod; ///< 2 sine oscillators, carrier and modulator
60  Panner mPanner; ///< stereo panner
61 };
62 
63 ///
64 /// FancyFMInstrument - FM with vibrato (with AR-envelope), attack chiff (filtered noise with AR-envelope),
65 /// and random freq. drift and ampl. swell envelopes
66 ///
68 public:
69  FancyFMInstrument(); ///< Constructor
71 
72  void setParameter(unsigned selector, int argc, void **argv, const char *types);
73  void playOSC(int argc, void **argv, const char *types);
74  void playMIDI(float dur, int chan, int key, int vel);
75  ///< These are the additional UGens of the DSP graph (i.e., the FM instrument)
76  Envelope mVibEnv; ///< vibrato envelope
77  ADSR mChiffEnv; ///< attack-chiff envelope
78  Osc mVibrato; ///< sine oscillator for vibrato
79  WhiteNoise mChiff; ///< chiff noise
80  Butter mChFilter; ///< chiff filter
82 };
83 
84 }
85 
86 #endif