FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
RSAlgorithmicVerb/Source/LFO.cpp at main · reillypascal/RSAlgorithmicVerb · GitHub
reillypascal
/
RSAlgorithmicVerb
Public
Notifications
You must be signed in to change notification settings
Fork
7
Star
75
Code
Issues
4
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
RSAlgorithmicVerb
/
Source
/
LFO.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
129 lines (98 loc) · 3.04 KB
Breadcrumbs
RSAlgorithmicVerb
/
Source
/
LFO.cpp
Copy path
File metadata and controls
129 lines (98 loc) · 3.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
Sine/tri/saw LFO with quadrature output
#
include
"
LFO.h
"
LFO
::
LFO
()
{
srand
(
static_cast
<
uint32_t
>(
time
(
NULL
)));
}
LFO
::
~LFO
() =
default
;
bool
LFO::reset
(
double
_sampleRate)
{
sampleRate = _sampleRate;
phaseInc = lfoParameters.
frequency_Hz
/ sampleRate;
modCounter =
0.0
;
modCounterQP =
0.25
;
return
true
;
}
OscillatorParameters
LFO::getParameters
()
{
return
lfoParameters;
}
void
LFO::setParameters
(
const
OscillatorParameters& params)
{
if
(params.
frequency_Hz
!= lfoParameters.
frequency_Hz
)
phaseInc = params.
frequency_Hz
/ sampleRate;
lfoParameters = params;
}
const
SignalGenData
LFO::renderAudioOutput
()
{
checkAndWrapModulo
(modCounter, phaseInc);
modCounterQP = modCounter;
advanceAndCheckWrapModulo
(modCounterQP,
0.25
);
SignalGenData output;
if
(lfoParameters.
waveform
== generatorWaveform::sin)
{
double
angle = modCounter *
2.0
*
M_PI
-
M_PI
;
//
output.normalOutput = parabolicSine(-angle);
output.
normalOutput
=
std::sin
(-angle);
angle = modCounterQP *
2.0
*
M_PI
-
M_PI
;
//
output.quadPhaseOutput_pos = parabolicSine(-angle);
output.
quadPhaseOutput_pos
=
std::sin
(-angle);
}
else
if
(lfoParameters.
waveform
== generatorWaveform::triangle)
{
//
bipolar saw
output.
normalOutput
=
unipolarToBipolar
(modCounter);
//
bipolar triangle from saw
output.
normalOutput
=
2.0
*
fabs
(output.
normalOutput
) -
1.0
;
output.
quadPhaseOutput_pos
=
unipolarToBipolar
(modCounterQP);
output.
quadPhaseOutput_pos
=
2.0
*
fabs
(output.
quadPhaseOutput_pos
) -
1.0
;
}
else
if
(lfoParameters.
waveform
== generatorWaveform::saw)
{
output.
normalOutput
=
unipolarToBipolar
(modCounter);
output.
quadPhaseOutput_pos
=
unipolarToBipolar
(modCounterQP);
}
output.
quadPhaseOutput_neg
= -output.
quadPhaseOutput_pos
;
output.
invertedOutput
= -output.
normalOutput
;
advanceModulo
(modCounter, phaseInc);
return
output;
}
inline
bool
LFO::checkAndWrapModulo
(
double
& moduloCounter,
double
phaseInc)
{
if
(phaseInc >
0
&& moduloCounter >=
1.0
)
{
moduloCounter -=
1.0
;
return
true
;
}
if
(phaseInc <
0
&& moduloCounter <=
0.0
)
{
moduloCounter +=
1.0
;
return
true
;
}
return
false
;
}
inline
bool
LFO::advanceAndCheckWrapModulo
(
double
& moduloCounter,
double
phaseInc)
{
moduloCounter += phaseInc;
if
(phaseInc >
0
&& moduloCounter >=
1.0
)
{
moduloCounter -=
1.0
;
return
true
;
}
if
(phaseInc <
0
&& moduloCounter >=
1.0
)
{
moduloCounter +=
1.0
;
return
true
;
}
return
false
;
}
inline
void
LFO::advanceModulo
(
double
& moduloCounter,
double
phaseInc)
{
moduloCounter += phaseInc;
}
inline
double
LFO::parabolicSine
(
double
angle)
{
double
y = B * angle + C * angle *
fabs
(angle);
y = P * (y *
fabs
(y) - y) + y;
return
y;
}
Back
|
FazBrowse Home
|
New Git URL