Debian Codegraph @

lib-src/libnyquist/nyquist/nyqstk/include/SineWave.h

raw
1 /***************************************************/
2 /*! \class SineWave
3 \brief STK sinusoid oscillator class.
4
5 This class computes and saves a static sine "table" that can be
6 shared by multiple instances. It has an interface similar to the
7 WaveLoop class but inherits from the Generator class. Output
8 values are computed using linear interpolation.
9
10 The "table" length, set in SineWave.h, is 2048 samples by default.
11
12 by Perry R. Cook and Gary P. Scavone, 1995 - 2005.
13 */
14 /***************************************************/
15
16 #ifndef STK_SINEWAVE_H
17 #define STK_SINEWAVE_H
18
19 namespace Nyq
20 {
21
22 const unsigned long TABLE_SIZE = 2048;
23
24 } // namespace Nyq
25
26 #include "Generator.h"
27
28 namespace Nyq
29 {
30
31 class SineWave : public Generator
32 {
33 public:
34 //! Default constructor.
35 SineWave( void );
36
37 //! Class destructor.
38 virtual ~SineWave( void );
39
40 //! Clear output and reset time pointer to zero.
41 void reset( void );
42
43 //! Set the data read rate in samples. The rate can be negative.
44 /*!
45 If the rate value is negative, the data is read in reverse order.
46 */
47 void setRate( StkFloat rate ) { rate_ = rate; };
48
49 //! Set the data interpolation rate based on a looping frequency.
50 /*!
51 This function determines the interpolation rate based on the file
52 size and the current Stk::sampleRate. The \e frequency value
53 corresponds to file cycles per second. The frequency can be
54 negative, in which case the loop is read in reverse order.
55 */
56 void setFrequency( StkFloat frequency );
57
58 //! Increment the read pointer by \e time samples, modulo file size.
59 void addTime( StkFloat time );
60
61 //! Increment current read pointer by \e angle, relative to a looping frequency.
62 /*!
63 This function increments the read pointer based on the file
64 size and the current Stk::sampleRate. The \e anAngle value
65 is a multiple of file size.
66 */
67 void addPhase( StkFloat angle );
68
69 //! Add a phase offset to the current read pointer.
70 /*!
71 This function determines a time offset based on the file
72 size and the current Stk::sampleRate. The \e angle value
73 is a multiple of file size.
74 */
75 void addPhaseOffset( StkFloat angle );
76
77 protected:
78
79 StkFloat computeSample( void );
80
81 static StkFrames table_;
82 StkFloat time_;
83 StkFloat rate_;
84 StkFloat phaseOffset_;
85
86 };
87
88 } // namespace Nyq
89
90 #endif