Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
allpass.hpp
1// Allpass filter 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#include "util/functions.h"
26#include <cstdint>
27#include <limits>
28#include <span>
29
30namespace freeverb {
31class Allpass {
32public:
33 Allpass() = default;
34
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 setFeedback(float val) { feedback_ = val * std::numeric_limits<int32_t>::max(); }
40
41 [[nodiscard]] constexpr float getFeedback() const { return (float)feedback_ / std::numeric_limits<int32_t>::max(); }
42
43 [[gnu::always_inline]] constexpr int32_t process(int32_t input) {
44 int32_t bufout = buffer_[bufidx_];
45 int32_t output = -input + bufout;
46
47 buffer_[bufidx_] = input + (bufout >> 1); // Shortcut - because feedback was always one half by default anyway
48 // buffer[bufidx] = input + (multiply_32x32_rshift32_rounded(bufout, feedback) << 1);
49
50 if (++bufidx_ >= buffer_.size()) {
51 bufidx_ = 0;
52 }
53
54 return output;
55 }
56
57private:
58 int32_t feedback_;
59 std::span<int32_t> buffer_;
60 int32_t bufidx_{0};
61};
62} // namespace freeverb