Debian Codegraph @

lib-src/libnyquist/nyquist/nyqstk/src/BowTable.cpp

raw
1 /***************************************************/
2 /*! \class BowTable
3 \brief STK bowed string table class.
4
5 This class implements a simple bowed string
6 non-linear function, as described by Smith (1986).
7
8 by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
9 */
10 /***************************************************/
11
12 #include "BowTable.h"
13 #include <math.h>
14
15 using namespace Nyq;
16
17 BowTable :: BowTable()
18 {
19 offset_ = (StkFloat) 0.0;
20 slope_ = (StkFloat) 0.1;
21 }
22
23 BowTable :: ~BowTable()
24 {
25 }
26
27 void BowTable :: setOffset(StkFloat offset)
28 {
29 offset_ = offset;
30 }
31
32 void BowTable :: setSlope(StkFloat slope)
33 {
34 slope_ = slope;
35 }
36
37 StkFloat BowTable :: computeSample(StkFloat input)
38 {
39 // The input represents differential string vs. bow velocity.
40 StkFloat sample;
41 sample = input + offset_; // add bias to input
42 sample *= slope_; // then scale it
43 lastOutput_ = (StkFloat) fabs( (double) sample ) + (StkFloat) 0.75;
44 lastOutput_ = (StkFloat) pow( lastOutput_, (StkFloat) -4.0 );
45
46 // Set minimum friction to 0.0
47 // if (lastOutput < 0.0 ) lastOutput = 0.0;
48 // Set maximum friction to 1.0.
49 if (lastOutput_ > 1.0 ) lastOutput_ = (StkFloat) 1.0;
50
51 return lastOutput_;
52 }
53