Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Plucked.h
1#ifndef STK_PLUCKED_H
2#define STK_PLUCKED_H
3
4#include "Instrmnt.h"
5#include "DelayA.h"
6#include "OneZero.h"
7#include "OnePole.h"
8#include "Noise.h"
9
10 namespace stk {
11
12/***************************************************/
32/***************************************************/
33
34 class Plucked : public Instrmnt
35{
36 public:
38 Plucked( StkFloat lowestFrequency = 10.0 );
39
41 ~Plucked( void );
42
44 void clear( void );
45
47 void setFrequency( StkFloat frequency );
48
50 void pluck( StkFloat amplitude );
51
53 void noteOn( StkFloat frequency, StkFloat amplitude );
54
56 void noteOff( StkFloat amplitude );
57
59 StkFloat tick( unsigned int channel = 0 );
60
62
69 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
70
71 protected:
72
73 DelayA delayLine_;
74 OneZero loopFilter_;
75 OnePole pickFilter_;
76 Noise noise_;
77
78 StkFloat loopGain_;
79};
80
81 inline StkFloat Plucked :: tick( unsigned int )
82{
83 // Here's the whole inner loop of the instrument!!
84 return lastFrame_[0] = 3.0 * delayLine_.tick( loopFilter_.tick( delayLine_.lastOut() * loopGain_ ) );
85}
86
87 inline StkFrames& Plucked :: tick( StkFrames& frames, unsigned int channel )
88{
89 unsigned int nChannels = lastFrame_.channels();
90#if defined(_STK_DEBUG_)
91 if ( channel > frames.channels() - nChannels ) {
92 oStream_ << "Plucked::tick(): channel and StkFrames arguments are incompatible!";
93 handleError( StkError::FUNCTION_ARGUMENT );
94 }
95#endif
96
97 StkFloat *samples = &frames[channel];
98 unsigned int j, hop = frames.channels() - nChannels;
99 if ( nChannels == 1 ) {
100 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
101 *samples++ = tick();
102 }
103 else {
104 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
105 *samples++ = tick();
106 for ( j=1; j<nChannels; j++ )
107 *samples++ = lastFrame_[j];
108 }
109 }
110
111 return frames;
112}
113
114} // stk namespace
115
116#endif
117
stk::DelayA
STK allpass interpolating delay line class.
Definition DelayA.h:29
stk::Instrmnt::Instrmnt
Instrmnt(void)
Class constructor.
Definition Instrmnt.h:23
stk::Noise
STK noise generator.
Definition Noise.h:22
stk::Noise::tick
StkFloat tick(void)
Compute and return one output sample.
Definition Noise.h:59
stk::OnePole
STK one-pole filter class.
Definition OnePole.h:21
stk::OneZero
STK one-zero filter class.
Definition OneZero.h:21
stk::Plucked::setFrequency
void setFrequency(StkFloat frequency)
Set instrument parameters for a particular frequency.
stk::Plucked::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Start a note with the given frequency and amplitude.
stk::Plucked::clear
void clear(void)
Reset and clear all internal state.
stk::Plucked::~Plucked
~Plucked(void)
Class destructor.
stk::Plucked::Plucked
Plucked(StkFloat lowestFrequency=10.0)
Class constructor, taking the lowest desired playing frequency.
stk::Plucked::pluck
void pluck(StkFloat amplitude)
Pluck the string with the given amplitude using the current frequency.
stk::Plucked::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk::Plucked::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition Plucked.h:81
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::Stk::handleError
static void handleError(const char *message, StkError::Type type)
Static function for error reporting and handling using c-strings.
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.