Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

Mesh2D.h
1#ifndef STK_MESH2D_H
2#define STK_MESH2D_H
3
4#include "Instrmnt.h"
5#include "OnePole.h"
6
7 namespace stk {
8
9/***************************************************/
33/***************************************************/
34
35 const unsigned short NXMAX = 12;
36 const unsigned short NYMAX = 12;
37
38 class Mesh2D : public Instrmnt
39{
40 public:
42 Mesh2D( unsigned short nX, unsigned short nY );
43
45 ~Mesh2D( void );
46
48 void clear( void );
49
51 void setNX( unsigned short lenX );
52
54 void setNY( unsigned short lenY );
55
57 void setInputPosition( StkFloat xFactor, StkFloat yFactor );
58
60 void setDecay( StkFloat decayFactor );
61
63 void noteOn( StkFloat frequency, StkFloat amplitude );
64
66 void noteOff( StkFloat amplitude );
67
69 StkFloat energy( void );
70
72 StkFloat inputTick( StkFloat input );
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 StkFloat tick0();
93 StkFloat tick1();
94 void clearMesh();
95
96 unsigned short NX_, NY_;
97 unsigned short xInput_, yInput_;
98 OnePole filterX_[NXMAX];
99 OnePole filterY_[NYMAX];
100 StkFloat v_[NXMAX-1][NYMAX-1]; // junction velocities
101 StkFloat vxp_[NXMAX][NYMAX]; // positive-x velocity wave
102 StkFloat vxm_[NXMAX][NYMAX]; // negative-x velocity wave
103 StkFloat vyp_[NXMAX][NYMAX]; // positive-y velocity wave
104 StkFloat vym_[NXMAX][NYMAX]; // negative-y velocity wave
105
106 // Alternate buffers
107 StkFloat vxp1_[NXMAX][NYMAX]; // positive-x velocity wave
108 StkFloat vxm1_[NXMAX][NYMAX]; // negative-x velocity wave
109 StkFloat vyp1_[NXMAX][NYMAX]; // positive-y velocity wave
110 StkFloat vym1_[NXMAX][NYMAX]; // negative-y velocity wave
111
112 int counter_; // time in samples
113};
114
115 inline StkFrames& Mesh2D :: tick( StkFrames& frames, unsigned int channel )
116{
117 unsigned int nChannels = lastFrame_.channels();
118#if defined(_STK_DEBUG_)
119 if ( channel > frames.channels() - nChannels ) {
120 oStream_ << "Mesh2D::tick(): channel and StkFrames arguments are incompatible!";
121 handleError( StkError::FUNCTION_ARGUMENT );
122 }
123#endif
124
125 StkFloat *samples = &frames[channel];
126 unsigned int j, hop = frames.channels() - nChannels;
127 if ( nChannels == 1 ) {
128 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
129 *samples++ = tick();
130 }
131 else {
132 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
133 *samples++ = tick();
134 for ( j=1; j<nChannels; j++ )
135 *samples++ = lastFrame_[j];
136 }
137 }
138
139 return frames;
140}
141
142} // stk namespace
143
144#endif
stk::Instrmnt::Instrmnt
Instrmnt(void)
Class constructor.
Definition Instrmnt.h:23
stk::Mesh2D::noteOff
void noteOff(StkFloat amplitude)
Stop a note with the given amplitude (speed of decay) ... currently ignored.
stk::Mesh2D::setNY
void setNY(unsigned short lenY)
Set the y dimension size in samples.
stk::Mesh2D::clear
void clear(void)
Reset and clear all internal state.
stk::Mesh2D::energy
StkFloat energy(void)
Calculate and return the signal energy stored in the mesh.
stk::Mesh2D::setNX
void setNX(unsigned short lenX)
Set the x dimension size in samples.
stk::Mesh2D::inputTick
StkFloat inputTick(StkFloat input)
Input a sample to the mesh and compute one output sample.
stk::Mesh2D::noteOn
void noteOn(StkFloat frequency, StkFloat amplitude)
Impulse the mesh with the given amplitude (frequency ignored).
stk::Mesh2D::setInputPosition
void setInputPosition(StkFloat xFactor, StkFloat yFactor)
Set the x, y input position on a 0.0 - 1.0 scale.
stk::Mesh2D::setDecay
void setDecay(StkFloat decayFactor)
Set the loss filters gains (0.0 - 1.0).
stk::Mesh2D::~Mesh2D
~Mesh2D(void)
Class destructor.
stk::Mesh2D::controlChange
void controlChange(int number, StkFloat value)
Perform the control change specified by number and value (0.0 - 128.0).
stk::Mesh2D::tick
StkFloat tick(unsigned int channel=0)
Compute and return one output sample.
stk::Mesh2D::Mesh2D
Mesh2D(unsigned short nX, unsigned short nY)
Class constructor, taking the x and y dimensions in samples.
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.