LMMS
Loading...
Searching...
No Matches
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
36namespace lmms
37{
38
39
40template<class FX = DspEffectLibrary::StereoBypass>
42{
43public:
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 ),
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 ),
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
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
91private:
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;
103
104 unsigned long m_counter;
105 double m_freq;
106
107};
108
109
110} // namespace lmms
111
112#endif
virtual ~KickerOsc()=default
DspEffectLibrary::MonoToStereoAdaptor< DistFX > m_FX
Definition KickerOsc.h:102
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
void update(SampleFrame *buf, const f_cnt_t frames, const float sampleRate)
Definition KickerOsc.h:64
static sample_t noiseSample(const float)
Definition Oscillator.h:163
static sample_t sinSample(const float _sample)
Definition Oscillator.h:114
Definition SampleFrame.h:41
unsigned s
Definition inflate.c:1555
virtual ASIOError start()=0
static float noise(float x, float y)
Definition lice_texgen.cpp:149
Definition AudioAlsa.cpp:35
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
float sample_t
Definition LmmsTypes.h:39
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
png_uint_32 length
Definition png.c:2247