Deluge Firmware 1.3.0
Build date: 2025.08.13
Loading...
Searching...
No Matches
impulse_response_processor.h
1/*
2 * Copyright © 2015-2023 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "dsp_ng/core/types.hpp"
21#include "util/fixedpoint.h"
22#include <cstdint>
23
24namespace deluge::dsp {
25class [[gnu::hot]] ImpulseResponseProcessor {
26 constexpr static size_t IR_SIZE = 26;
27 constexpr static size_t IR_BUFFER_SIZE = (IR_SIZE - 1);
28
29 constexpr static std::array<int32_t, IR_SIZE> ir = {
30 -3203916, 8857848, 24813136, 41537808, 35217472, 15195632, -27538592, -61984128, 1944654848,
31 1813580928, 438462784, 101125088, 6042048, -22429488, -46218864, -56638560, -64785312, -52108528,
32 -37256992, -11863856, 1390352, 14663296, 12784464, 14254800, 5690912, 4490736,
33 };
34
35public:
36 ImpulseResponseProcessor() = default;
37
38 inline void process(const StereoSample<q31_t> input, StereoSample<q31_t>& output) {
39 output.l = buffer_[0].l + multiply_32x32_rshift32_rounded(input.l, ir[0]);
40 output.r = buffer_[0].r + multiply_32x32_rshift32_rounded(input.r, ir[0]);
41
42 for (int32_t i = 1; i < IR_BUFFER_SIZE; i++) {
43 buffer_[i - 1].l = buffer_[i].l + multiply_32x32_rshift32_rounded(input.l, ir[i]);
44 buffer_[i - 1].r = buffer_[i].r + multiply_32x32_rshift32_rounded(input.r, ir[i]);
45 }
46
47 buffer_[IR_BUFFER_SIZE - 1].l = multiply_32x32_rshift32_rounded(input.l, ir[IR_BUFFER_SIZE]);
48 buffer_[IR_BUFFER_SIZE - 1].r = multiply_32x32_rshift32_rounded(input.r, ir[IR_BUFFER_SIZE]);
49 }
50
51private:
52 std::array<StereoSample<q31_t>, IR_BUFFER_SIZE> buffer_;
53};
54} // namespace deluge::dsp