The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Moog.h
1#ifndef STK_MOOG_H
2#define STK_MOOG_H
3
4#include "Sampler.h"
5#include "FormSwep.h"
6
7namespace stk {
8
9/***************************************************/
27/***************************************************/
28
29 class Moog : public Sampler
30{
31 public:
33
36 Moog( void );
37
39 ~Moog( void );
40
42 void setFrequency( StkFloat frequency );
43
45 void noteOn( StkFloat frequency, StkFloat amplitude );
46
48 void setModulationSpeed( StkFloat mSpeed ) { loops_[1]->setFrequency( mSpeed ); };
49
51 void setModulationDepth( StkFloat mDepth ) { modDepth_ = mDepth * 0.5; };
52
54 void controlChange( int number, StkFloat value );
55
57 StkFloat tick( unsigned int channel = 0 );
58
60
67 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
68
69 protected:
70
71 FormSwep filters_[2];
72 StkFloat modDepth_;
73 StkFloat filterQ_;
74 StkFloat filterRate_;
75
76};
77
78 inline StkFloat Moog :: tick( unsigned int )
79{
80 StkFloat temp;
81
82 if ( modDepth_ != 0.0 ) {
83 temp = loops_[1]->tick() * modDepth_;
84 loops_[0]->setFrequency( baseFrequency_ * (1.0 + temp) );
85 }
86
87 temp = attackGain_ * attacks_[0]->tick();
88 temp += loopGain_ * loops_[0]->tick();
89 temp = filter_.tick( temp );
90 temp *= adsr_.tick();
91 temp = filters_[0].tick( temp );
92 lastFrame_[0] = filters_[1].tick( temp );
93 return lastFrame_[0] * 6.0;
94}
95
96 inline StkFrames& Moog :: tick( StkFrames& frames, unsigned int channel )
97{
98 unsigned int nChannels = lastFrame_.channels();
99#if defined(_STK_DEBUG_)
100 if ( channel > frames.channels() - nChannels ) {
101 oStream_ << "Moog::tick(): channel and StkFrames arguments are incompatible!";
102 handleError( StkError::FUNCTION_ARGUMENT );
103 }
104#endif
105
106 StkFloat *samples = &frames[channel];
107 unsigned int j, hop = frames.channels() - nChannels;
108 if ( nChannels == 1 ) {
109 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
110 *samples++ = tick();
111 }
112 else {
113 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
114 *samples++ = tick();
115 for ( j=1; j<nChannels; j++ )
116 *samples++ = lastFrame_[j];
117 }
118 }
119
120 return frames;
121}
122
123} // stk namespace
124
125#endif
stk::FormSwep
STK sweepable formant filter class.
Definition: FormSwep.h:21
stk::FormSwep::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return a reference to one output.
Definition: FormSwep.h:123
stk::Moog
STK moog-like swept filter sampling synthesis class.
Definition: Moog.h:30
stk::Moog::Moog
Moog(void)
Class constructor.
stk::Moog::setModulationDepth
void setModulationDepth(StkFloat mDepth)
Set the modulation (vibrato) depth.
Definition: Moog.h:51
stk::Moog::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::Moog::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::Moog::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: Moog.h:78
stk::Moog::~Moog
~Moog(void)
Class destructor.
stk::Moog::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::Moog::setModulationSpeed
void setModulationSpeed(StkFloat mSpeed)
Set the modulation (vibrato) speed in Hz.
Definition: Moog.h:48
stk::Sampler
STK sampling synthesis abstract base class.
Definition: Sampler.h:23
stk::StkFrames
An STK class to handle vectorized audio data.
Definition: Stk.h:279
stk::StkFrames::channels
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:416
stk::StkFrames::frames
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:419
stk
The STK namespace.
Definition: ADSR.h:6

The Synthesis ToolKit in C++ (STK)
©1995--2021 Perry R. Cook and Gary P. Scavone. All Rights Reserved.