LMMS
Loading...
Searching...
No Matches
FrequencyShifterEffect.h
Go to the documentation of this file.
1/*
2 * FrequencyShifter.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#ifndef LMMS_FREQUENCY_SHIFTER_EFFECT_H
25#define LMMS_FREQUENCY_SHIFTER_EFFECT_H
26
27#include "Effect.h"
29
30#include "HilbertTransform.h"
31#include "interpolation.h"
32#include "lmms_math.h"
33
34#include <array>
35#include <cmath>
36#include <numbers>
37#include <vector>
38
39namespace lmms
40{
41
43{
44 Q_OBJECT
45public:
46 FrequencyShifterEffect(Model* parent, const Descriptor::SubPluginFeatures::Key* key);
47 ~FrequencyShifterEffect() override = default;
48
49 ProcessStatus processImpl(SampleFrame* buf, const f_cnt_t frames) override;
51 {
52 return &m_controls;
53 }
54
55private slots:
56 void updateSampleRate();
57
58private:
59 std::array<float, 2> getHermiteSample(int indexFloor, float fraction)
60 {
61 const int size = m_ringBufSize;
62
63 const int i0 = (indexFloor == 0) ? (size - 1) : (indexFloor - 1);
64 const int i1 = indexFloor;
65
66 int i2 = indexFloor + 1;
67 int i3 = indexFloor + 2;
68 if (i2 >= size) i2 -= size;
69 if (i3 >= size) i3 -= size;
70
71 std::array<float, 2> out;
72
73 for (int ch = 0; ch < 2; ++ch)
74 {
75 const float v0 = m_ringBuf[i0][ch];
76 const float v1 = m_ringBuf[i1][ch];
77 const float v2 = m_ringBuf[i2][ch];
78 const float v3 = m_ringBuf[i3][ch];
79
80 out[ch] = hermiteInterpolate(v0, v1, v2, v3, fraction);
81 }
82
83 return out;
84 }
85
88
89 std::vector<std::array<float, 2>> m_ringBuf;
90
91 std::array<float, 2> m_phase{};
92 std::array<float, 2> m_trueShift{};
93 std::array<float, 2> m_dampState{};
94 std::array<float, 2> m_toneState{};
95
96 float m_lfoPhase{};
97 float m_truePhase{};
98 float m_trueDelay{1.f};
99
102
105
108
110};
111
112} // namespace lmms
113
114#endif // LMMS_FREQUENCY_SHIFTER_EFFECT_H
115
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 FrequencyShifterControls.h:36
int m_writeIndex
Definition FrequencyShifterEffect.h:104
bool m_prevResetShifter
Definition FrequencyShifterEffect.h:106
void updateSampleRate()
Definition FrequencyShifterEffect.cpp:262
~FrequencyShifterEffect() override=default
float m_twoPiOverSr
Definition FrequencyShifterEffect.h:100
std::array< float, 2 > m_trueShift
Definition FrequencyShifterEffect.h:92
std::array< float, 2 > m_dampState
Definition FrequencyShifterEffect.h:93
EffectControls * controls() override
Definition FrequencyShifterEffect.h:50
float m_sampleRate
Definition FrequencyShifterEffect.h:101
float m_truePhase
Definition FrequencyShifterEffect.h:97
std::array< float, 2 > m_toneState
Definition FrequencyShifterEffect.h:94
HilbertIIRFloat< 2 > m_hilbert1
Definition FrequencyShifterEffect.h:86
FrequencyShifterEffect(Model *parent, const Descriptor::SubPluginFeatures::Key *key)
Definition FrequencyShifterEffect.cpp:56
bool m_prevResetLfo
Definition FrequencyShifterEffect.h:107
std::array< float, 2 > m_phase
Definition FrequencyShifterEffect.h:91
ProcessStatus processImpl(SampleFrame *buf, const f_cnt_t frames) override
Definition FrequencyShifterEffect.cpp:65
int m_ringBufSize
Definition FrequencyShifterEffect.h:103
HilbertIIRFloat< 2 > m_hilbert2
Definition FrequencyShifterEffect.h:87
float m_lfoPhase
Definition FrequencyShifterEffect.h:96
FrequencyShifterControls m_controls
Definition FrequencyShifterEffect.h:109
float m_trueDelay
Definition FrequencyShifterEffect.h:98
std::vector< std::array< float, 2 > > m_ringBuf
Definition FrequencyShifterEffect.h:89
std::array< float, 2 > getHermiteSample(int indexFloor, float fraction)
Definition FrequencyShifterEffect.h:59
Definition Model.h:37
const Descriptor::SubPluginFeatures::Key & key() const
Definition Plugin.h:266
Definition SampleFrame.h:41
static void v2(register WDL_FFT_REAL *a)
Definition fft.c:1099
static uintptr_t parent
Definition pugl.h:1644
float out
Definition lilv_test.c:1461
Definition AudioAlsa.cpp:35
float hermiteInterpolate(float x0, float x1, float x2, float x3, float frac_pos)
Definition interpolation.h:34
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
auto fraction(std::floating_point auto x) noexcept
Returns the fractional part of a float, a value between -1.0f and 1.0f.
Definition lmms_math.h:63
Definition HilbertTransform.h:46
ulg size
Definition extract.c:2350