Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Drummer.h
1#ifndef STK_DRUMMER_H
2#define STK_DRUMMER_H
3
4#include "Instrmnt.h"
5#include "FileWvIn.h"
6#include "OnePole.h"
7
8 namespace stk {
9
10/***************************************************/
25/***************************************************/
26
27 const int DRUM_NUMWAVES = 11;
28 const int DRUM_POLYPHONY = 4;
29
30 class Drummer : public Instrmnt
31{
32 public:
34
37 Drummer( void );
38
40 ~Drummer( void );
41
43
49 void noteOn( StkFloat instrument, StkFloat amplitude );
50
52 void noteOff( StkFloat amplitude );
53
55 StkFloat tick( unsigned int channel = 0 );
56
58
65 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
66
67 protected:
68
69 FileWvIn waves_[DRUM_POLYPHONY];
70 OnePole filters_[DRUM_POLYPHONY];
71 std::vector<int> soundOrder_;
72 std::vector<int> soundNumber_;
73 int nSounding_;
74};
75
76 inline StkFloat Drummer :: tick( unsigned int )
77{
78 lastFrame_[0] = 0.0;
79 if ( nSounding_ == 0 ) return lastFrame_[0];
80
81 for ( int i=0; i<DRUM_POLYPHONY; i++ ) {
82 if ( soundOrder_[i] >= 0 ) {
83 if ( waves_[i].isFinished() ) {
84 // Re-order the list.
85 for ( int j=0; j<DRUM_POLYPHONY; j++ ) {
86 if ( soundOrder_[j] > soundOrder_[i] )
87 soundOrder_[j] -= 1;
88 }
89 soundOrder_[i] = -1;
90 nSounding_--;
91 }
92 else
93 lastFrame_[0] += filters_[i].tick( waves_[i].tick() );
94 }
95 }
96
97 return lastFrame_[0];
98}
99
100 inline StkFrames& Drummer :: tick( StkFrames& frames, unsigned int channel )
101{
102 unsigned int nChannels = lastFrame_.channels();
103#if defined(_STK_DEBUG_)
104 if ( channel > frames.channels() - nChannels ) {
105 oStream_ << "Drummer::tick(): channel and StkFrames arguments are incompatible!";
106 handleError( StkError::FUNCTION_ARGUMENT );
107 }
108#endif
109
110 StkFloat *samples = &frames[channel];
111 unsigned int j, hop = frames.channels() - nChannels;
112 if ( nChannels == 1 ) {
113 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
114 *samples++ = tick();
115 }
116 else {
117 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
118 *samples++ = tick();
119 for ( j=1; j<nChannels; j++ )
120 *samples++ = lastFrame_[j];
121 }
122 }
123
124 return frames;
125}
126
127
128} // stk namespace
129
130#endif
stk::Drummer::~Drummer
~Drummer(void)
Class destructor.
stk::Drummer::noteOn
void noteOn(StkFloat instrument, StkFloat amplitude)
Start a note with the given drum type and amplitude.
stk::Drummer::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay).
stk::Drummer::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
Definition Drummer.h:76
stk::Drummer::Drummer
Drummer(void)
Class constructor.
stk::FileWvIn
STK audio file input class.
Definition FileWvIn.h:53
stk::Instrmnt::Instrmnt
Instrmnt(void)
Class constructor.
Definition Instrmnt.h:23
stk::OnePole
STK one-pole filter class.
Definition OnePole.h:21
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.