Debian Codegraph @

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

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