The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

VoicForm.h
1#ifndef STK_VOICFORM_H
2#define STK_VOICFORM_H
3
4#include "Instrmnt.h"
5#include "Envelope.h"
6#include "Noise.h"
7#include "SingWave.h"
8#include "FormSwep.h"
9#include "OnePole.h"
10#include "OneZero.h"
11
12namespace stk {
13
14/***************************************************/
39/***************************************************/
40
41 class VoicForm : public Instrmnt
42{
43 public:
45
48 VoicForm( void );
49
51 ~VoicForm( void );
52
54 void clear( void );
55
57 void setFrequency( StkFloat frequency );
58
60 bool setPhoneme( const char* phoneme );
61
63 void setVoiced( StkFloat vGain ) { voiced_->setGainTarget(vGain); };
64
66 void setUnVoiced( StkFloat nGain ) { noiseEnv_.setTarget(nGain); };
67
69 void setFilterSweepRate( unsigned int whichOne, StkFloat rate );
70
72 void setPitchSweepRate( StkFloat rate ) { voiced_->setSweepRate(rate); };
73
75 void speak( void ) { voiced_->noteOn(); };
76
78 void quiet( void );
79
81 void noteOn( StkFloat frequency, StkFloat amplitude );
82
84 void noteOff( StkFloat amplitude ) { this->quiet(); };
85
87 void controlChange( int number, StkFloat value );
88
90 StkFloat tick( unsigned int channel = 0 );
91
93
100 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
101
102protected:
103
104 SingWave *voiced_;
105 Noise noise_;
106 Envelope noiseEnv_;
107 FormSwep filters_[4];
108 OnePole onepole_;
109 OneZero onezero_;
110
111};
112
113 inline StkFloat VoicForm :: tick( unsigned int )
114{
115 StkFloat temp;
116 temp = onepole_.tick( onezero_.tick( voiced_->tick() ) );
117 temp += noiseEnv_.tick() * noise_.tick();
118 lastFrame_[0] = filters_[0].tick(temp);
119 lastFrame_[0] += filters_[1].tick(temp);
120 lastFrame_[0] += filters_[2].tick(temp);
121 lastFrame_[0] += filters_[3].tick(temp);
122 /*
123 temp += noiseEnv_.tick() * noise_.tick();
124 lastFrame_[0] = filters_[0].tick(temp);
125 lastFrame_[0] = filters_[1].tick(lastFrame_[0]);
126 lastFrame_[0] = filters_[2].tick(lastFrame_[0]);
127 lastFrame_[0] = filters_[3].tick(lastFrame_[0]);
128 */
129 return lastFrame_[0];
130}
131
132 inline StkFrames& VoicForm :: tick( StkFrames& frames, unsigned int channel )
133{
134 unsigned int nChannels = lastFrame_.channels();
135#if defined(_STK_DEBUG_)
136 if ( channel > frames.channels() - nChannels ) {
137 oStream_ << "VoicForm::tick(): channel and StkFrames arguments are incompatible!";
138 handleError( StkError::FUNCTION_ARGUMENT );
139 }
140#endif
141
142 StkFloat *samples = &frames[channel];
143 unsigned int j, hop = frames.channels() - nChannels;
144 if ( nChannels == 1 ) {
145 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
146 *samples++ = tick();
147 }
148 else {
149 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
150 *samples++ = tick();
151 for ( j=1; j<nChannels; j++ )
152 *samples++ = lastFrame_[j];
153 }
154 }
155
156 return frames;
157}
158
159} // stk namespace
160
161#endif
stk::Envelope
STK linear line envelope class.
Definition Envelope.h:23
stk::Envelope::setTarget
void setTarget(StkFloat target)
Set the target value.
stk::FormSwep
STK sweepable formant filter class.
Definition FormSwep.h:21
stk::Instrmnt
STK instrument abstract base class.
Definition Instrmnt.h:20
stk::Noise
STK noise generator.
Definition Noise.h:22
stk::OnePole
STK one-pole filter class.
Definition OnePole.h:21
stk::OneZero
STK one-zero filter class.
Definition OneZero.h:21
stk::OneZero::tick
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition OneZero.h:79
stk::SingWave
STK "singing" looped soundfile class.
Definition SingWave.h:26
stk::SingWave::noteOn
void noteOn(void)
Start a note.
Definition SingWave.h:72
stk::SingWave::setSweepRate
void setSweepRate(StkFloat rate)
Set the sweep rate.
Definition SingWave.h:63
stk::SingWave::setGainTarget
void setGainTarget(StkFloat target)
Set the gain target value.
Definition SingWave.h:69
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::VoicForm
Four formant synthesis instrument.
Definition VoicForm.h:42
stk::VoicForm::setFilterSweepRate
void setFilterSweepRate(unsigned int whichOne, StkFloat rate)
Set the sweep rate for a particular formant filter (0-3).
stk::VoicForm::~VoicForm
~VoicForm(void)
Class destructor.
stk::VoicForm::setPitchSweepRate
void setPitchSweepRate(StkFloat rate)
Set voiced component pitch sweep rate.
Definition VoicForm.h:72
stk::VoicForm::quiet
void quiet(void)
Stop the voice.
stk::VoicForm::speak
void speak(void)
Start the voice.
Definition VoicForm.h:75
stk::VoicForm::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::VoicForm::setPhoneme
bool setPhoneme(const char *phoneme)
Set instrument parameters for the given phoneme. Returns false if phoneme not found.
stk::VoicForm::VoicForm
VoicForm(void)
Class constructor.
stk::VoicForm::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::VoicForm::setUnVoiced
void setUnVoiced(StkFloat nGain)
Set the unvoiced component gain.
Definition VoicForm.h:66
stk::VoicForm::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
Definition VoicForm.h:84
stk::VoicForm::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition VoicForm.h:113
stk::VoicForm::setVoiced
void setVoiced(StkFloat vGain)
Set the voiced component gain.
Definition VoicForm.h:63
stk::VoicForm::clear
void clear(void)
Reset and clear all internal state.
stk::VoicForm::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk
The STK namespace.
Definition ADSR.h:6

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