1 module stk.fm; 2 3 import stk.stk; 4 import stk.instrument; 5 import stk.adsr; 6 import stk.fileloop; 7 import stk.sinewave; 8 import stk.twozero; 9 10 /***************************************************/ 11 /*! \class FM 12 \brief STK abstract FM synthesis base class. 13 14 This class controls an arbitrary number of 15 waves and envelopes, determined via a 16 constructor argument. 17 18 Control Change Numbers: 19 - Control One = 2 20 - Control Two = 4 21 - LFO Speed = 11 22 - LFO Depth = 1 23 - ADSR 2 & 4 Target = 128 24 25 The basic Chowning/Stanford FM patent expired 26 in 1995, but there exist follow-on patents, 27 mostly assigned to Yamaha. If you are of the 28 type who should worry about this (making 29 money) worry away. 30 31 by Perry R. Cook and Gary P. Scavone, 1995--2016. 32 */ 33 /***************************************************/ 34 35 abstract class FM : Instrmnt 36 { 37 public: 38 //! Class constructor, taking the number of wave/envelope operators to control. 39 /*! 40 An StkError will be thrown if the rawwave path is incorrectly set. 41 */ 42 this( uint operators = 4 ) { 43 } 44 45 //! Class destructor. 46 ~this() { 47 } 48 49 //! Load the rawwave filenames in waves. 50 void loadWaves( const char **filenames ) { 51 } 52 53 //! Set instrument parameters for a particular frequency. 54 override void setFrequency( StkFloat frequency ) { 55 } 56 57 //! Set the frequency ratio for the specified wave. 58 void setRatio(uint waveIndex, StkFloat ratio) { 59 } 60 61 //! Set the gain for the specified wave. 62 void setGain( uint waveIndex, StkFloat gain ) { 63 } 64 65 //! Set the modulation speed in Hz. 66 void setModulationSpeed( StkFloat mSpeed ) { vibrato_.setFrequency( mSpeed ); }; 67 68 //! Set the modulation depth. 69 void setModulationDepth( StkFloat mDepth ) { modDepth_ = mDepth; }; 70 71 //! Set the value of control1. 72 void setControl1( StkFloat cVal ) { control1_ = cVal * 2.0; }; 73 74 //! Set the value of control1. 75 void setControl2( StkFloat cVal ) { control2_ = cVal * 2.0; }; 76 77 //! Start envelopes toward "on" targets. 78 void keyOn() { 79 } 80 81 //! Start envelopes toward "off" targets. 82 void keyOff() { 83 } 84 85 //! Stop a note with the given amplitude (speed of decay). 86 void noteOff( StkFloat amplitude ) { 87 } 88 89 //! Perform the control change specified by \e number and \e value (0.0 - 128.0). 90 override void controlChange( int number, StkFloat value ) { 91 } 92 93 //! Compute and return one output sample. 94 StkFloat tick( uint channel = 0) { 95 return 0; 96 } 97 98 //! Fill a channel of the StkFrames object with computed outputs. 99 /*! 100 The \c channel argument must be less than the number of 101 channels in the StkFrames argument (the first channel is specified 102 by 0). However, range checking is only performed if _STK_DEBUG_ 103 is defined during compilation, in which case an out-of-range value 104 will trigger an StkError exception. 105 */ 106 //ref StkFrames tick( ref StkFrames frames, uint channel = 0 ) = 0; 107 108 protected: 109 110 ADSR[] adsr_; 111 FileLoop[] waves_; 112 SineWave vibrato_; 113 TwoZero twozero_; 114 uint nOperators_; 115 StkFloat baseFrequency_; 116 StkFloat[] ratios_; 117 StkFloat[] gains_; 118 StkFloat modDepth_; 119 StkFloat control1_; 120 StkFloat control2_; 121 StkFloat[100] fmGains_; 122 StkFloat[16] fmSusLevels_; 123 StkFloat[32] fmAttTimes_; 124 125 } 126