beeps 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.doc/ext/beeps/beeps.cpp +0 -5
- data/.doc/ext/beeps/file_in.cpp +0 -5
- data/.doc/ext/beeps/native.cpp +0 -4
- data/.doc/ext/beeps/processor.cpp +1 -5
- data/.doc/ext/beeps/sawtooth_wave.cpp +0 -5
- data/.doc/ext/beeps/sine_wave.cpp +0 -5
- data/.doc/ext/beeps/sound.cpp +0 -5
- data/.doc/ext/beeps/square_wave.cpp +0 -5
- data/README.md +1 -1
- data/Rakefile +15 -12
- data/VERSION +1 -1
- data/beeps.gemspec +5 -7
- data/ext/beeps/beeps.cpp +0 -5
- data/ext/beeps/defs.h +3 -2
- data/ext/beeps/extconf.rb +2 -3
- data/ext/beeps/file_in.cpp +0 -5
- data/ext/beeps/native.cpp +0 -4
- data/ext/beeps/processor.cpp +1 -5
- data/ext/beeps/sawtooth_wave.cpp +0 -5
- data/ext/beeps/sine_wave.cpp +0 -5
- data/ext/beeps/sound.cpp +0 -5
- data/ext/beeps/square_wave.cpp +0 -5
- data/include/beeps.h +5 -0
- data/include/beeps/debug.h +23 -0
- data/include/beeps/processor.h +9 -6
- data/include/beeps/signals.h +2 -9
- data/include/beeps/sound.h +2 -1
- data/lib/beeps/module.rb +4 -19
- data/lib/beeps/processor.rb +16 -20
- data/src/beeps.cpp +3 -64
- data/src/exception.cpp +0 -3
- data/src/openal.cpp +63 -174
- data/src/openal.h +15 -4
- data/src/processor.cpp +5 -5
- data/src/signals.cpp +21 -19
- data/src/signals.h +23 -0
- data/src/sound.cpp +173 -14
- data/src/sound.h +17 -0
- metadata +27 -70
- data/include/beeps/openal.h +0 -34
- data/src/stk/include/Blit.h +0 -151
- data/src/stk/include/BlitSaw.h +0 -148
- data/src/stk/include/BlitSquare.h +0 -170
- data/src/stk/include/FileRead.h +0 -141
- data/src/stk/include/FileWvIn.h +0 -195
- data/src/stk/include/Generator.h +0 -50
- data/src/stk/include/SineWave.h +0 -159
- data/src/stk/include/Stk.h +0 -589
- data/src/stk/include/WvIn.h +0 -46
- data/src/stk/src/Blit.cpp +0 -78
- data/src/stk/src/BlitSaw.cpp +0 -91
- data/src/stk/src/BlitSquare.cpp +0 -95
- data/src/stk/src/FileRead.cpp +0 -903
- data/src/stk/src/FileWvIn.cpp +0 -260
- data/src/stk/src/SineWave.cpp +0 -78
- data/src/stk/src/Stk.cpp +0 -395
data/src/stk/include/FileRead.h
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
#ifndef STK_FILEREAD_H
|
2
|
-
#define STK_FILEREAD_H
|
3
|
-
|
4
|
-
#include "Stk.h"
|
5
|
-
|
6
|
-
namespace stk {
|
7
|
-
|
8
|
-
/***************************************************/
|
9
|
-
/*! \class FileRead
|
10
|
-
\brief STK audio file input class.
|
11
|
-
|
12
|
-
This class provides input support for various
|
13
|
-
audio file formats. Multi-channel (>2)
|
14
|
-
soundfiles are supported. The file data is
|
15
|
-
returned via an external StkFrames object
|
16
|
-
passed to the read() function. This class
|
17
|
-
does not store its own copy of the file data,
|
18
|
-
rather the data is read directly from disk.
|
19
|
-
|
20
|
-
FileRead currently supports uncompressed WAV,
|
21
|
-
AIFF/AIFC, SND (AU), MAT-file (Matlab), and
|
22
|
-
STK RAW file formats. Signed integer (8-,
|
23
|
-
16-, 24-, and 32-bit) and floating-point (32- and
|
24
|
-
64-bit) data types are supported. Compressed
|
25
|
-
data types are not supported.
|
26
|
-
|
27
|
-
STK RAW files have no header and are assumed to
|
28
|
-
contain a monophonic stream of 16-bit signed
|
29
|
-
integers in big-endian byte order at a sample
|
30
|
-
rate of 22050 Hz. MAT-file data should be saved
|
31
|
-
in an array with each data channel filling a
|
32
|
-
matrix row. The sample rate for MAT-files should
|
33
|
-
be specified in a variable named "fs". If no
|
34
|
-
such variable is found, the sample rate is
|
35
|
-
assumed to be 44100 Hz.
|
36
|
-
|
37
|
-
by Perry R. Cook and Gary P. Scavone, 1995--2014.
|
38
|
-
*/
|
39
|
-
/***************************************************/
|
40
|
-
|
41
|
-
class FileRead : public Stk
|
42
|
-
{
|
43
|
-
public:
|
44
|
-
//! Default constructor.
|
45
|
-
FileRead( void );
|
46
|
-
|
47
|
-
//! Overloaded constructor that opens a file during instantiation.
|
48
|
-
/*!
|
49
|
-
An StkError will be thrown if the file is not found or its
|
50
|
-
format is unknown or unsupported. The optional arguments allow a
|
51
|
-
headerless file type to be supported. If \c typeRaw is false (the
|
52
|
-
default), the subsequent parameters are ignored.
|
53
|
-
*/
|
54
|
-
FileRead( std::string fileName, bool typeRaw = false, unsigned int nChannels = 1,
|
55
|
-
StkFormat format = STK_SINT16, StkFloat rate = 22050.0 );
|
56
|
-
|
57
|
-
//! Class destructor.
|
58
|
-
~FileRead( void );
|
59
|
-
|
60
|
-
//! Open the specified file and determine its formatting.
|
61
|
-
/*!
|
62
|
-
An StkError will be thrown if the file is not found or its
|
63
|
-
format is unknown or unsupported. The optional arguments allow a
|
64
|
-
headerless file type to be supported. If \c typeRaw is false (the
|
65
|
-
default), the subsequent parameters are ignored.
|
66
|
-
*/
|
67
|
-
void open( std::string fileName, bool typeRaw = false, unsigned int nChannels = 1,
|
68
|
-
StkFormat format = STK_SINT16, StkFloat rate = 22050.0 );
|
69
|
-
|
70
|
-
//! If a file is open, close it.
|
71
|
-
void close( void );
|
72
|
-
|
73
|
-
//! Returns \e true if a file is currently open.
|
74
|
-
bool isOpen( void );
|
75
|
-
|
76
|
-
//! Return the file size in sample frames.
|
77
|
-
unsigned long fileSize( void ) const { return fileSize_; };
|
78
|
-
|
79
|
-
//! Return the number of audio channels in the file.
|
80
|
-
unsigned int channels( void ) const { return channels_; };
|
81
|
-
|
82
|
-
//! Return the data format of the file.
|
83
|
-
StkFormat format( void ) const { return dataType_; };
|
84
|
-
|
85
|
-
//! Return the file sample rate in Hz.
|
86
|
-
/*!
|
87
|
-
WAV, SND, and AIF formatted files specify a sample rate in
|
88
|
-
their headers. By definition, STK RAW files have a sample rate of
|
89
|
-
22050 Hz. MAT-files are assumed to have a rate of 44100 Hz.
|
90
|
-
*/
|
91
|
-
StkFloat fileRate( void ) const { return fileRate_; };
|
92
|
-
|
93
|
-
//! Read sample frames from the file into an StkFrames object.
|
94
|
-
/*!
|
95
|
-
The number of sample frames to read will be determined from the
|
96
|
-
number of frames of the StkFrames argument. If this size is
|
97
|
-
larger than the available data in the file (given the file size
|
98
|
-
and starting frame index), the extra frames will be unaffected
|
99
|
-
(the StkFrames object will not be resized). Optional parameters
|
100
|
-
are provided to specify the starting sample frame within the file
|
101
|
-
(default = 0) and whether to normalize the data with respect to
|
102
|
-
fixed-point limits (default = true). An StkError will be thrown
|
103
|
-
if a file error occurs or if the number of channels in the
|
104
|
-
StkFrames argument is not equal to that in the file.
|
105
|
-
*/
|
106
|
-
void read( StkFrames& buffer, unsigned long startFrame = 0, bool doNormalize = true );
|
107
|
-
|
108
|
-
protected:
|
109
|
-
|
110
|
-
// Get STK RAW file information.
|
111
|
-
bool getRawInfo( const char *fileName, unsigned int nChannels,
|
112
|
-
StkFormat format, StkFloat rate );
|
113
|
-
|
114
|
-
// Get WAV file header information.
|
115
|
-
bool getWavInfo( const char *fileName );
|
116
|
-
|
117
|
-
// Get SND (AU) file header information.
|
118
|
-
bool getSndInfo( const char *fileName );
|
119
|
-
|
120
|
-
// Get AIFF file header information.
|
121
|
-
bool getAifInfo( const char *fileName );
|
122
|
-
|
123
|
-
// Get MAT-file header information.
|
124
|
-
bool getMatInfo( const char *fileName );
|
125
|
-
|
126
|
-
// Helper function for MAT-file parsing.
|
127
|
-
bool findNextMatArray( SINT32 *chunkSize, SINT32 *rows, SINT32 *columns, SINT32 *nametype );
|
128
|
-
|
129
|
-
FILE *fd_;
|
130
|
-
bool byteswap_;
|
131
|
-
bool wavFile_;
|
132
|
-
unsigned long fileSize_;
|
133
|
-
unsigned long dataOffset_;
|
134
|
-
unsigned int channels_;
|
135
|
-
StkFormat dataType_;
|
136
|
-
StkFloat fileRate_;
|
137
|
-
};
|
138
|
-
|
139
|
-
} // stk namespace
|
140
|
-
|
141
|
-
#endif
|
data/src/stk/include/FileWvIn.h
DELETED
@@ -1,195 +0,0 @@
|
|
1
|
-
#ifndef STK_FILEWVIN_H
|
2
|
-
#define STK_FILEWVIN_H
|
3
|
-
|
4
|
-
#include "WvIn.h"
|
5
|
-
#include "FileRead.h"
|
6
|
-
|
7
|
-
namespace stk {
|
8
|
-
|
9
|
-
/***************************************************/
|
10
|
-
/*! \class FileWvIn
|
11
|
-
\brief STK audio file input class.
|
12
|
-
|
13
|
-
This class inherits from WvIn. It provides a "tick-level"
|
14
|
-
interface to the FileRead class. It also provides variable-rate
|
15
|
-
playback functionality. Audio file support is provided by the
|
16
|
-
FileRead class. Linear interpolation is used for fractional read
|
17
|
-
rates.
|
18
|
-
|
19
|
-
FileWvIn supports multi-channel data. It is important to
|
20
|
-
distinguish the tick() method that computes a single frame (and
|
21
|
-
returns only the specified sample of a multi-channel frame) from
|
22
|
-
the overloaded one that takes an StkFrames object for
|
23
|
-
multi-channel and/or multi-frame data.
|
24
|
-
|
25
|
-
FileWvIn will either load the entire content of an audio file into
|
26
|
-
local memory or incrementally read file data from disk in chunks.
|
27
|
-
This behavior is controlled by the optional constructor arguments
|
28
|
-
\e chunkThreshold and \e chunkSize. File sizes greater than \e
|
29
|
-
chunkThreshold (in sample frames) will be read incrementally in
|
30
|
-
chunks of \e chunkSize each (also in sample frames).
|
31
|
-
|
32
|
-
When the file end is reached, subsequent calls to the tick()
|
33
|
-
functions return zeros and isFinished() returns \e true.
|
34
|
-
|
35
|
-
See the FileRead class for a description of the supported audio
|
36
|
-
file formats.
|
37
|
-
|
38
|
-
by Perry R. Cook and Gary P. Scavone, 1995--2014.
|
39
|
-
*/
|
40
|
-
/***************************************************/
|
41
|
-
|
42
|
-
class FileWvIn : public WvIn
|
43
|
-
{
|
44
|
-
public:
|
45
|
-
//! Default constructor.
|
46
|
-
FileWvIn( unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
|
47
|
-
|
48
|
-
//! Overloaded constructor for file input.
|
49
|
-
/*!
|
50
|
-
An StkError will be thrown if the file is not found, its format is
|
51
|
-
unknown, or a read error occurs.
|
52
|
-
*/
|
53
|
-
FileWvIn( std::string fileName, bool raw = false, bool doNormalize = true,
|
54
|
-
unsigned long chunkThreshold = 1000000, unsigned long chunkSize = 1024 );
|
55
|
-
|
56
|
-
//! Class destructor.
|
57
|
-
~FileWvIn( void );
|
58
|
-
|
59
|
-
//! Open the specified file and load its data.
|
60
|
-
/*!
|
61
|
-
Data from a previously opened file will be overwritten by this
|
62
|
-
function. An StkError will be thrown if the file is not found,
|
63
|
-
its format is unknown, or a read error occurs. If the file data
|
64
|
-
is to be loaded incrementally from disk and normalization is
|
65
|
-
specified, a scaling will be applied with respect to fixed-point
|
66
|
-
limits. If the data format is floating-point, no scaling is
|
67
|
-
performed.
|
68
|
-
*/
|
69
|
-
virtual void openFile( std::string fileName, bool raw = false, bool doNormalize = true );
|
70
|
-
|
71
|
-
//! Close a file if one is open.
|
72
|
-
virtual void closeFile( void );
|
73
|
-
|
74
|
-
//! Clear outputs and reset time (file) pointer to zero.
|
75
|
-
virtual void reset( void );
|
76
|
-
|
77
|
-
//! Normalize data to a maximum of +-1.0.
|
78
|
-
/*!
|
79
|
-
This function has no effect when data is incrementally loaded
|
80
|
-
from disk.
|
81
|
-
*/
|
82
|
-
virtual void normalize( void );
|
83
|
-
|
84
|
-
//! Normalize data to a maximum of \e +-peak.
|
85
|
-
/*!
|
86
|
-
This function has no effect when data is incrementally loaded
|
87
|
-
from disk.
|
88
|
-
*/
|
89
|
-
virtual void normalize( StkFloat peak );
|
90
|
-
|
91
|
-
//! Return the file size in sample frames.
|
92
|
-
virtual unsigned long getSize( void ) const { return file_.fileSize(); };
|
93
|
-
|
94
|
-
//! Return the input file sample rate in Hz (not the data read rate).
|
95
|
-
/*!
|
96
|
-
WAV, SND, and AIF formatted files specify a sample rate in
|
97
|
-
their headers. STK RAW files have a sample rate of 22050 Hz
|
98
|
-
by definition. MAT-files are assumed to have a rate of 44100 Hz.
|
99
|
-
*/
|
100
|
-
virtual StkFloat getFileRate( void ) const { return data_.dataRate(); };
|
101
|
-
|
102
|
-
//! Query whether a file is open.
|
103
|
-
bool isOpen( void ) { return file_.isOpen(); };
|
104
|
-
|
105
|
-
//! Query whether reading is complete.
|
106
|
-
bool isFinished( void ) const { return finished_; };
|
107
|
-
|
108
|
-
//! Set the data read rate in samples. The rate can be negative.
|
109
|
-
/*!
|
110
|
-
If the rate value is negative, the data is read in reverse order.
|
111
|
-
*/
|
112
|
-
virtual void setRate( StkFloat rate );
|
113
|
-
|
114
|
-
//! Increment the read pointer by \e time samples.
|
115
|
-
/*!
|
116
|
-
Note that this function will not modify the interpolation flag status.
|
117
|
-
*/
|
118
|
-
virtual void addTime( StkFloat time );
|
119
|
-
|
120
|
-
//! Turn linear interpolation on/off.
|
121
|
-
/*!
|
122
|
-
Interpolation is automatically off when the read rate is
|
123
|
-
an integer value. If interpolation is turned off for a
|
124
|
-
fractional rate, the time index is truncated to an integer
|
125
|
-
value.
|
126
|
-
*/
|
127
|
-
void setInterpolate( bool doInterpolate ) { interpolate_ = doInterpolate; };
|
128
|
-
|
129
|
-
//! Return the specified channel value of the last computed frame.
|
130
|
-
/*!
|
131
|
-
If no file is loaded, the returned value is 0.0. The \c
|
132
|
-
channel argument must be less than the number of output channels,
|
133
|
-
which can be determined with the channelsOut() function (the first
|
134
|
-
channel is specified by 0). However, range checking is only
|
135
|
-
performed if _STK_DEBUG_ is defined during compilation, in which
|
136
|
-
case an out-of-range value will trigger an StkError exception. \sa
|
137
|
-
lastFrame()
|
138
|
-
*/
|
139
|
-
StkFloat lastOut( unsigned int channel = 0 );
|
140
|
-
|
141
|
-
//! Compute a sample frame and return the specified \c channel value.
|
142
|
-
/*!
|
143
|
-
For multi-channel files, use the lastFrame() function to get
|
144
|
-
all values from the computed frame. If no file data is loaded,
|
145
|
-
the returned value is 0.0. The \c channel argument must be less
|
146
|
-
than the number of channels in the file data (the first channel is
|
147
|
-
specified by 0). However, range checking is only performed if
|
148
|
-
_STK_DEBUG_ is defined during compilation, in which case an
|
149
|
-
out-of-range value will trigger an StkError exception.
|
150
|
-
*/
|
151
|
-
virtual StkFloat tick( unsigned int channel = 0 );
|
152
|
-
|
153
|
-
//! Fill the StkFrames object with computed sample frames, starting at the specified channel and return the same reference.
|
154
|
-
/*!
|
155
|
-
The \c channel argument plus the number of input channels must
|
156
|
-
be less than the number of channels in the StkFrames argument (the
|
157
|
-
first channel is specified by 0). However, range checking is only
|
158
|
-
performed if _STK_DEBUG_ is defined during compilation, in which
|
159
|
-
case an out-of-range value will trigger an StkError exception.
|
160
|
-
*/
|
161
|
-
virtual StkFrames& tick( StkFrames& frames,unsigned int channel = 0 );
|
162
|
-
|
163
|
-
protected:
|
164
|
-
|
165
|
-
void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
|
166
|
-
|
167
|
-
FileRead file_;
|
168
|
-
bool finished_;
|
169
|
-
bool interpolate_;
|
170
|
-
bool normalizing_;
|
171
|
-
bool chunking_;
|
172
|
-
StkFloat time_;
|
173
|
-
StkFloat rate_;
|
174
|
-
unsigned long chunkThreshold_;
|
175
|
-
unsigned long chunkSize_;
|
176
|
-
long chunkPointer_;
|
177
|
-
|
178
|
-
};
|
179
|
-
|
180
|
-
inline StkFloat FileWvIn :: lastOut( unsigned int channel )
|
181
|
-
{
|
182
|
-
#if defined(_STK_DEBUG_)
|
183
|
-
if ( channel >= data_.channels() ) {
|
184
|
-
oStream_ << "FileWvIn::lastOut(): channel argument and soundfile data are incompatible!";
|
185
|
-
handleError( StkError::FUNCTION_ARGUMENT );
|
186
|
-
}
|
187
|
-
#endif
|
188
|
-
|
189
|
-
if ( finished_ ) return 0.0;
|
190
|
-
return lastFrame_[channel];
|
191
|
-
}
|
192
|
-
|
193
|
-
} // stk namespace
|
194
|
-
|
195
|
-
#endif
|
data/src/stk/include/Generator.h
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
#ifndef STK_GENERATOR_H
|
2
|
-
#define STK_GENERATOR_H
|
3
|
-
|
4
|
-
#include "Stk.h"
|
5
|
-
|
6
|
-
namespace stk {
|
7
|
-
|
8
|
-
/***************************************************/
|
9
|
-
/*! \class Generator
|
10
|
-
\brief STK abstract unit generator parent class.
|
11
|
-
|
12
|
-
This class provides limited common functionality for STK unit
|
13
|
-
generator sample-source subclasses. It is general enough to
|
14
|
-
support both monophonic and polyphonic output classes.
|
15
|
-
|
16
|
-
by Perry R. Cook and Gary P. Scavone, 1995--2014.
|
17
|
-
*/
|
18
|
-
/***************************************************/
|
19
|
-
|
20
|
-
class Generator : public Stk
|
21
|
-
{
|
22
|
-
public:
|
23
|
-
|
24
|
-
//! Class constructor.
|
25
|
-
Generator( void ) { lastFrame_.resize( 1, 1, 0.0 ); };
|
26
|
-
|
27
|
-
//! Return the number of output channels for the class.
|
28
|
-
unsigned int channelsOut( void ) const { return lastFrame_.channels(); };
|
29
|
-
|
30
|
-
//! Return an StkFrames reference to the last output sample frame.
|
31
|
-
const StkFrames& lastFrame( void ) const { return lastFrame_; };
|
32
|
-
|
33
|
-
//! Fill the StkFrames object with computed sample frames, starting at the specified channel.
|
34
|
-
/*!
|
35
|
-
The \c channel argument plus the number of output channels must
|
36
|
-
be less than the number of channels in the StkFrames argument (the
|
37
|
-
first channel is specified by 0). However, range checking is only
|
38
|
-
performed if _STK_DEBUG_ is defined during compilation, in which
|
39
|
-
case an out-of-range value will trigger an StkError exception.
|
40
|
-
*/
|
41
|
-
virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ) = 0;
|
42
|
-
|
43
|
-
protected:
|
44
|
-
|
45
|
-
StkFrames lastFrame_;
|
46
|
-
};
|
47
|
-
|
48
|
-
} // stk namespace
|
49
|
-
|
50
|
-
#endif
|
data/src/stk/include/SineWave.h
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
#ifndef STK_SINEWAVE_H
|
2
|
-
#define STK_SINEWAVE_H
|
3
|
-
|
4
|
-
const unsigned long TABLE_SIZE = 2048;
|
5
|
-
|
6
|
-
#include "Generator.h"
|
7
|
-
|
8
|
-
namespace stk {
|
9
|
-
|
10
|
-
/***************************************************/
|
11
|
-
/*! \class SineWave
|
12
|
-
\brief STK sinusoid oscillator class.
|
13
|
-
|
14
|
-
This class computes and saves a static sine "table" that can be
|
15
|
-
shared by multiple instances. It has an interface similar to the
|
16
|
-
WaveLoop class but inherits from the Generator class. Output
|
17
|
-
values are computed using linear interpolation.
|
18
|
-
|
19
|
-
The "table" length, set in SineWave.h, is 2048 samples by default.
|
20
|
-
|
21
|
-
by Perry R. Cook and Gary P. Scavone, 1995--2014.
|
22
|
-
*/
|
23
|
-
/***************************************************/
|
24
|
-
|
25
|
-
class SineWave : public Generator
|
26
|
-
{
|
27
|
-
public:
|
28
|
-
//! Default constructor.
|
29
|
-
SineWave( void );
|
30
|
-
|
31
|
-
//! Class destructor.
|
32
|
-
~SineWave( void );
|
33
|
-
|
34
|
-
//! Clear output and reset time pointer to zero.
|
35
|
-
void reset( void );
|
36
|
-
|
37
|
-
//! Set the data read rate in samples. The rate can be negative.
|
38
|
-
/*!
|
39
|
-
If the rate value is negative, the data is read in reverse order.
|
40
|
-
*/
|
41
|
-
void setRate( StkFloat rate ) { rate_ = rate; };
|
42
|
-
|
43
|
-
//! Set the data interpolation rate based on a looping frequency.
|
44
|
-
/*!
|
45
|
-
This function determines the interpolation rate based on the file
|
46
|
-
size and the current Stk::sampleRate. The \e frequency value
|
47
|
-
corresponds to file cycles per second. The frequency can be
|
48
|
-
negative, in which case the loop is read in reverse order.
|
49
|
-
*/
|
50
|
-
void setFrequency( StkFloat frequency );
|
51
|
-
|
52
|
-
//! Increment the read pointer by \e time in samples, modulo the table size.
|
53
|
-
void addTime( StkFloat time );
|
54
|
-
|
55
|
-
//! Increment the read pointer by a normalized \e phase value.
|
56
|
-
/*!
|
57
|
-
This function increments the read pointer by a normalized phase
|
58
|
-
value, such that \e phase = 1.0 corresponds to a 360 degree phase
|
59
|
-
shift. Positive or negative values are possible.
|
60
|
-
*/
|
61
|
-
void addPhase( StkFloat phase );
|
62
|
-
|
63
|
-
//! Add a normalized phase offset to the read pointer.
|
64
|
-
/*!
|
65
|
-
A \e phaseOffset = 1.0 corresponds to a 360 degree phase
|
66
|
-
offset. Positive or negative values are possible.
|
67
|
-
*/
|
68
|
-
void addPhaseOffset( StkFloat phaseOffset );
|
69
|
-
|
70
|
-
//! Return the last computed output value.
|
71
|
-
StkFloat lastOut( void ) const { return lastFrame_[0]; };
|
72
|
-
|
73
|
-
//! Compute and return one output sample.
|
74
|
-
StkFloat tick( void );
|
75
|
-
|
76
|
-
//! Fill a channel of the StkFrames object with computed outputs.
|
77
|
-
/*!
|
78
|
-
The \c channel argument must be less than the number of
|
79
|
-
channels in the StkFrames argument (the first channel is specified
|
80
|
-
by 0). However, range checking is only performed if _STK_DEBUG_
|
81
|
-
is defined during compilation, in which case an out-of-range value
|
82
|
-
will trigger an StkError exception.
|
83
|
-
*/
|
84
|
-
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
|
85
|
-
|
86
|
-
protected:
|
87
|
-
|
88
|
-
void sampleRateChanged( StkFloat newRate, StkFloat oldRate );
|
89
|
-
|
90
|
-
static StkFrames table_;
|
91
|
-
StkFloat time_;
|
92
|
-
StkFloat rate_;
|
93
|
-
StkFloat phaseOffset_;
|
94
|
-
unsigned int iIndex_;
|
95
|
-
StkFloat alpha_;
|
96
|
-
|
97
|
-
};
|
98
|
-
|
99
|
-
inline StkFloat SineWave :: tick( void )
|
100
|
-
{
|
101
|
-
// Check limits of time address ... if necessary, recalculate modulo
|
102
|
-
// TABLE_SIZE.
|
103
|
-
while ( time_ < 0.0 )
|
104
|
-
time_ += TABLE_SIZE;
|
105
|
-
while ( time_ >= TABLE_SIZE )
|
106
|
-
time_ -= TABLE_SIZE;
|
107
|
-
|
108
|
-
iIndex_ = (unsigned int) time_;
|
109
|
-
alpha_ = time_ - iIndex_;
|
110
|
-
StkFloat tmp = table_[ iIndex_ ];
|
111
|
-
tmp += ( alpha_ * ( table_[ iIndex_ + 1 ] - tmp ) );
|
112
|
-
|
113
|
-
// Increment time, which can be negative.
|
114
|
-
time_ += rate_;
|
115
|
-
|
116
|
-
lastFrame_[0] = tmp;
|
117
|
-
return lastFrame_[0];
|
118
|
-
}
|
119
|
-
|
120
|
-
inline StkFrames& SineWave :: tick( StkFrames& frames, unsigned int channel )
|
121
|
-
{
|
122
|
-
#if defined(_STK_DEBUG_)
|
123
|
-
if ( channel >= frames.channels() ) {
|
124
|
-
oStream_ << "SineWave::tick(): channel and StkFrames arguments are incompatible!";
|
125
|
-
handleError( StkError::FUNCTION_ARGUMENT );
|
126
|
-
}
|
127
|
-
#endif
|
128
|
-
|
129
|
-
StkFloat *samples = &frames[channel];
|
130
|
-
StkFloat tmp = 0.0;
|
131
|
-
|
132
|
-
unsigned int hop = frames.channels();
|
133
|
-
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
|
134
|
-
|
135
|
-
// Check limits of time address ... if necessary, recalculate modulo
|
136
|
-
// TABLE_SIZE.
|
137
|
-
while ( time_ < 0.0 )
|
138
|
-
time_ += TABLE_SIZE;
|
139
|
-
while ( time_ >= TABLE_SIZE )
|
140
|
-
time_ -= TABLE_SIZE;
|
141
|
-
|
142
|
-
iIndex_ = (unsigned int) time_;
|
143
|
-
alpha_ = time_ - iIndex_;
|
144
|
-
tmp = table_[ iIndex_ ];
|
145
|
-
tmp += ( alpha_ * ( table_[ iIndex_ + 1 ] - tmp ) );
|
146
|
-
*samples = tmp;
|
147
|
-
|
148
|
-
// Increment time, which can be negative.
|
149
|
-
time_ += rate_;
|
150
|
-
}
|
151
|
-
|
152
|
-
lastFrame_[0] = tmp;
|
153
|
-
return frames;
|
154
|
-
}
|
155
|
-
|
156
|
-
} // stk namespace
|
157
|
-
|
158
|
-
#endif
|
159
|
-
|