Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
comb.hpp
1// Comb filter class 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 "util/fixedpoint.h"
27#include <cstdint>
28#include <limits>
29#include <span>
30
31namespace freeverb {
32class Comb {
33public:
34 Comb() = default;
35 constexpr void setBuffer(std::span<int32_t> buffer) { buffer_ = buffer; }
36
37 constexpr void mute() { std::fill(buffer_.begin(), buffer_.end(), 0); }
38
39 constexpr void setDamp(float val) {
40 damp1_ = val * std::numeric_limits<int32_t>::max();
41 damp2_ = std::numeric_limits<int32_t>::max() - damp1_;
42 }
43
44 [[nodiscard]] constexpr float getDamp() const { return damp1_ / std::numeric_limits<int32_t>::max(); }
45
46 constexpr void setFeedback(int32_t val) { feedback_ = val; }
47
48 [[nodiscard]] constexpr int32_t getFeedback() const { return feedback_; }
49
50 // Big to inline - but crucial for speed
51 inline int32_t process(int32_t input) {
52 int32_t output = buffer_[bufidx_];
53
54 filterstore_ = (multiply_32x32_rshift32_rounded(output, damp2_) + //<
55 multiply_32x32_rshift32_rounded(filterstore_, damp1_))
56 << 1;
57
58 buffer_[bufidx_] = input + (multiply_32x32_rshift32_rounded(filterstore_, feedback_) << 1);
59
60 if (++bufidx_ >= buffer_.size()) {
61 bufidx_ = 0;
62 }
63
64 return output;
65 }
66
67private:
68 int32_t feedback_;
69 int32_t filterstore_{0};
70 int32_t damp1_;
71 int32_t damp2_;
72 std::span<int32_t> buffer_;
73 int32_t bufidx_{0};
74};
75} // namespace freeverb
76// ends