LMMS
Loading...
Searching...
No Matches
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
31namespace lmms
32{
33
34
36{
37public:
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;
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;
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);
84 m_phase = std::fmod(m_phase, 2 * std::numbers::pi);
85 }
86
87private:
89 double m_phase;
92 double m_offset;
94
95};
96
97
98} // namespace lmms
99
100#endif // LMMS_QUADRATURE_LFO_H
double m_increment
Definition QuadratureLfo.h:90
double m_twoPiOverSr
Definition QuadratureLfo.h:91
~QuadratureLfo()=default
void setFrequency(double frequency)
Definition QuadratureLfo.h:48
double m_frequency
Definition QuadratureLfo.h:88
double m_offset
Definition QuadratureLfo.h:92
void tick(float *l, float *r)
Definition QuadratureLfo.h:79
int m_samplerate
Definition QuadratureLfo.h:93
void setSampleRate(int samplerate)
Definition QuadratureLfo.h:65
QuadratureLfo(int sampleRate)
Definition QuadratureLfo.h:38
void setOffset(double offsetVal)
Definition QuadratureLfo.h:73
void restart()
Definition QuadratureLfo.h:59
double m_phase
Definition QuadratureLfo.h:89
int * l
Definition inflate.c:1579
const double pi
Definition exprtk_benchmark.cpp:186
Definition AudioAlsa.cpp:35
Definition juce_Uuid.h:141
int r
Definition crypt.c:458