The Synthesis ToolKit in C++ (STK)

Home Information Classes Download Usage Mail List Requirements Links FAQ Tutorial

BowTable.h
1 #ifndef STK_BOWTABL_H
2 #define STK_BOWTABL_H
3
4 #include "Function.h"
5 #include <cmath>
6
7 namespace stk {
8
9 /***************************************************/
20 /***************************************************/
21
22 class BowTable : public Function
23 {
24 public:
26 BowTable( void ) : offset_(0.0), slope_(0.1), minOutput_(0.01), maxOutput_(0.98) {};
27
29
35 void setOffset( StkFloat offset ) { offset_ = offset; };
36
38
42 void setSlope( StkFloat slope ) { slope_ = slope; };
43
45 void setMinOutput( StkFloat minimum ) { minOutput_ = minimum; };
46
48 void setMaxOutput( StkFloat maximum ) { maxOutput_ = maximum; };
49
51 StkFloat tick( StkFloat input );
52
54
62 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
63
65
73 StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
74
75 protected:
76
77 StkFloat offset_;
78 StkFloat slope_;
79 StkFloat minOutput_;
80 StkFloat maxOutput_;
81
82 };
83
84 inline StkFloat BowTable :: tick( StkFloat input )
85 {
86 // The input represents differential string vs. bow velocity.
87 StkFloat sample = input + offset_; // add bias to input
88 sample *= slope_; // then scale it
89 lastFrame_[0] = (StkFloat) fabs( (double) sample ) + (StkFloat) 0.75;
90 lastFrame_[0] = (StkFloat) pow( lastFrame_[0], (StkFloat) -4.0 );
91
92 // Set minimum threshold
93 if ( lastFrame_[0] < minOutput_ ) lastFrame_[0] = minOutput_;
94
95 // Set maximum threshold
96 if ( lastFrame_[0] > maxOutput_ ) lastFrame_[0] = maxOutput_;
97
98 return lastFrame_[0];
99 }
100
101 inline StkFrames& BowTable :: tick( StkFrames& frames, unsigned int channel )
102 {
103 #if defined(_STK_DEBUG_)
104 if ( channel >= frames.channels() ) {
105 oStream_ << "BowTable::tick(): channel and StkFrames arguments are incompatible!";
106 handleError( StkError::FUNCTION_ARGUMENT );
107 }
108 #endif
109
110 StkFloat *samples = &frames[channel];
111 unsigned int hop = frames.channels();
112 for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
113 *samples = *samples + offset_;
114 *samples *= slope_;
115 *samples = (StkFloat) fabs( (double) *samples ) + 0.75;
116 *samples = (StkFloat) pow( *samples, (StkFloat) -4.0 );
117 if ( *samples > 1.0) *samples = 1.0;
118 }
119
120 lastFrame_[0] = *(samples-hop);
121 return frames;
122 }
123
124 inline StkFrames& BowTable :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
125 {
126 #if defined(_STK_DEBUG_)
127 if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
128 oStream_ << "BowTable::tick(): channel and StkFrames arguments are incompatible!";
129 handleError( StkError::FUNCTION_ARGUMENT );
130 }
131 #endif
132
133 StkFloat *iSamples = &iFrames[iChannel];
134 StkFloat *oSamples = &oFrames[oChannel];
135 unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
136 for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
137 *oSamples = *iSamples + offset_;
138 *oSamples *= slope_;
139 *oSamples = (StkFloat) fabs( (double) *oSamples ) + 0.75;
140 *oSamples = (StkFloat) pow( *oSamples, (StkFloat) -4.0 );
141 if ( *oSamples > 1.0) *oSamples = 1.0;
142 }
143
144 lastFrame_[0] = *(oSamples-oHop);
145 return iFrames;
146 }
147
148 } // stk namespace
149
150 #endif

The Synthesis ToolKit in C++ (STK)
©1995--2017 Perry R. Cook and Gary P. Scavone. All Rights Reserved.