The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Wurley.h
1#ifndef STK_WURLEY_H
2#define STK_WURLEY_H
3
4#include "FM.h"
5
6namespace stk {
7
8/***************************************************/
38/***************************************************/
39
40 class Wurley : public FM
41{
42 public:
44
47 Wurley( void );
48
50 ~Wurley( void );
51
53 void setFrequency( StkFloat frequency );
54
56 void noteOn( StkFloat frequency, StkFloat amplitude );
57
59 StkFloat tick( unsigned int channel = 0 );
60
62
69 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
70
71 protected:
72
73};
74
75 inline StkFloat Wurley :: tick( unsigned int )
76{
77 StkFloat temp, temp2;
78
79 temp = gains_[1] * adsr_[1]->tick() * waves_[1]->tick();
80 temp = temp * control1_;
81
82 waves_[0]->addPhaseOffset( temp );
83 waves_[3]->addPhaseOffset( twozero_.lastOut() );
84 temp = gains_[3] * adsr_[3]->tick() * waves_[3]->tick();
85 twozero_.tick(temp);
86
87 waves_[2]->addPhaseOffset( temp );
88 temp = ( 1.0 - (control2_ * 0.5)) * gains_[0] * adsr_[0]->tick() * waves_[0]->tick();
89 temp += control2_ * 0.5 * gains_[2] * adsr_[2]->tick() * waves_[2]->tick();
90
91 // Calculate amplitude modulation and apply it to output.
92 temp2 = vibrato_.tick() * modDepth_;
93 temp = temp * (1.0 + temp2);
94
95 lastFrame_[0] = temp * 0.5;
96 return lastFrame_[0];
97}
98
99 inline StkFrames& Wurley :: tick( StkFrames& frames, unsigned int channel )
100{
101 unsigned int nChannels = lastFrame_.channels();
102#if defined(_STK_DEBUG_)
103 if ( channel > frames.channels() - nChannels ) {
104 oStream_ << "Wurley::tick(): channel and StkFrames arguments are incompatible!";
105 handleError( StkError::FUNCTION_ARGUMENT );
106 }
107#endif
108
109 StkFloat *samples = &frames[channel];
110 unsigned int j, hop = frames.channels() - nChannels;
111 if ( nChannels == 1 ) {
112 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
113 *samples++ = tick();
114 }
115 else {
116 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
117 *samples++ = tick();
118 for ( j=1; j<nChannels; j++ )
119 *samples++ = lastFrame_[j];
120 }
121 }
122
123 return frames;
124}
125
126} // stk namespace
127
128#endif
stk::FM
STK abstract FM synthesis base class.
Definition: FM.h:38
stk::SineWave::tick
StkFloat tick(void)
Compute and return one output sample.
Definition: SineWave.h:99
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::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
stk::TwoZero::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition: TwoZero.h:60
stk::TwoZero::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition: TwoZero.h:92
stk::Wurley
STK Wurlitzer electric piano FM synthesis instrument.
Definition: Wurley.h:41
stk::Wurley::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: Wurley.h:75
stk::Wurley::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::Wurley::~Wurley
~Wurley(void)
Class destructor.
stk::Wurley::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::Wurley::Wurley
Wurley(void)
Class constructor.
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.