Deluge Firmware 1.3.0
Build date: 2026.11.28
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 "dsp/reverb/freeverb/delay_lines.hpp"
27#include "dsp/reverb/freeverb/tuning.h"
28#include "util/fixedpoint.h"
29#include <cstdint>
30#include <limits>
31#include <span>
32
33namespace freeverb {
34// All the comb filters: numcombs for the left channel, then numcombs for the right. They all have the same damping and
35// feedback.
36class Combs {
37public:
38 Combs() = default;
39
40 // For comb i; the last maxblockframes words of the buffer are spare
41 void setBuffer(size_t i, std::span<int32_t> buffer) { lines_.setBuffer(i, buffer); }
42
43 void mute() { lines_.mute(); }
44
45 constexpr void setDamp(float val) {
46 damp1_ = val * std::numeric_limits<int32_t>::max();
47 damp2_ = std::numeric_limits<int32_t>::max() - damp1_;
48 }
49
50 constexpr void setFeedback(int32_t val) { feedback_ = val; }
51
52 // One frame: adds the left combs' outputs to out_l and the right ones' to out_r
53 [[gnu::always_inline]] void process(int32_t input, int32_t& out_l, int32_t& out_r) {
54 for (size_t i = 0; i < kNumCombs; i++) {
55 int32_t output = lines_[i];
56
57 filterstore_[i] = (multiply_32x32_rshift32_rounded(output, damp2_) + //<
58 multiply_32x32_rshift32_rounded(filterstore_[i], damp1_))
59 << 1;
60
61 lines_[i] = input + (multiply_32x32_rshift32_rounded(filterstore_[i], feedback_) << 1);
62
63 ((i < numcombs) ? out_l : out_r) += output;
64 }
65 lines_.advance();
66 }
67
68 // Exactly the same as process() for each frame of a block (a multiple of four frames long, at most
69 // maxblockframes), but storing the sums in output_l and output_r
70 void processBlock(const int32_t* input, int32_t* output_l, int32_t* output_r, size_t numFrames);
71
72private:
73 static constexpr size_t kNumCombs = 2 * numcombs;
74
76 alignas(16) std::array<int32_t, kNumCombs> filterstore_{};
77 int32_t damp1_;
78 int32_t damp2_;
79 int32_t feedback_;
80};
81} // namespace freeverb
82// ends
Definition delay_lines.hpp:33