lmms
Cross-platform music production software
Toggle main menu visibility
Loading...
Searching...
No Matches
include
QuadratureLfo.h
Go to the documentation of this file.
1
/*
2
* quadraturelfo.h - definition of QuadratureLfo class.
3
*
4
* Copyright (c) 2014 David French <dave/dot/french3/at/googlemail/dot/com>
5
*
6
* This file is part of LMMS - https://lmms.io
7
*
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public
19
* License along with this program (see COPYING); if not, write to the
20
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
* Boston, MA 02110-1301 USA.
22
*
23
*/
24
25
#ifndef LMMS_QUADRATURE_LFO_H
26
#define LMMS_QUADRATURE_LFO_H
27
28
#include <numbers>
29
#include <cmath>
30
31
namespace
lmms
32
{
33
34
35
class
QuadratureLfo
36
{
37
public
:
38
QuadratureLfo
(
int
sampleRate ) :
39
m_frequency
(0),
40
m_phase
(0),
41
m_offset
(std::numbers::pi * 0.5)
42
{
43
setSampleRate
(sampleRate);
44
}
45
46
~QuadratureLfo
() =
default
;
47
48
inline
void
setFrequency
(
double
frequency )
49
{
50
if
( frequency < 0 || frequency >
m_samplerate
/ 2.0 || frequency ==
m_frequency
)
51
{
52
return
;
53
}
54
m_frequency
= frequency;
55
m_increment
=
m_frequency
*
m_twoPiOverSr
;
56
}
57
58
59
inline
void
restart
()
60
{
61
m_phase
= 0;
62
}
63
64
65
inline
void
setSampleRate
(
int
samplerate )
66
{
67
m_samplerate
= samplerate;
68
m_twoPiOverSr
= 2 * std::numbers::pi_v<float> / samplerate;
69
m_increment
=
m_frequency
*
m_twoPiOverSr
;
70
}
71
72
73
inline
void
setOffset
(
double
offsetVal )
74
{
75
m_offset
= offsetVal;
76
}
77
78
79
void
tick
(
float
*l,
float
*r )
80
{
81
*l = std::sin(
m_phase
);
82
*r = std::sin(
m_phase
+
m_offset
);
83
m_phase
+=
m_increment
;
84
m_phase
= std::fmod(
m_phase
, 2 * std::numbers::pi);
85
}
86
87
private
:
88
double
m_frequency
;
89
double
m_phase
;
90
double
m_increment
;
91
double
m_twoPiOverSr
;
92
double
m_offset
;
93
int
m_samplerate
;
94
95
};
96
97
98
}
// namespace lmms
99
100
#endif
// LMMS_QUADRATURE_LFO_H
lmms::QuadratureLfo::m_increment
double m_increment
Definition
QuadratureLfo.h:90
lmms::QuadratureLfo::m_twoPiOverSr
double m_twoPiOverSr
Definition
QuadratureLfo.h:91
lmms::QuadratureLfo::~QuadratureLfo
~QuadratureLfo()=default
lmms::QuadratureLfo::setFrequency
void setFrequency(double frequency)
Definition
QuadratureLfo.h:48
lmms::QuadratureLfo::m_frequency
double m_frequency
Definition
QuadratureLfo.h:88
lmms::QuadratureLfo::m_offset
double m_offset
Definition
QuadratureLfo.h:92
lmms::QuadratureLfo::tick
void tick(float *l, float *r)
Definition
QuadratureLfo.h:79
lmms::QuadratureLfo::m_samplerate
int m_samplerate
Definition
QuadratureLfo.h:93
lmms::QuadratureLfo::setSampleRate
void setSampleRate(int samplerate)
Definition
QuadratureLfo.h:65
lmms::QuadratureLfo::QuadratureLfo
QuadratureLfo(int sampleRate)
Definition
QuadratureLfo.h:38
lmms::QuadratureLfo::setOffset
void setOffset(double offsetVal)
Definition
QuadratureLfo.h:73
lmms::QuadratureLfo::restart
void restart()
Definition
QuadratureLfo.h:59
lmms::QuadratureLfo::m_phase
double m_phase
Definition
QuadratureLfo.h:89
lmms
Definition
RemotePluginBase.cpp:34
Generated on
for lmms by
1.18.0