File: FM.h

package info (click to toggle)
stk 4.5.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 5,620 kB
  • ctags: 6,787
  • sloc: cpp: 30,471; ansic: 3,216; tcl: 2,375; sh: 2,319; perl: 114; objc: 60; makefile: 46
file content (119 lines) | stat: -rw-r--r-- 3,364 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef STK_FM_H
#define STK_FM_H

#include "Instrmnt.h"
#include "ADSR.h"
#include "FileLoop.h"
#include "SineWave.h"
#include "TwoZero.h"

namespace stk {

/***************************************************/
/*! \class FM
    \brief STK abstract FM synthesis base class.

    This class controls an arbitrary number of
    waves and envelopes, determined via a
    constructor argument.

    Control Change Numbers: 
       - Control One = 2
       - Control Two = 4
       - LFO Speed = 11
       - LFO Depth = 1
       - ADSR 2 & 4 Target = 128

    The basic Chowning/Stanford FM patent expired
    in 1995, but there exist follow-on patents,
    mostly assigned to Yamaha.  If you are of the
    type who should worry about this (making
    money) worry away.

    by Perry R. Cook and Gary P. Scavone, 1995--2014.
*/
/***************************************************/

class FM : public Instrmnt
{
 public:
  //! Class constructor, taking the number of wave/envelope operators to control.
  /*!
    An StkError will be thrown if the rawwave path is incorrectly set.
  */
  FM( unsigned int operators = 4 );

  //! Class destructor.
  virtual ~FM( void );

  //! Load the rawwave filenames in waves.
  void loadWaves( const char **filenames );

  //! Set instrument parameters for a particular frequency.
  virtual void setFrequency( StkFloat frequency );

  //! Set the frequency ratio for the specified wave.
  void setRatio( unsigned int waveIndex, StkFloat ratio );

  //! Set the gain for the specified wave.
  void setGain( unsigned int waveIndex, StkFloat gain );

  //! Set the modulation speed in Hz.
  void setModulationSpeed( StkFloat mSpeed ) { vibrato_.setFrequency( mSpeed ); };

  //! Set the modulation depth.
  void setModulationDepth( StkFloat mDepth ) { modDepth_ = mDepth; };

  //! Set the value of control1.
  void setControl1( StkFloat cVal ) { control1_ = cVal * 2.0; };

  //! Set the value of control1.
  void setControl2( StkFloat cVal ) { control2_ = cVal * 2.0; };

  //! Start envelopes toward "on" targets.
  void keyOn( void );

  //! Start envelopes toward "off" targets.
  void keyOff( void );

  //! Stop a note with the given amplitude (speed of decay).
  void noteOff( StkFloat amplitude );

  //! Perform the control change specified by \e number and \e value (0.0 - 128.0).
  virtual void controlChange( int number, StkFloat value );

  //! Compute and return one output sample.
  virtual StkFloat tick( unsigned int ) = 0;

  //! Fill a channel of the StkFrames object with computed outputs.
  /*!
    The \c channel argument must be less than the number of
    channels in the StkFrames argument (the first channel is specified
    by 0).  However, range checking is only performed if _STK_DEBUG_
    is defined during compilation, in which case an out-of-range value
    will trigger an StkError exception.
  */
  virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ) = 0;

 protected:

  std::vector<ADSR *> adsr_; 
  std::vector<FileLoop *> waves_;
  SineWave vibrato_;
  TwoZero  twozero_;
  unsigned int nOperators_;
  StkFloat baseFrequency_;
  std::vector<StkFloat> ratios_;
  std::vector<StkFloat> gains_;
  StkFloat modDepth_;
  StkFloat control1_;
  StkFloat control2_;
  StkFloat fmGains_[100];
  StkFloat fmSusLevels_[16];
  StkFloat fmAttTimes_[32];

};

} // stk namespace

#endif