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
41class 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
113inline 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
132inline 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 linear line envelope class.
Definition Envelope.h:23
void setTarget(StkFloat target)
Set the target value.
STK sweepable formant filter class.
Definition FormSwep.h:21
STK instrument abstract base class.
Definition Instrmnt.h:20
STK noise generator.
Definition Noise.h:22
STK one-pole filter class.
Definition OnePole.h:21
STK one-zero filter class.
Definition OneZero.h:21
StkFloat tick(StkFloat input)
Input one sample to the filter and return one output.
Definition OneZero.h:79
STK "singing" looped soundfile class.
Definition SingWave.h:26
void noteOn(void)
Start a note.
Definition SingWave.h:72
void setSweepRate(StkFloat rate)
Set the sweep rate.
Definition SingWave.h:63
void setGainTarget(StkFloat target)
Set the gain target value.
Definition SingWave.h:69
An STK class to handle vectorized audio data.
Definition Stk.h:279
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition Stk.h:416
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition Stk.h:419
Four formant synthesis instrument.
Definition VoicForm.h:42
void setFilterSweepRate(unsigned int whichOne, StkFloat rate)
Set the sweep rate for a particular formant filter (0-3).
~VoicForm(void)
Class destructor.
void setPitchSweepRate(StkFloat rate)
Set voiced component pitch sweep rate.
Definition VoicForm.h:72
void quiet(void)
Stop the voice.
void speak(void)
Start the voice.
Definition VoicForm.h:75
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
bool setPhoneme(const char *phoneme)
Set instrument parameters for the given phoneme. Returns false if phoneme not found.
VoicForm(void)
Class constructor.
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
void setUnVoiced(StkFloat nGain)
Set the unvoiced component gain.
Definition VoicForm.h:66
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
Definition VoicForm.h:84
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition VoicForm.h:113
void setVoiced(StkFloat vGain)
Set the voiced component gain.
Definition VoicForm.h:63
void clear(void)
Reset and clear all internal state.
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
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.