lmms
Cross-platform music production software
Toggle main menu visibility
Loading...
Searching...
No Matches
plugins
Kicker
KickerOsc.h
Go to the documentation of this file.
1
/*
2
* KickerOsc.h - alternative sweeping oscillator
3
*
4
* Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5
* Copyright (c) 2014 grejppi <grejppi/at/gmail.com>
6
*
7
* This file is part of LMMS - https://lmms.io
8
*
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public
11
* License as published by the Free Software Foundation; either
12
* version 2 of the License, or (at your option) any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public
20
* License along with this program (see COPYING); if not, write to the
21
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
* Boston, MA 02110-1301 USA.
23
*
24
*/
25
26
#ifndef KICKER_OSC_H
27
#define KICKER_OSC_H
28
29
#include <cmath>
30
31
#include "
DspEffectLibrary.h
"
32
#include "
Oscillator.h
"
33
34
#include "
lmms_math.h
"
35
36
namespace
lmms
37
{
38
39
40
template
<
class
FX = DspEffectLibrary::StereoBypass>
41
class
KickerOsc
42
{
43
public
:
44
KickerOsc
(
const
FX & fx,
const
float
start,
const
float
end,
const
float
noise,
const
float
offset,
45
const
float
slope,
const
float
env,
const
float
diststart,
const
float
distend,
const
float
length ) :
46
m_phase
( offset ),
47
m_startFreq
( start ),
48
m_endFreq
( end ),
49
m_noise
( noise ),
50
m_slope
( slope ),
51
m_env
( env ),
52
m_distStart
( diststart ),
53
m_distEnd
( distend ),
54
m_hasDistEnv
( diststart != distend ),
55
m_length
( length ),
56
m_FX
( fx ),
57
m_counter
( 0 ),
58
m_freq
( start )
59
{
60
}
61
62
virtual
~KickerOsc
() =
default
;
63
64
void
update
(
SampleFrame
* buf,
const
f_cnt_t
frames,
const
float
sampleRate )
65
{
66
for
(
f_cnt_t
frame = 0; frame < frames; ++frame )
67
{
68
const
double
gain = 1 -
fastPow
((
m_counter
<
m_length
) ?
m_counter
/
m_length
: 1,
m_env
);
69
const
sample_t
s = (
Oscillator::sinSample
(
m_phase
) * ( 1 -
m_noise
) ) + (
Oscillator::noiseSample
( 0 ) * gain * gain *
m_noise
);
70
buf[frame][0] = s * gain;
71
buf[frame][1] = s * gain;
72
73
// update distortion envelope if necessary
74
if
(
m_hasDistEnv
&&
m_counter
<
m_length
)
75
{
76
float
thres = std::lerp(
m_distStart
,
m_distEnd
,
m_counter
/
m_length
);
77
m_FX
.leftFX().setThreshold( thres );
78
m_FX
.rightFX().setThreshold( thres );
79
}
80
81
m_FX
.nextSample( buf[frame][0], buf[frame][1] );
82
m_phase
+=
m_freq
/ sampleRate;
83
84
const
double
change = (
m_counter
<
m_length
) ? ((
m_startFreq
-
m_endFreq
) * (1 -
fastPow
(
m_counter
/
m_length
,
m_slope
))) : 0;
85
m_freq
=
m_endFreq
+ change;
86
++
m_counter
;
87
}
88
}
89
90
91
private
:
92
float
m_phase
;
93
const
float
m_startFreq
;
94
const
float
m_endFreq
;
95
const
float
m_noise
;
96
const
float
m_slope
;
97
const
float
m_env
;
98
const
float
m_distStart
;
99
const
float
m_distEnd
;
100
const
bool
m_hasDistEnv
;
101
const
float
m_length
;
102
FX
m_FX
;
103
104
unsigned
long
m_counter
;
105
double
m_freq
;
106
107
};
108
109
110
}
// namespace lmms
111
112
#endif
DspEffectLibrary.h
Oscillator.h
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_phase
float m_phase
Definition
KickerOsc.h:92
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_noise
const float m_noise
Definition
KickerOsc.h:95
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_counter
unsigned long m_counter
Definition
KickerOsc.h:104
lmms::KickerOsc::~KickerOsc
virtual ~KickerOsc()=default
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_FX
DspEffectLibrary::MonoToStereoAdaptor< DistFX > m_FX
Definition
KickerOsc.h:102
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_startFreq
const float m_startFreq
Definition
KickerOsc.h:93
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_length
const float m_length
Definition
KickerOsc.h:101
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_hasDistEnv
const bool m_hasDistEnv
Definition
KickerOsc.h:100
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_endFreq
const float m_endFreq
Definition
KickerOsc.h:94
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_slope
const float m_slope
Definition
KickerOsc.h:96
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_freq
double m_freq
Definition
KickerOsc.h:105
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_distStart
const float m_distStart
Definition
KickerOsc.h:98
lmms::KickerOsc::KickerOsc
KickerOsc(const FX &fx, const float start, const float end, const float noise, const float offset, const float slope, const float env, const float diststart, const float distend, const float length)
Definition
KickerOsc.h:44
lmms::KickerOsc::update
void update(SampleFrame *buf, const f_cnt_t frames, const float sampleRate)
Definition
KickerOsc.h:64
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_env
const float m_env
Definition
KickerOsc.h:97
lmms::KickerOsc< DspEffectLibrary::MonoToStereoAdaptor< DistFX > >::m_distEnd
const float m_distEnd
Definition
KickerOsc.h:99
lmms::Oscillator::noiseSample
static sample_t noiseSample(const float)
Definition
Oscillator.h:163
lmms::Oscillator::sinSample
static sample_t sinSample(const float _sample)
Definition
Oscillator.h:114
lmms::SampleFrame
Definition
SampleFrame.h:41
lmms_math.h
lmms
Definition
RemotePluginBase.cpp:34
lmms::fastPow
double fastPow(double a, double b)
Source: http://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/.
Definition
lmms_math.h:202
lmms::sample_t
float sample_t
Definition
LmmsTypes.h:39
lmms::f_cnt_t
std::uint64_t f_cnt_t
Definition
LmmsTypes.h:43
Generated on
for lmms by
1.18.0