beeps 0.1.12 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/beeps/beeps.cpp +2 -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 +2 -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/exception.h +6 -2
- data/include/beeps/processor.h +9 -6
- data/include/beeps/ruby/beeps.h +1 -0
- 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 +30 -73
- 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/include/beeps/openal.h
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
// -*- c++ -*-
|
2
|
-
#pragma once
|
3
|
-
#ifndef __BEEPS_OPENAL_H__
|
4
|
-
#define __BEEPS_OPENAL_H__
|
5
|
-
|
6
|
-
|
7
|
-
#if defined(OSX) || defined(IOS)
|
8
|
-
#include <OpenAL/al.h>
|
9
|
-
#include <OpenAL/alc.h>
|
10
|
-
#else
|
11
|
-
#include <AL/al.h>
|
12
|
-
#include <AL/alc.h>
|
13
|
-
#endif
|
14
|
-
|
15
|
-
|
16
|
-
namespace Beeps
|
17
|
-
{
|
18
|
-
|
19
|
-
|
20
|
-
ALCenum get_error ();
|
21
|
-
|
22
|
-
bool no_error ();
|
23
|
-
|
24
|
-
bool is_error (ALCenum err);
|
25
|
-
|
26
|
-
void check_error(const char* file, int line);
|
27
|
-
|
28
|
-
void clear_error ();
|
29
|
-
|
30
|
-
|
31
|
-
}// Beeps
|
32
|
-
|
33
|
-
|
34
|
-
#endif//EOH
|
data/src/stk/include/Blit.h
DELETED
@@ -1,151 +0,0 @@
|
|
1
|
-
#ifndef STK_BLIT_H
|
2
|
-
#define STK_BLIT_H
|
3
|
-
|
4
|
-
#include "Generator.h"
|
5
|
-
#include <cmath>
|
6
|
-
#include <limits>
|
7
|
-
|
8
|
-
namespace stk {
|
9
|
-
|
10
|
-
/***************************************************/
|
11
|
-
/*! \class Blit
|
12
|
-
\brief STK band-limited impulse train class.
|
13
|
-
|
14
|
-
This class generates a band-limited impulse train using a
|
15
|
-
closed-form algorithm reported by Stilson and Smith in "Alias-Free
|
16
|
-
Digital Synthesis of Classic Analog Waveforms", 1996. The user
|
17
|
-
can specify both the fundamental frequency of the impulse train
|
18
|
-
and the number of harmonics contained in the resulting signal.
|
19
|
-
|
20
|
-
The signal is normalized so that the peak value is +/-1.0.
|
21
|
-
|
22
|
-
If nHarmonics is 0, then the signal will contain all harmonics up
|
23
|
-
to half the sample rate. Note, however, that this setting may
|
24
|
-
produce aliasing in the signal when the frequency is changing (no
|
25
|
-
automatic modification of the number of harmonics is performed by
|
26
|
-
the setFrequency() function).
|
27
|
-
|
28
|
-
Original code by Robin Davies, 2005.
|
29
|
-
Revisions by Gary Scavone for STK, 2005.
|
30
|
-
*/
|
31
|
-
/***************************************************/
|
32
|
-
|
33
|
-
class Blit: public Generator
|
34
|
-
{
|
35
|
-
public:
|
36
|
-
//! Default constructor that initializes BLIT frequency to 220 Hz.
|
37
|
-
Blit( StkFloat frequency = 220.0 );
|
38
|
-
|
39
|
-
//! Class destructor.
|
40
|
-
~Blit();
|
41
|
-
|
42
|
-
//! Resets the oscillator state and phase to 0.
|
43
|
-
void reset();
|
44
|
-
|
45
|
-
//! Set the phase of the signal.
|
46
|
-
/*!
|
47
|
-
Set the phase of the signal, in the range 0 to 1.
|
48
|
-
*/
|
49
|
-
void setPhase( StkFloat phase ) { phase_ = PI * phase; };
|
50
|
-
|
51
|
-
//! Get the current phase of the signal.
|
52
|
-
/*!
|
53
|
-
Get the phase of the signal, in the range [0 to 1.0).
|
54
|
-
*/
|
55
|
-
StkFloat getPhase() const { return phase_ / PI; };
|
56
|
-
|
57
|
-
//! Set the impulse train rate in terms of a frequency in Hz.
|
58
|
-
void setFrequency( StkFloat frequency );
|
59
|
-
|
60
|
-
//! Set the number of harmonics generated in the signal.
|
61
|
-
/*!
|
62
|
-
This function sets the number of harmonics contained in the
|
63
|
-
resulting signal. It is equivalent to (2 * M) + 1 in the BLIT
|
64
|
-
algorithm. The default value of 0 sets the algorithm for maximum
|
65
|
-
harmonic content (harmonics up to half the sample rate). This
|
66
|
-
parameter is not checked against the current sample rate and
|
67
|
-
fundamental frequency. Thus, aliasing can result if one or more
|
68
|
-
harmonics for a given fundamental frequency exceeds fs / 2. This
|
69
|
-
behavior was chosen over the potentially more problematic solution
|
70
|
-
of automatically modifying the M parameter, which can produce
|
71
|
-
audible clicks in the signal.
|
72
|
-
*/
|
73
|
-
void setHarmonics( unsigned int nHarmonics = 0 );
|
74
|
-
|
75
|
-
//! Return the last computed output value.
|
76
|
-
StkFloat lastOut( void ) const { return lastFrame_[0]; };
|
77
|
-
|
78
|
-
//! Compute and return one output sample.
|
79
|
-
StkFloat tick( void );
|
80
|
-
|
81
|
-
//! Fill a channel of the StkFrames object with computed outputs.
|
82
|
-
/*!
|
83
|
-
The \c channel argument must be less than the number of
|
84
|
-
channels in the StkFrames argument (the first channel is specified
|
85
|
-
by 0). However, range checking is only performed if _STK_DEBUG_
|
86
|
-
is defined during compilation, in which case an out-of-range value
|
87
|
-
will trigger an StkError exception.
|
88
|
-
*/
|
89
|
-
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
|
90
|
-
|
91
|
-
protected:
|
92
|
-
|
93
|
-
void updateHarmonics( void );
|
94
|
-
|
95
|
-
unsigned int nHarmonics_;
|
96
|
-
unsigned int m_;
|
97
|
-
StkFloat rate_;
|
98
|
-
StkFloat phase_;
|
99
|
-
StkFloat p_;
|
100
|
-
|
101
|
-
};
|
102
|
-
|
103
|
-
inline StkFloat Blit :: tick( void )
|
104
|
-
{
|
105
|
-
// The code below implements the SincM algorithm of Stilson and
|
106
|
-
// Smith with an additional scale factor of P / M applied to
|
107
|
-
// normalize the output.
|
108
|
-
|
109
|
-
// A fully optimized version of this code would replace the two sin
|
110
|
-
// calls with a pair of fast sin oscillators, for which stable fast
|
111
|
-
// two-multiply algorithms are well known. In the spirit of STK,
|
112
|
-
// which favors clarity over performance, the optimization has not
|
113
|
-
// been made here.
|
114
|
-
|
115
|
-
// Avoid a divide by zero at the sinc peak, which has a limiting
|
116
|
-
// value of 1.0.
|
117
|
-
StkFloat tmp, denominator = sin( phase_ );
|
118
|
-
if ( denominator <= std::numeric_limits<StkFloat>::epsilon() )
|
119
|
-
tmp = 1.0;
|
120
|
-
else {
|
121
|
-
tmp = sin( m_ * phase_ );
|
122
|
-
tmp /= m_ * denominator;
|
123
|
-
}
|
124
|
-
|
125
|
-
phase_ += rate_;
|
126
|
-
if ( phase_ >= PI ) phase_ -= PI;
|
127
|
-
|
128
|
-
lastFrame_[0] = tmp;
|
129
|
-
return lastFrame_[0];
|
130
|
-
}
|
131
|
-
|
132
|
-
inline StkFrames& Blit :: tick( StkFrames& frames, unsigned int channel )
|
133
|
-
{
|
134
|
-
#if defined(_STK_DEBUG_)
|
135
|
-
if ( channel >= frames.channels() ) {
|
136
|
-
oStream_ << "Blit::tick(): channel and StkFrames arguments are incompatible!";
|
137
|
-
handleError( StkError::FUNCTION_ARGUMENT );
|
138
|
-
}
|
139
|
-
#endif
|
140
|
-
|
141
|
-
StkFloat *samples = &frames[channel];
|
142
|
-
unsigned int hop = frames.channels();
|
143
|
-
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
|
144
|
-
*samples = Blit::tick();
|
145
|
-
|
146
|
-
return frames;
|
147
|
-
}
|
148
|
-
|
149
|
-
} // stk namespace
|
150
|
-
|
151
|
-
#endif
|
data/src/stk/include/BlitSaw.h
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
#ifndef STK_BLITSAW_H
|
2
|
-
#define STK_BLITSAW_H
|
3
|
-
|
4
|
-
#include "Generator.h"
|
5
|
-
#include <cmath>
|
6
|
-
#include <limits>
|
7
|
-
|
8
|
-
namespace stk {
|
9
|
-
|
10
|
-
/***************************************************/
|
11
|
-
/*! \class BlitSaw
|
12
|
-
\brief STK band-limited sawtooth wave class.
|
13
|
-
|
14
|
-
This class generates a band-limited sawtooth waveform using a
|
15
|
-
closed-form algorithm reported by Stilson and Smith in "Alias-Free
|
16
|
-
Digital Synthesis of Classic Analog Waveforms", 1996. The user
|
17
|
-
can specify both the fundamental frequency of the sawtooth and the
|
18
|
-
number of harmonics contained in the resulting signal.
|
19
|
-
|
20
|
-
If nHarmonics is 0, then the signal will contain all harmonics up
|
21
|
-
to half the sample rate. Note, however, that this setting may
|
22
|
-
produce aliasing in the signal when the frequency is changing (no
|
23
|
-
automatic modification of the number of harmonics is performed by
|
24
|
-
the setFrequency() function).
|
25
|
-
|
26
|
-
Based on initial code of Robin Davies, 2005.
|
27
|
-
Modified algorithm code by Gary Scavone, 2005.
|
28
|
-
*/
|
29
|
-
/***************************************************/
|
30
|
-
|
31
|
-
class BlitSaw: public Generator
|
32
|
-
{
|
33
|
-
public:
|
34
|
-
//! Class constructor.
|
35
|
-
BlitSaw( StkFloat frequency = 220.0 );
|
36
|
-
|
37
|
-
//! Class destructor.
|
38
|
-
~BlitSaw();
|
39
|
-
|
40
|
-
//! Resets the oscillator state and phase to 0.
|
41
|
-
void reset();
|
42
|
-
|
43
|
-
//! Set the sawtooth oscillator rate in terms of a frequency in Hz.
|
44
|
-
void setFrequency( StkFloat frequency );
|
45
|
-
|
46
|
-
//! Set the number of harmonics generated in the signal.
|
47
|
-
/*!
|
48
|
-
This function sets the number of harmonics contained in the
|
49
|
-
resulting signal. It is equivalent to (2 * M) + 1 in the BLIT
|
50
|
-
algorithm. The default value of 0 sets the algorithm for maximum
|
51
|
-
harmonic content (harmonics up to half the sample rate). This
|
52
|
-
parameter is not checked against the current sample rate and
|
53
|
-
fundamental frequency. Thus, aliasing can result if one or more
|
54
|
-
harmonics for a given fundamental frequency exceeds fs / 2. This
|
55
|
-
behavior was chosen over the potentially more problematic solution
|
56
|
-
of automatically modifying the M parameter, which can produce
|
57
|
-
audible clicks in the signal.
|
58
|
-
*/
|
59
|
-
void setHarmonics( unsigned int nHarmonics = 0 );
|
60
|
-
|
61
|
-
//! Return the last computed output value.
|
62
|
-
StkFloat lastOut( void ) const { return lastFrame_[0]; };
|
63
|
-
|
64
|
-
//! Compute and return one output sample.
|
65
|
-
StkFloat tick( void );
|
66
|
-
|
67
|
-
//! Fill a channel of the StkFrames object with computed outputs.
|
68
|
-
/*!
|
69
|
-
The \c channel argument must be less than the number of
|
70
|
-
channels in the StkFrames argument (the first channel is specified
|
71
|
-
by 0). However, range checking is only performed if _STK_DEBUG_
|
72
|
-
is defined during compilation, in which case an out-of-range value
|
73
|
-
will trigger an StkError exception.
|
74
|
-
*/
|
75
|
-
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
|
76
|
-
|
77
|
-
protected:
|
78
|
-
|
79
|
-
void updateHarmonics( void );
|
80
|
-
|
81
|
-
unsigned int nHarmonics_;
|
82
|
-
unsigned int m_;
|
83
|
-
StkFloat rate_;
|
84
|
-
StkFloat phase_;
|
85
|
-
StkFloat p_;
|
86
|
-
StkFloat C2_;
|
87
|
-
StkFloat a_;
|
88
|
-
StkFloat state_;
|
89
|
-
|
90
|
-
};
|
91
|
-
|
92
|
-
inline StkFloat BlitSaw :: tick( void )
|
93
|
-
{
|
94
|
-
// The code below implements the BLIT algorithm of Stilson and
|
95
|
-
// Smith, followed by a summation and filtering operation to produce
|
96
|
-
// a sawtooth waveform. After experimenting with various approaches
|
97
|
-
// to calculate the average value of the BLIT over one period, I
|
98
|
-
// found that an estimate of C2_ = 1.0 / period (in samples) worked
|
99
|
-
// most consistently. A "leaky integrator" is then applied to the
|
100
|
-
// difference of the BLIT output and C2_. (GPS - 1 October 2005)
|
101
|
-
|
102
|
-
// A fully optimized version of this code would replace the two sin
|
103
|
-
// calls with a pair of fast sin oscillators, for which stable fast
|
104
|
-
// two-multiply algorithms are well known. In the spirit of STK,
|
105
|
-
// which favors clarity over performance, the optimization has
|
106
|
-
// not been made here.
|
107
|
-
|
108
|
-
// Avoid a divide by zero, or use of a denormalized divisor
|
109
|
-
// at the sinc peak, which has a limiting value of m_ / p_.
|
110
|
-
StkFloat tmp, denominator = sin( phase_ );
|
111
|
-
if ( fabs(denominator) <= std::numeric_limits<StkFloat>::epsilon() )
|
112
|
-
tmp = a_;
|
113
|
-
else {
|
114
|
-
tmp = sin( m_ * phase_ );
|
115
|
-
tmp /= p_ * denominator;
|
116
|
-
}
|
117
|
-
|
118
|
-
tmp += state_ - C2_;
|
119
|
-
state_ = tmp * 0.995;
|
120
|
-
|
121
|
-
phase_ += rate_;
|
122
|
-
if ( phase_ >= PI ) phase_ -= PI;
|
123
|
-
|
124
|
-
lastFrame_[0] = tmp;
|
125
|
-
return lastFrame_[0];
|
126
|
-
}
|
127
|
-
|
128
|
-
inline StkFrames& BlitSaw :: tick( StkFrames& frames, unsigned int channel )
|
129
|
-
{
|
130
|
-
#if defined(_STK_DEBUG_)
|
131
|
-
if ( channel >= frames.channels() ) {
|
132
|
-
oStream_ << "BlitSaw::tick(): channel and StkFrames arguments are incompatible!";
|
133
|
-
handleError( StkError::FUNCTION_ARGUMENT );
|
134
|
-
}
|
135
|
-
#endif
|
136
|
-
|
137
|
-
|
138
|
-
StkFloat *samples = &frames[channel];
|
139
|
-
unsigned int hop = frames.channels();
|
140
|
-
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
|
141
|
-
*samples = BlitSaw::tick();
|
142
|
-
|
143
|
-
return frames;
|
144
|
-
}
|
145
|
-
|
146
|
-
} // stk namespace
|
147
|
-
|
148
|
-
#endif
|
@@ -1,170 +0,0 @@
|
|
1
|
-
#ifndef STK_BLITSQUARE_H
|
2
|
-
#define STK_BLITSQUARE_H
|
3
|
-
|
4
|
-
#include "Generator.h"
|
5
|
-
#include <cmath>
|
6
|
-
#include <limits>
|
7
|
-
|
8
|
-
namespace stk {
|
9
|
-
|
10
|
-
/***************************************************/
|
11
|
-
/*! \class BlitSquare
|
12
|
-
\brief STK band-limited square wave class.
|
13
|
-
|
14
|
-
This class generates a band-limited square wave signal. It is
|
15
|
-
derived in part from the approach reported by Stilson and Smith in
|
16
|
-
"Alias-Free Digital Synthesis of Classic Analog Waveforms", 1996.
|
17
|
-
The algorithm implemented in this class uses a SincM function with
|
18
|
-
an even M value to achieve a bipolar bandlimited impulse train.
|
19
|
-
This signal is then integrated to achieve a square waveform. The
|
20
|
-
integration process has an associated DC offset so a DC blocking
|
21
|
-
filter is applied at the output.
|
22
|
-
|
23
|
-
The user can specify both the fundamental frequency of the
|
24
|
-
waveform and the number of harmonics contained in the resulting
|
25
|
-
signal.
|
26
|
-
|
27
|
-
If nHarmonics is 0, then the signal will contain all harmonics up
|
28
|
-
to half the sample rate. Note, however, that this setting may
|
29
|
-
produce aliasing in the signal when the frequency is changing (no
|
30
|
-
automatic modification of the number of harmonics is performed by
|
31
|
-
the setFrequency() function). Also note that the harmonics of a
|
32
|
-
square wave fall at odd integer multiples of the fundamental, so
|
33
|
-
aliasing will happen with a lower fundamental than with the other
|
34
|
-
Blit waveforms. This class is not guaranteed to be well behaved
|
35
|
-
in the presence of significant aliasing.
|
36
|
-
|
37
|
-
Based on initial code of Robin Davies, 2005.
|
38
|
-
Modified algorithm code by Gary Scavone, 2005 - 2006.
|
39
|
-
*/
|
40
|
-
/***************************************************/
|
41
|
-
|
42
|
-
class BlitSquare: public Generator
|
43
|
-
{
|
44
|
-
public:
|
45
|
-
//! Default constructor that initializes BLIT frequency to 220 Hz.
|
46
|
-
BlitSquare( StkFloat frequency = 220.0 );
|
47
|
-
|
48
|
-
//! Class destructor.
|
49
|
-
~BlitSquare();
|
50
|
-
|
51
|
-
//! Resets the oscillator state and phase to 0.
|
52
|
-
void reset();
|
53
|
-
|
54
|
-
//! Set the phase of the signal.
|
55
|
-
/*!
|
56
|
-
Set the phase of the signal, in the range 0 to 1.
|
57
|
-
*/
|
58
|
-
void setPhase( StkFloat phase ) { phase_ = PI * phase; };
|
59
|
-
|
60
|
-
//! Get the current phase of the signal.
|
61
|
-
/*!
|
62
|
-
Get the phase of the signal, in the range [0 to 1.0).
|
63
|
-
*/
|
64
|
-
StkFloat getPhase() const { return phase_ / PI; };
|
65
|
-
|
66
|
-
//! Set the impulse train rate in terms of a frequency in Hz.
|
67
|
-
void setFrequency( StkFloat frequency );
|
68
|
-
|
69
|
-
//! Set the number of harmonics generated in the signal.
|
70
|
-
/*!
|
71
|
-
This function sets the number of harmonics contained in the
|
72
|
-
resulting signal. It is equivalent to (2 * M) + 1 in the BLIT
|
73
|
-
algorithm. The default value of 0 sets the algorithm for maximum
|
74
|
-
harmonic content (harmonics up to half the sample rate). This
|
75
|
-
parameter is not checked against the current sample rate and
|
76
|
-
fundamental frequency. Thus, aliasing can result if one or more
|
77
|
-
harmonics for a given fundamental frequency exceeds fs / 2. This
|
78
|
-
behavior was chosen over the potentially more problematic solution
|
79
|
-
of automatically modifying the M parameter, which can produce
|
80
|
-
audible clicks in the signal.
|
81
|
-
*/
|
82
|
-
void setHarmonics( unsigned int nHarmonics = 0 );
|
83
|
-
|
84
|
-
//! Return the last computed output value.
|
85
|
-
StkFloat lastOut( void ) const { return lastFrame_[0]; };
|
86
|
-
|
87
|
-
//! Compute and return one output sample.
|
88
|
-
StkFloat tick( void );
|
89
|
-
|
90
|
-
//! Fill a channel of the StkFrames object with computed outputs.
|
91
|
-
/*!
|
92
|
-
The \c channel argument must be less than the number of
|
93
|
-
channels in the StkFrames argument (the first channel is specified
|
94
|
-
by 0). However, range checking is only performed if _STK_DEBUG_
|
95
|
-
is defined during compilation, in which case an out-of-range value
|
96
|
-
will trigger an StkError exception.
|
97
|
-
*/
|
98
|
-
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 );
|
99
|
-
|
100
|
-
protected:
|
101
|
-
|
102
|
-
void updateHarmonics( void );
|
103
|
-
|
104
|
-
unsigned int nHarmonics_;
|
105
|
-
unsigned int m_;
|
106
|
-
StkFloat rate_;
|
107
|
-
StkFloat phase_;
|
108
|
-
StkFloat p_;
|
109
|
-
StkFloat a_;
|
110
|
-
StkFloat lastBlitOutput_;
|
111
|
-
StkFloat dcbState_;
|
112
|
-
};
|
113
|
-
|
114
|
-
inline StkFloat BlitSquare :: tick( void )
|
115
|
-
{
|
116
|
-
StkFloat temp = lastBlitOutput_;
|
117
|
-
|
118
|
-
// A fully optimized version of this would replace the two sin calls
|
119
|
-
// with a pair of fast sin oscillators, for which stable fast
|
120
|
-
// two-multiply algorithms are well known. In the spirit of STK,
|
121
|
-
// which favors clarity over performance, the optimization has
|
122
|
-
// not been made here.
|
123
|
-
|
124
|
-
// Avoid a divide by zero, or use of a denomralized divisor
|
125
|
-
// at the sinc peak, which has a limiting value of 1.0.
|
126
|
-
StkFloat denominator = sin( phase_ );
|
127
|
-
if ( fabs( denominator ) < std::numeric_limits<StkFloat>::epsilon() ) {
|
128
|
-
// Inexact comparison safely distinguishes betwen *close to zero*, and *close to PI*.
|
129
|
-
if ( phase_ < 0.1f || phase_ > TWO_PI - 0.1f )
|
130
|
-
lastBlitOutput_ = a_;
|
131
|
-
else
|
132
|
-
lastBlitOutput_ = -a_;
|
133
|
-
}
|
134
|
-
else {
|
135
|
-
lastBlitOutput_ = sin( m_ * phase_ );
|
136
|
-
lastBlitOutput_ /= p_ * denominator;
|
137
|
-
}
|
138
|
-
|
139
|
-
lastBlitOutput_ += temp;
|
140
|
-
|
141
|
-
// Now apply DC blocker.
|
142
|
-
lastFrame_[0] = lastBlitOutput_ - dcbState_ + 0.999 * lastFrame_[0];
|
143
|
-
dcbState_ = lastBlitOutput_;
|
144
|
-
|
145
|
-
phase_ += rate_;
|
146
|
-
if ( phase_ >= TWO_PI ) phase_ -= TWO_PI;
|
147
|
-
|
148
|
-
return lastFrame_[0];
|
149
|
-
}
|
150
|
-
|
151
|
-
inline StkFrames& BlitSquare :: tick( StkFrames& frames, unsigned int channel )
|
152
|
-
{
|
153
|
-
#if defined(_STK_DEBUG_)
|
154
|
-
if ( channel >= frames.channels() ) {
|
155
|
-
oStream_ << "BlitSquare::tick(): channel and StkFrames arguments are incompatible!";
|
156
|
-
handleError( StkError::FUNCTION_ARGUMENT );
|
157
|
-
}
|
158
|
-
#endif
|
159
|
-
|
160
|
-
StkFloat *samples = &frames[channel];
|
161
|
-
unsigned int hop = frames.channels();
|
162
|
-
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
|
163
|
-
*samples = BlitSquare::tick();
|
164
|
-
|
165
|
-
return frames;
|
166
|
-
}
|
167
|
-
|
168
|
-
} // stk namespace
|
169
|
-
|
170
|
-
#endif
|