71 void noteOn( StkFloat instrument, StkFloat amplitude );
80 StkFloat
tick(
unsigned int channel = 0 );
103 for (
int i=0; i<3; i++ ) {
114 void setType(
int type );
115 void setResonance( BiQuad &filter, StkFloat frequency, StkFloat radius );
116 StkFloat tickResonance( BiQuad &filter, StkFloat input );
117 void setEqualization( StkFloat b0, StkFloat b1, StkFloat b2 );
118 StkFloat tickEqualize( StkFloat input );
119 int randomInt(
int max );
120 StkFloat randomFloat( StkFloat max = 1.0 );
121 StkFloat noise(
void );
122 void waterDrop(
void );
125 unsigned int nResonances_;
126 StkFloat shakeEnergy_;
127 StkFloat soundDecay_;
128 StkFloat systemDecay_;
132 StkFloat currentGain_;
134 StkFloat baseObjects_;
135 StkFloat decayScale_;
137 StkFloat ratchetCount_;
138 StkFloat ratchetDelta_;
139 StkFloat baseRatchetDelta_;
140 int lastRatchetValue_;
142 std::vector< BiQuad > filters_;
143 std::vector< StkFloat > baseFrequencies_;
144 std::vector< StkFloat > baseRadii_;
145 std::vector< bool > doVaryFrequency_;
146 std::vector< StkFloat > tempFrequencies_;
147 StkFloat varyFactor_;
150 inline void Shakers :: setResonance( BiQuad &filter, StkFloat frequency, StkFloat radius )
152 filter.a[1] = -2.0 * radius * cos( STK_TWO_PI * frequency /
Stk::sampleRate());
153 filter.a[2] = radius * radius;
156 inline StkFloat Shakers :: tickResonance( BiQuad &filter, StkFloat input )
158 filter.outputs[0] = input * filter.gain * currentGain_;
159 filter.outputs[0] -= filter.a[1] * filter.outputs[1] + filter.a[2] * filter.outputs[2];
160 filter.outputs[2] = filter.outputs[1];
161 filter.outputs[1] = filter.outputs[0];
162 return filter.outputs[0];
165 inline void Shakers :: setEqualization( StkFloat b0, StkFloat b1, StkFloat b2 )
167 equalizer_.b[0] = b0;
168 equalizer_.b[1] = b1;
169 equalizer_.b[2] = b2;
172 inline StkFloat Shakers :: tickEqualize( StkFloat input )
174 equalizer_.inputs[0] = input;
175 equalizer_.outputs[0] = equalizer_.b[0] * equalizer_.inputs[0] + equalizer_.b[1] * equalizer_.inputs[1] + equalizer_.b[2] * equalizer_.inputs[2];
176 equalizer_.inputs[2] = equalizer_.inputs[1];
177 equalizer_.inputs[1] = equalizer_.inputs[0];
178 return equalizer_.outputs[0];
181 inline int Shakers :: randomInt(
int max )
183 return (
int) ((float)max * rand() / (RAND_MAX + 1.0) );
186 inline StkFloat Shakers :: randomFloat( StkFloat max )
188 return (StkFloat) (max * rand() / (RAND_MAX + 1.0) );
191 inline StkFloat Shakers :: noise(
void )
193 return ( (StkFloat) ( 2.0 * rand() / (RAND_MAX + 1.0) ) - 1.0 );
196 const StkFloat MIN_ENERGY = 0.001;
197 const StkFloat WATER_FREQ_SWEEP = 1.0001;
199 inline void Shakers :: waterDrop(
void )
201 if ( randomInt( 32767 ) < nObjects_) {
202 sndLevel_ = shakeEnergy_;
203 unsigned int j = randomInt( 3 );
204 if ( j == 0 && filters_[0].gain == 0.0 ) {
205 tempFrequencies_[0] = baseFrequencies_[1] * (0.75 + (0.25 * noise()));
206 filters_[0].gain = fabs( noise() );
208 else if (j == 1 && filters_[1].gain == 0.0) {
209 tempFrequencies_[1] = baseFrequencies_[1] * (1.0 + (0.25 * noise()));
210 filters_[1].gain = fabs( noise() );
212 else if ( filters_[2].gain == 0.0 ) {
213 tempFrequencies_[2] = baseFrequencies_[1] * (1.25 + (0.25 * noise()));
214 filters_[2].gain = fabs( noise() );
219 for (
unsigned int i=0; i<3; i++ ) {
220 filters_[i].gain *= baseRadii_[i];
221 if ( filters_[i].gain > 0.001 ) {
222 tempFrequencies_[i] *= WATER_FREQ_SWEEP;
223 filters_[i].a[1] = -2.0 * baseRadii_[i] * cos( STK_TWO_PI * tempFrequencies_[i] /
Stk::sampleRate() );
226 filters_[i].gain = 0.0;
232 unsigned int iTube = 0;
233 StkFloat input = 0.0;
234 if ( shakerType_ == 19 || shakerType_ == 20 ) {
235 if ( ratchetCount_ <= 0 )
return lastFrame_[0] = 0.0;
237 shakeEnergy_ -= ( ratchetDelta_ + ( 0.002 * shakeEnergy_ ) );
238 if ( shakeEnergy_ < 0.0 ) {
243 if ( randomFloat( 1024 ) < nObjects_ )
244 sndLevel_ += shakeEnergy_ * shakeEnergy_;
247 input = sndLevel_ * noise() * shakeEnergy_;
250 if ( shakeEnergy_ < MIN_ENERGY )
return lastFrame_[0] = 0.0;
253 shakeEnergy_ *= systemDecay_;
256 if ( shakerType_ == 21 ) {
261 if ( randomFloat( 1024.0 ) < nObjects_ ) {
262 sndLevel_ += shakeEnergy_;
265 for (
unsigned int i=0; i<nResonances_; i++ ) {
266 if ( doVaryFrequency_[i] ) {
267 StkFloat tempRand = baseFrequencies_[i] * ( 1.0 + ( varyFactor_ * noise() ) );
268 filters_[i].a[1] = -2.0 * baseRadii_[i] * cos( STK_TWO_PI * tempRand /
Stk::sampleRate() );
271 if ( shakerType_ == 22 ) iTube = randomInt( 7 );
277 sndLevel_ *= soundDecay_;
281 if ( shakerType_ == 22 ) {
282 for (
unsigned int i=0; i<nResonances_; i++ ) {
284 lastFrame_[0] += tickResonance( filters_[i], input );
286 lastFrame_[0] += tickResonance( filters_[i], 0.0 );
290 for (
unsigned int i=0; i<nResonances_; i++ )
291 lastFrame_[0] += tickResonance( filters_[i], input );
295 lastFrame_[0] = tickEqualize( lastFrame_[0] );
300 return lastFrame_[0];
305 unsigned int nChannels = lastFrame_.
channels();
306 #if defined(_STK_DEBUG_)
307 if ( channel > frames.
channels() - nChannels ) {
308 oStream_ <<
"Shakers::tick(): channel and StkFrames arguments are incompatible!";
313 StkFloat *samples = &frames[channel];
314 unsigned int j, hop = frames.
channels() - nChannels;
315 if ( nChannels == 1 ) {
316 for (
unsigned int i=0; i<frames.
frames(); i++, samples += hop )
320 for (
unsigned int i=0; i<frames.
frames(); i++, samples += hop ) {
322 for ( j=1; j<nChannels; j++ )
323 *samples++ = lastFrame_[j];
STK instrument abstract base class.
Definition: Instrmnt.h:20
PhISEM and PhOLIES class.
Definition: Shakers.h:61
Shakers(int type=0)
Class constructor taking instrument type argument.
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
void noteOn(StkFloat instrument, StkFloat amplitude)
Start a note with the given instrument and amplitude.
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition: Shakers.h:230
An STK class to handle vectorized audio data.
Definition: Stk.h:287
unsigned int channels(void) const
Return the number of channels represented by the data.
Definition: Stk.h:415
unsigned int frames(void) const
Return the number of sample frames represented by the data.
Definition: Stk.h:418
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
static StkFloat sampleRate(void)
Static method that returns the current STK sample rate.
Definition: Stk.h:156
The STK namespace.
Definition: ADSR.h:8