The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

StifKarp.h
1#ifndef STK_STIFKARP_H
2#define STK_STIFKARP_H
3
4#include "Instrmnt.h"
5#include "DelayL.h"
6#include "DelayA.h"
7#include "OneZero.h"
8#include "Noise.h"
9#include "BiQuad.h"
10
11namespace stk {
12
13/***************************************************/
34/***************************************************/
35
36 class StifKarp : public Instrmnt
37{
38 public:
40 StifKarp( StkFloat lowestFrequency = 10.0 );
41
43 ~StifKarp( void );
44
46 void clear( void );
47
49 void setFrequency( StkFloat frequency );
50
52 void setStretch( StkFloat stretch );
53
55 void setPickupPosition( StkFloat position );
56
58
63 void setBaseLoopGain( StkFloat aGain );
64
66 void pluck( StkFloat amplitude );
67
69 void noteOn( StkFloat frequency, StkFloat amplitude );
70
72 void noteOff( StkFloat amplitude );
73
75 void controlChange( int number, StkFloat value );
76
78 StkFloat tick( unsigned int channel = 0 );
79
81
88 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
89
90 protected:
91
92 DelayA delayLine_;
93 DelayL combDelay_;
94 OneZero filter_;
95 Noise noise_;
96 BiQuad biquad_[4];
97
98 StkFloat loopGain_;
99 StkFloat baseLoopGain_;
100 StkFloat lastFrequency_;
101 StkFloat lastLength_;
102 StkFloat stretching_;
103 StkFloat pluckAmplitude_;
104 StkFloat pickupPosition_;
105
106};
107
108 inline StkFloat StifKarp :: tick( unsigned int )
109{
110 StkFloat temp = delayLine_.lastOut() * loopGain_;
111
112 // Calculate allpass stretching.
113 for (int i=0; i<4; i++)
114 temp = biquad_[i].tick(temp);
115
116 // Moving average filter.
117 temp = filter_.tick(temp);
118
119 lastFrame_[0] = delayLine_.tick(temp);
120 lastFrame_[0] = lastFrame_[0] - combDelay_.tick( lastFrame_[0] );
121 return lastFrame_[0];
122}
123
124 inline StkFrames& StifKarp :: tick( StkFrames& frames, unsigned int channel )
125{
126 unsigned int nChannels = lastFrame_.channels();
127#if defined(_STK_DEBUG_)
128 if ( channel > frames.channels() - nChannels ) {
129 oStream_ << "StifKarp::tick(): channel and StkFrames arguments are incompatible!";
130 handleError( StkError::FUNCTION_ARGUMENT );
131 }
132#endif
133
134 StkFloat *samples = &frames[channel];
135 unsigned int j, hop = frames.channels() - nChannels;
136 if ( nChannels == 1 ) {
137 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
138 *samples++ = tick();
139 }
140 else {
141 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
142 *samples++ = tick();
143 for ( j=1; j<nChannels; j++ )
144 *samples++ = lastFrame_[j];
145 }
146 }
147
148 return frames;
149}
150
151} // stk namespace
152
153#endif
stk::BiQuad
STK biquad (two-pole, two-zero) filter class.
Definition BiQuad.h:26
stk::BiQuad::lastOut
StkFloat lastOut(void) const
Return the last computed output value.
Definition BiQuad.h:152
stk::DelayA
STK allpass interpolating delay line class.
Definition DelayA.h:29
stk::DelayL
STK linear interpolating delay line class.
Definition DelayL.h:28
stk::Instrmnt
STK instrument abstract base class.
Definition Instrmnt.h:20
stk::Noise
STK noise generator.
Definition Noise.h:22
stk::OneZero
STK one-zero filter class.
Definition OneZero.h:21
stk::StifKarp
STK plucked stiff string instrument.
Definition StifKarp.h:37
stk::StifKarp::pluck
void pluck(StkFloat amplitude)
Pluck the string with the given amplitude using the current frequency.
stk::StifKarp::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk::StifKarp::setStretch
void setStretch(StkFloat stretch)
Set the stretch "factor" of the string (0.0 - 1.0).
stk::StifKarp::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::StifKarp::~StifKarp
~StifKarp(void)
Class destructor.
stk::StifKarp::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::StifKarp::setPickupPosition
void setPickupPosition(StkFloat position)
Set the pluck or "excitation" position along the string (0.0 - 1.0).
stk::StifKarp::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition StifKarp.h:108
stk::StifKarp::clear
void clear(void)
Reset and clear all internal state.
stk::StifKarp::setBaseLoopGain
void setBaseLoopGain(StkFloat aGain)
Set the base loop gain.
stk::StifKarp::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::StifKarp::StifKarp
StifKarp(StkFloat lowestFrequency=10.0)
Class constructor, taking the lowest desired playing frequency.
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--2023 Perry R. Cook and Gary P. Scavone. All Rights Reserved.