LMMS
Loading...
Searching...
No Matches
SlewDistortion.h
Go to the documentation of this file.
1/*
2 * SlewDistortion.h
3 *
4 * Copyright (c) 2025 Lost Robot <r94231/at/gmail/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_SLEW_DISTORTION_H
26#define LMMS_SLEW_DISTORTION_H
27
28#include "Effect.h"
30
31#include "BasicFilters.h"
32#include "lmms_math.h"
33#include "OversamplingHelpers.h"
34
35namespace lmms
36{
37constexpr inline float SLEW_DISTORTION_MIN_FLOOR = 0.0012589f;// -72 dBFS
38constexpr inline float SLEW_DISTORTION_DC_FREQ = 7.f;
39
40class SlewDistortion : public Effect
41{
42 Q_OBJECT
43public:
44 SlewDistortion(Model* parent, const Descriptor::SubPluginFeatures::Key* key);
45 ~SlewDistortion() override = default;
46 ProcessStatus processImpl(SampleFrame* buf, const f_cnt_t frames) override;
47
49 {
51 }
52
53 float msToCoeff(float ms)
54 {
55 return (ms == 0) ? 0 : std::exp(m_coeffPrecalc / ms);
56 }
57private slots:
58 void changeSampleRate();
59private:
60 alignas(16) std::array<float, 4> m_inPeakDisplay = {0};
61 alignas(16) std::array<float, 4> m_slewOut = {0};
62 alignas(16) std::array<float, 4> m_dcOffset = {0};
63 alignas(16) std::array<float, 4> m_inEnv = {0};
64 alignas(16) std::array<float, 4> m_outEnv = {0};
65 alignas(16) std::array<float, 4> m_outPeakDisplay = {0};
66 alignas(16) std::array<std::array<float, 1 << SLEWDIST_MAX_OVERSAMPLE_STAGES>, 2> m_overOuts = {{0}};
67
68 float m_sampleRate = 44100.f;
69
71 float m_coeffPrecalc = 0;
72 float m_dcCoeff = 0;
74 float m_trueBias1 = 0;
75 float m_trueBias2 = 0;
76
77 std::array<Upsampler<SLEWDIST_MAX_OVERSAMPLE_STAGES>, 2> m_upsampler;
78 std::array<Downsampler<SLEWDIST_MAX_OVERSAMPLE_STAGES>, 2> m_downsampler;
79
82
84
87};
88
89} // namespace lmms
90
91#endif // LMMS_SLEW_DISTORTION_H
Definition EffectControls.h:44
Effect(const Plugin::Descriptor *_desc, Model *_parent, const Descriptor::SubPluginFeatures::Key *_key)
Definition Effect.cpp:41
ProcessStatus
Definition Effect.h:147
Definition Model.h:37
const Descriptor::SubPluginFeatures::Key & key() const
Definition Plugin.h:266
Definition SampleFrame.h:41
EffectControls * controls() override
Definition SlewDistortion.h:48
float msToCoeff(float ms)
Definition SlewDistortion.h:53
std::array< Upsampler< SLEWDIST_MAX_OVERSAMPLE_STAGES >, 2 > m_upsampler
Definition SlewDistortion.h:77
float m_dcCoeff
Definition SlewDistortion.h:72
StereoLinkwitzRiley m_lp
Definition SlewDistortion.h:80
std::array< float, 4 > m_dcOffset
Definition SlewDistortion.h:62
float m_biasInterpCoef
Definition SlewDistortion.h:73
std::array< float, 4 > m_inPeakDisplay
Definition SlewDistortion.h:60
std::array< Downsampler< SLEWDIST_MAX_OVERSAMPLE_STAGES >, 2 > m_downsampler
Definition SlewDistortion.h:78
~SlewDistortion() override=default
void changeSampleRate()
Definition SlewDistortion.cpp:674
std::array< float, 4 > m_inEnv
Definition SlewDistortion.h:63
std::array< std::array< float, 1<< SLEWDIST_MAX_OVERSAMPLE_STAGES >, 2 > m_overOuts
Definition SlewDistortion.h:66
std::array< float, 4 > m_outPeakDisplay
Definition SlewDistortion.h:65
float m_coeffPrecalc
Definition SlewDistortion.h:71
float m_trueBias2
Definition SlewDistortion.h:75
friend class SlewDistortionControls
Definition SlewDistortion.h:85
SlewDistortionControls m_slewdistortionControls
Definition SlewDistortion.h:83
float m_trueBias1
Definition SlewDistortion.h:74
int m_oldOversampleVal
Definition SlewDistortion.h:70
StereoLinkwitzRiley m_hp
Definition SlewDistortion.h:81
std::array< float, 4 > m_outEnv
Definition SlewDistortion.h:64
SlewDistortion(Model *parent, const Descriptor::SubPluginFeatures::Key *key)
Definition SlewDistortion.cpp:50
ProcessStatus processImpl(SampleFrame *buf, const f_cnt_t frames) override
Definition SlewDistortion.cpp:439
std::array< float, 4 > m_slewOut
Definition SlewDistortion.h:61
float m_sampleRate
Definition SlewDistortion.h:68
Definition SlewDistortionControlDialog.h:44
static uintptr_t parent
Definition pugl.h:1644
Definition AudioAlsa.cpp:35
constexpr int SLEWDIST_MAX_OVERSAMPLE_STAGES
Definition SlewDistortionControls.h:35
constexpr float SLEW_DISTORTION_MIN_FLOOR
Definition SlewDistortion.h:37
constexpr float SLEW_DISTORTION_DC_FREQ
Definition SlewDistortion.h:38
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
LinkwitzRiley< 2 > StereoLinkwitzRiley
Definition BasicFilters.h:140