Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
freeverb.hpp
1// Reverb model declaration
2//
3// Written by Jezar at Dreampoint, June 2000
4// http://www.dreampoint.co.uk
5// This code is public domain
6
7/*
8 * Copyright © 2015-2023 Synthstrom Audible Limited
9 *
10 * This file is part of The Synthstrom Audible Deluge Firmware.
11 *
12 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
13 * terms of the GNU General Public License as published by the Free Software Foundation,
14 * either version 3 of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
17 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 * See the GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along with this program.
21 * If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include "dsp/reverb/base.hpp"
27#include "dsp/reverb/freeverb/allpass.hpp"
28#include "dsp/reverb/freeverb/comb.hpp"
29#include "dsp/reverb/freeverb/tuning.h"
30#include <cstdint>
31#include <span>
32
33namespace deluge::dsp::reverb {
34class Freeverb : public Base {
35public:
36 Freeverb();
37 ~Freeverb() override = default;
38
39 void mute();
40
41 void setRoomSize(float value) override {
42 roomsize = (value * scaleroom) + offsetroom;
43 update();
44 }
45
46 [[nodiscard]] constexpr float getRoomSize() const override { return (roomsize - offsetroom) / scaleroom; }
47
48 void setDamping(float value) override {
49 damp = value * scaledamp;
50 update();
51 }
52
53 [[nodiscard]] constexpr float getDamping() const override { return damp / scaledamp; }
54
55 void setWet(float value) {
56 wet = value * scalewet;
57 update();
58 }
59
60 [[nodiscard]] constexpr float getWet() const { return wet / scalewet; }
61
62 void setDry(float value) { dry = value * scaledry; }
63
64 [[nodiscard]] constexpr float getDry() const { return dry / scaledry; }
65
66 void setWidth(float value) override {
67 width = value;
68 update();
69 }
70
71 [[nodiscard]] constexpr float getWidth() const override { return width; }
72
73 [[gnu::always_inline]] void ProcessOne(int32_t input, StereoSample& output_sample) {
74 int32_t out_l = 0;
75 int32_t out_r = 0;
76
77 // Accumulate comb filters in parallel
78 combs_.process(input, out_l, out_r);
79
80 // Feed through allpasses in series
81 allpasses_.process(out_l, out_r);
82
83 // Calculate output
84 out_l = (out_l + multiply_32x32_rshift32_rounded(out_r, wet2)) << 1;
85 out_r = (out_r + multiply_32x32_rshift32_rounded(out_l, wet2)) << 1;
86
87 // Mix output
88 output_sample.l += multiply_32x32_rshift32_rounded(out_l, this->getPanLeft());
89 output_sample.r += multiply_32x32_rshift32_rounded(out_r, this->getPanRight());
90 }
91
92 void process(std::span<int32_t> input, std::span<StereoSample> output) override;
93
94private:
95 void update();
96
97 int32_t gain;
98 float roomsize;
99 float damp;
100 float wet;
101 float wet1;
102 int32_t wet2;
103 float dry;
104 float width;
105
106 // The following are all declared inline
107 // to remove the need for dynamic allocation
108 // with its subsequent error-checking messiness
109
110 // Comb filters
111 freeverb::Combs combs_;
112
113 // Allpass filters
114 freeverb::Allpasses allpasses_;
115
116 // Buffers for the combs
117 std::array<int32_t, combtuningL1 + maxblockframes> bufcombL1;
118 std::array<int32_t, combtuningR1 + maxblockframes> bufcombR1;
119 std::array<int32_t, combtuningL2 + maxblockframes> bufcombL2;
120 std::array<int32_t, combtuningR2 + maxblockframes> bufcombR2;
121 std::array<int32_t, combtuningL3 + maxblockframes> bufcombL3;
122 std::array<int32_t, combtuningR3 + maxblockframes> bufcombR3;
123 std::array<int32_t, combtuningL4 + maxblockframes> bufcombL4;
124 std::array<int32_t, combtuningR4 + maxblockframes> bufcombR4;
125 std::array<int32_t, combtuningL5 + maxblockframes> bufcombL5;
126 std::array<int32_t, combtuningR5 + maxblockframes> bufcombR5;
127 std::array<int32_t, combtuningL6 + maxblockframes> bufcombL6;
128 std::array<int32_t, combtuningR6 + maxblockframes> bufcombR6;
129 std::array<int32_t, combtuningL7 + maxblockframes> bufcombL7;
130 std::array<int32_t, combtuningR7 + maxblockframes> bufcombR7;
131 std::array<int32_t, combtuningL8 + maxblockframes> bufcombL8;
132 std::array<int32_t, combtuningR8 + maxblockframes> bufcombR8;
133
134 // Buffers for the allpasses
135 std::array<int32_t, allpasstuningL1 + maxblockframes> bufallpassL1;
136 std::array<int32_t, allpasstuningR1 + maxblockframes> bufallpassR1;
137 std::array<int32_t, allpasstuningL2 + maxblockframes> bufallpassL2;
138 std::array<int32_t, allpasstuningR2 + maxblockframes> bufallpassR2;
139 std::array<int32_t, allpasstuningL3 + maxblockframes> bufallpassL3;
140 std::array<int32_t, allpasstuningR3 + maxblockframes> bufallpassR3;
141 std::array<int32_t, allpasstuningL4 + maxblockframes> bufallpassL4;
142 std::array<int32_t, allpasstuningR4 + maxblockframes> bufallpassR4;
143
144 int32_t reverb_send_post_lpf_ = 0;
145};
146} // namespace deluge::dsp::reverb
Definition allpass.hpp:32
Definition comb.hpp:36
Definition stereo_sample.h:25