CLAM-Development
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
Processing
Generators
SimpleOscillator.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3
* UNIVERSITAT POMPEU FABRA
4
*
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
*
20
*/
21
22
#include "
SimpleOscillator.hxx
"
23
#include "
ProcessingFactory.hxx
"
24
25
namespace
CLAM
26
{
27
28
namespace
Hidden
29
{
30
static
const
char
*
metadata
[] = {
31
"key"
,
"SimpleOscillator"
,
32
"category"
,
"Generators"
,
33
"description"
,
"SimpleOscillator"
,
34
0
35
};
36
static
FactoryRegistrator<ProcessingFactory, SimpleOscillator>
reg
=
metadata
;
37
}
38
39
40
// OscillatorConfig method definition
41
void
SimpleOscillatorConfig::DefaultInit
(
void
)
42
{
43
AddFrequency();
44
AddAmplitude();
45
AddPhase();
46
AddSamplingRate();
47
48
UpdateData
();
49
50
SetFrequency(440.0);
51
SetAmplitude(1.0);
52
SetPhase(0.0);
53
SetSamplingRate( 44100 );
54
}
55
56
SimpleOscillator::SimpleOscillator
(
const
SimpleOscillatorConfig
& cfg )
57
: mOutput(
"Audio Output"
, this)
58
, mFreqUpdated( false )
59
, mAmpUpdated( false )
60
, mFreqCtl(
"Pitch"
, this, &
SimpleOscillator
::UpdateFreq )
61
, mAmpCtl(
"Amplitude"
, this, &
SimpleOscillator
::UpdateAmp )
62
, mSamplesBetweenCallsCtl(
"SamplesBetweenCalls"
, this)
63
{
64
Configure
( cfg );
65
}
66
67
SimpleOscillator::~SimpleOscillator
()
68
{
69
}
70
71
bool
SimpleOscillator::ConcreteConfigure
(
const
ProcessingConfig
& c )
72
{
73
CopyAsConcreteConfig
(
mConfig
, c);
74
75
76
mAmp
=
mConfig
.GetAmplitude();
77
mPhase
=
mConfig
.GetPhase();
// TEMP HACK (See also constructor
78
mSamplingRate
=
mConfig
.GetSamplingRate();
79
mDeltaPhase
=
TData
(2.*
PI
*
mConfig
.GetFrequency()/
mSamplingRate
);
80
//xamat: kludge to convert this into an LFO, eventually separate into a different class
81
mSamplesBetweenCallsCtl
.
DoControl
(1);
82
return
true
;
83
}
84
85
bool
SimpleOscillator::Do
()
86
{
87
bool
res =
false
;
88
res =
Do
(
mOutput
.
GetAudio
());
89
mOutput
.
Produce
();
90
return
res;
91
}
92
93
bool
SimpleOscillator::Do
(
Audio
& out )
94
{
95
if
( !
AbleToExecute
() )
return
true
;
96
97
ApplyFreqAndAmpControls
();
98
99
TData
* ptr = out.GetBuffer().GetPtr();
100
for
(
int
i=0;i<out.
GetSize
();i++)
101
{
102
(*ptr++) =
mAmp
*
TData
(sin(
mPhase
));
103
mPhase
+=
mDeltaPhase
;
104
105
if
(
mPhase
>
TData
(2*
PI
))
106
mPhase
-=
TData
(2*
PI
);
107
}
108
109
return
true
;
110
}
111
112
//xamat: kludge to convert this into an LFO, eventually separate into a different class
113
bool
SimpleOscillator::Do
(
TData
& out )
114
{
115
if
( !
AbleToExecute
() )
return
true
;
116
117
ApplyFreqAndAmpControls
();
118
119
out =
mAmp
*
TData
(sin(
mPhase
));
120
mPhase
+=
mDeltaPhase
*
mSamplesBetweenCallsCtl
.
GetLastValue
();
121
122
if
(
mPhase
>
TData
(2*
PI
))
123
mPhase
-=
TData
(2*
PI
);
124
125
return
true
;
126
}
127
128
129
void
SimpleOscillator::UpdateFreq
(
TControlData
value )
130
{
131
mFreqUpdated
=
true
;
132
}
133
134
void
SimpleOscillator::UpdateAmp
(
TControlData
value )
135
{
136
mAmpUpdated
=
true
;
137
}
138
139
}
// namespace CLAM
140
Generated by
1.8.1