-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPI_AudioWavetableSynth.cpp
More file actions
106 lines (79 loc) · 2.16 KB
/
Copy pathMPI_AudioWavetableSynth.cpp
File metadata and controls
106 lines (79 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// MPI_AudioWavetableSynth.cpp
//
#include "MPI_AudioWavetableSynth.h"
#include "MPI_AudioWavetable.h"
MPI_AudioWavetableSynth::MPI_AudioWavetableSynth( MPI_Audio &audioinstance, MPI_AudioWavetable &wavetable ) :
MPI_AudioSynth( audioinstance ),
wavetable_( wavetable ),
gain_( 0.0 )
{
// FIXME application sampling rate hardcoded here! Should come from
// MPI_Audio...
reset();
setRate( wavetable_.getFileRate() / 44100.0 );
addSynthToAudioInstance();
}
MPI_AudioWavetableSynth::~MPI_AudioWavetableSynth()
{
removeSynthFromAudioInstance();
}
MPI_AudioWavetable& MPI_AudioWavetableSynth::getWavetable( void ) const
{
return wavetable_;
}
void MPI_AudioWavetableSynth::reset( void )
{
time_ = 0.0;
finished_ = false;
lastOutput_ = 0.0;
}
bool MPI_AudioWavetableSynth::isFinished( void ) const
{
return finished_;
}
void MPI_AudioWavetableSynth::setRate( float rate )
{
rate_ = rate;
// If negative rate and at beginning of sound, move pointer to end
// of sound.
// FIXME how does this work? getSize() returns the number of sample frames
// in the file.
if ( (rate_ < 0.0) && (time_ == 0.0) )
time_ = rate_ + wavetable_.getSize();
if ( fmod(rate_, 1.0) != 0.0 )
interpolate_ = true;
else
interpolate_ = false;
}
void MPI_AudioWavetableSynth::addTime( float time )
{
// Add an absolute time in samples
time_ += time;
if ( time_ < 0.0 )
time_ = 0.0;
if ( time_ >= wavetable_.getSize() ) {
time_ = wavetable_.getSize();
finished_ = true;
}
}
void MPI_AudioWavetableSynth::setInterpolate( bool doInterpolate )
{
interpolate_ = doInterpolate;
}
float MPI_AudioWavetableSynth::tick( void )
{
if ( finished_ ) return lastOutput_;
float lastOutput_ = gain_ * wavetable_.getValueAtTime( time_, interpolate_ );
// Increment time, which can be negative.
// adapted from WvIn::tickFrame()
time_ += rate_;
if ( time_ < 0.0 || time_ >= wavetable_.getSize() )
finished_ = true;
return lastOutput_;
}
void MPI_AudioWavetableSynth::setGain( float value )
{
gain_ = value;
}
// vim:sw=4:et:cindent: