LMMS
Loading...
Searching...
No Matches
Lfo.h
Go to the documentation of this file.
1/*
2 * lfo.h - declaration of Lfo class, a simple sine lfo
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 LFO_H
26#define LFO_H
27
28#include <cmath>
29#include <numbers>
30
31namespace lmms
32{
33
34
35class Lfo
36{
37public:
38 Lfo( int samplerate );
39 ~Lfo() = default;
40
41
42
43
44 inline void setFrequency( double frequency )
45 {
46 if( frequency < 0 || frequency > ( m_samplerate / 2.0 ) || frequency == m_frequency )
47 {
48 return;
49 }
50 m_frequency = frequency;
52
53 m_phase = std::fmod(m_phase, 2 * std::numbers::pi_v<float>);
54 }
55
56
57
58
59 inline void setSampleRate ( int samplerate )
60 {
61 m_samplerate = samplerate;
62 m_twoPiOverSr = 2 * std::numbers::pi_v<float> / samplerate;
64 }
65
66
67
68
69 float tick();
70
71private:
73 double m_phase;
77};
78
79
80} // namespace lmms
81
82#endif // LFO_H
Lfo(int samplerate)
Definition Lfo.cpp:34
~Lfo()=default
double m_frequency
Definition Lfo.h:72
int m_samplerate
Definition Lfo.h:76
double m_twoPiOverSr
Definition Lfo.h:75
double m_phase
Definition Lfo.h:73
void setSampleRate(int samplerate)
Definition Lfo.h:59
void setFrequency(double frequency)
Definition Lfo.h:44
double m_increment
Definition Lfo.h:74
float tick()
Definition Lfo.cpp:43
Definition AudioAlsa.cpp:35