1 /***************************************************/
2 /*! \class Function
3     \brief STK abstract function parent class.
4 
5     This class provides common functionality for STK classes which
6     implement tables or other types of input to output function
7     mappings.
8 
9     by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
10 */
11 /***************************************************/
12 
13 #include "Function.h"
14 
15 using namespace Nyq;
16 
Function()17 Function :: Function() : Stk()
18 {
19   lastOutput_ = (StkFloat) 0.0;
20 }
21 
~Function()22 Function :: ~Function()
23 {
24 }
25 
tick(StkFloat input)26 StkFloat Function :: tick( StkFloat input )
27 {
28   return computeSample( input );
29 }
30 
tick(StkFrames & frames,unsigned int channel)31 StkFrames& Function :: tick( StkFrames& frames, unsigned int channel )
32 {
33   if ( channel >= frames.channels() ) {
34     errorString_ << "Function::tick(): channel and StkFrames arguments are incompatible!";
35     handleError( StkError::FUNCTION_ARGUMENT );
36   }
37 
38   if ( frames.channels() == 1 ) {
39     for ( unsigned int i=0; i<frames.frames(); i++ )
40       frames[i] = computeSample( frames[i] );
41   }
42   else if ( frames.interleaved() ) {
43     unsigned int hop = frames.channels();
44     unsigned int index = channel;
45     for ( unsigned int i=0; i<frames.frames(); i++ ) {
46       frames[index] = computeSample( frames[index] );
47       index += hop;
48     }
49   }
50   else {
51     unsigned int iStart = channel * frames.frames();
52     for ( unsigned int i=0; i<frames.frames(); i++, iStart++ )
53       frames[iStart] = computeSample( frames[iStart] );
54   }
55 
56   return frames;
57 }
58