The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

FMVoices.h
1#ifndef STK_FMVOICES_H
2#define STK_FMVOICES_H
3
4#include "FM.h"
5
6namespace stk {
7
8/***************************************************/
38/***************************************************/
39
40 class FMVoices : public FM
41{
42 public:
44
47 FMVoices( void );
48
50 ~FMVoices( void );
51
53 void setFrequency( StkFloat frequency );
54
56 void noteOn( StkFloat frequency, StkFloat amplitude );
57
59 void controlChange( int number, StkFloat value );
60
62 StkFloat tick( unsigned int channel = 0 );
63
65
72 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
73
74 protected:
75
76 int currentVowel_;
77 StkFloat tilt_[3];
78 StkFloat mods_[3];
79};
80
81 inline StkFloat FMVoices :: tick( unsigned int )
82{
83 StkFloat temp, temp2;
84
85 temp = gains_[3] * adsr_[3]->tick() * waves_[3]->tick();
86 temp2 = vibrato_.tick() * modDepth_ * 0.1;
87
88 waves_[0]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[0]);
89 waves_[1]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[1]);
90 waves_[2]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[2]);
91 waves_[3]->setFrequency(baseFrequency_ * (1.0 + temp2) * ratios_[3]);
92
93 waves_[0]->addPhaseOffset(temp * mods_[0]);
94 waves_[1]->addPhaseOffset(temp * mods_[1]);
95 waves_[2]->addPhaseOffset(temp * mods_[2]);
96 waves_[3]->addPhaseOffset( twozero_.lastOut() );
97 twozero_.tick( temp );
98 temp = gains_[0] * tilt_[0] * adsr_[0]->tick() * waves_[0]->tick();
99 temp += gains_[1] * tilt_[1] * adsr_[1]->tick() * waves_[1]->tick();
100 temp += gains_[2] * tilt_[2] * adsr_[2]->tick() * waves_[2]->tick();
101
102 lastFrame_[0] = temp * 0.33;
103 return lastFrame_[0];
104}
105
106 inline StkFrames& FMVoices :: tick( StkFrames& frames, unsigned int channel )
107{
108 unsigned int nChannels = lastFrame_.channels();
109#if defined(_STK_DEBUG_)
110 if ( channel > frames.channels() - nChannels ) {
111 oStream_ << "FMVoices::tick(): channel and StkFrames arguments are incompatible!";
112 handleError( StkError::FUNCTION_ARGUMENT );
113 }
114#endif
115
116 StkFloat *samples = &frames[channel];
117 unsigned int j, hop = frames.channels() - nChannels;
118 if ( nChannels == 1 ) {
119 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
120 *samples++ = tick();
121 }
122 else {
123 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
124 *samples++ = tick();
125 for ( j=1; j<nChannels; j++ )
126 *samples++ = lastFrame_[j];
127 }
128 }
129
130 return frames;
131}
132
133} // stk namespace
134
135#endif
stk::FMVoices
STK singing FM synthesis instrument.
Definition: FMVoices.h:41
stk::FMVoices::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::FMVoices::FMVoices
FMVoices(void)
Class constructor.
stk::FMVoices::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: FMVoices.h:81
stk::FMVoices::~FMVoices
~FMVoices(void)
Class destructor.
stk::FMVoices::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::FMVoices::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::FM
STK abstract FM synthesis base class.
Definition: FM.h:38
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.