Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


JetTable.h
1 #ifndef STK_JETTABL_H
2 #define STK_JETTABL_H
3 
4 #include "Function.h"
5 
6 namespace stk {
7 
8 /***************************************************/
21 /***************************************************/
22 
23 class JetTable : public Function
24 {
25 public:
26 
28  StkFloat tick( StkFloat input );
29 
31 
39  StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
40 
42 
50  StkFrames& tick( StkFrames& iFrames, StkFrames &oFrames, unsigned int iChannel = 0, unsigned int oChannel = 0 );
51 
52 };
53 
54 inline StkFloat JetTable :: tick( StkFloat input )
55 {
56  // Perform "table lookup" using a polynomial
57  // calculation (x^3 - x), which approximates
58  // the jet sigmoid behavior.
59  lastFrame_[0] = input * (input * input - 1.0);
60 
61  // Saturate at +/- 1.0.
62  if ( lastFrame_[0] > 1.0 ) lastFrame_[0] = 1.0;
63  if ( lastFrame_[0] < -1.0 ) lastFrame_[0] = -1.0;
64  return lastFrame_[0];
65 }
66 
67 inline StkFrames& JetTable :: tick( StkFrames& frames, unsigned int channel )
68 {
69 #if defined(_STK_DEBUG_)
70  if ( channel >= frames.channels() ) {
71  oStream_ << "JetTable::tick(): channel and StkFrames arguments are incompatible!";
72  handleError( StkError::FUNCTION_ARGUMENT );
73  }
74 #endif
75 
76  StkFloat *samples = &frames[channel];
77  unsigned int hop = frames.channels();
78  for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
79  *samples = *samples * (*samples * *samples - 1.0);
80  if ( *samples > 1.0) *samples = 1.0;
81  if ( *samples < -1.0) *samples = -1.0;
82  }
83 
84  lastFrame_[0] = *(samples-hop);
85  return frames;
86 }
87 
88 inline StkFrames& JetTable :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
89 {
90 #if defined(_STK_DEBUG_)
91  if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
92  oStream_ << "JetTable::tick(): channel and StkFrames arguments are incompatible!";
93  handleError( StkError::FUNCTION_ARGUMENT );
94  }
95 #endif
96 
97  StkFloat *iSamples = &iFrames[iChannel];
98  StkFloat *oSamples = &oFrames[oChannel];
99  unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
100  for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
101  *oSamples = *oSamples * (*oSamples * *oSamples - 1.0);
102  if ( *oSamples > 1.0) *oSamples = 1.0;
103  if ( *oSamples < -1.0) *oSamples = -1.0;
104  }
105 
106  lastFrame_[0] = *(oSamples-oHop);
107  return iFrames;
108 }
109 
110 } // stk namespace
111 
112 #endif

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