Arduino STK  4.6.2
ReedTable.h
1 #ifndef STK_REEDTABLE_H
2 #define STK_REEDTABLE_H
3 
4 #include "Function.h"
5 
6 namespace stk {
7 
8 /***************************************************/
25 /***************************************************/
26 
27 class ReedTable : public Function
28 {
29 public:
31  ReedTable( void ) : offset_(0.6), slope_(-0.8) {};
32 
34 
39  void setOffset( StkFloat offset ) { offset_ = offset; };
40 
42 
47  void setSlope( StkFloat slope ) { slope_ = slope; };
48 
50  StkFloat tick( StkFloat input );
51 
53 
61  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
62 
64 
72  StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
73 
74 protected:
75 
76  StkFloat offset_;
77  StkFloat slope_;
78 
79 };
80 
81 inline StkFloat ReedTable :: tick( StkFloat input )
82 {
83  // The input is differential pressure across the reed.
84  lastFrame_[0] = offset_ + (slope_ * input);
85 
86  // If output is > 1, the reed has slammed shut and the
87  // reflection function value saturates at 1.0.
88  if ( lastFrame_[0] > 1.0) lastFrame_[0] = (StkFloat) 1.0;
89 
90  // This is nearly impossible in a physical system, but
91  // a reflection function value of -1.0 corresponds to
92  // an open end (and no discontinuity in bore profile).
93  if ( lastFrame_[0] < -1.0) lastFrame_[0] = (StkFloat) -1.0;
94 
95  return lastFrame_[0];
96 }
97 
98 inline StkFrames& ReedTable :: tick( StkFrames& frames, unsigned int channel )
99 {
100 #if defined(_STK_DEBUG_)
101  if ( channel >= frames.channels() ) {
102  oStream_ << "ReedTable::tick(): channel and StkFrames arguments are incompatible!";
103  handleError( StkError::FUNCTION_ARGUMENT );
104  }
105 #endif
106 
107  StkFloat *samples = &frames[channel];
108  unsigned int hop = frames.channels();
109  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
110  *samples = offset_ + (slope_ * *samples);
111  if ( *samples > 1.0) *samples = 1.0;
112  if ( *samples < -1.0) *samples = -1.0;
113  }
114 
115  lastFrame_[0] = *(samples-hop);
116  return frames;
117 }
118 
119 inline StkFrames& ReedTable :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
120 {
121 #if defined(_STK_DEBUG_)
122  if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
123  oStream_ << "ReedTable::tick(): channel and StkFrames arguments are incompatible!";
124  handleError( StkError::FUNCTION_ARGUMENT );
125  }
126 #endif
127 
128  StkFloat *iSamples = &iFrames[iChannel];
129  StkFloat *oSamples = &oFrames[oChannel];
130  unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
131  for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
132  *oSamples = offset_ + (slope_ * *iSamples);
133  if ( *oSamples > 1.0) *oSamples = 1.0;
134  if ( *oSamples < -1.0) *oSamples = -1.0;
135  }
136 
137  lastFrame_[0] = *(oSamples-oHop);
138  return iFrames;
139 }
140 
141 } // stk namespace
142 
143 #endif
STK abstract function parent class.
Definition: Function.h:21
STK reed table class.
Definition: ReedTable.h:28
ReedTable(void)
Default constructor.
Definition: ReedTable.h:31
StkFloat tick(StkFloat input)
Take one sample input and map to one sample of output.
Definition: ReedTable.h:81
void setSlope(StkFloat slope)
Set the table slope value.
Definition: ReedTable.h:47
void setOffset(StkFloat offset)
Set the table offset value.
Definition: ReedTable.h:39
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.
The STK namespace.
Definition: ADSR.h:8