Deluge Firmware 1.3.0
Build date: 2025.09.14
Loading...
Searching...
No Matches
delay.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 "definitions_cxx.hpp"
21#include "dsp/convolution/impulse_response_processor.h"
22#include "dsp/delay/delay_buffer.h"
23#include "model/sync.h"
24
25#include <cstdint>
26#include <span>
27
28namespace deluge::dsp {
29
30class Delay {
31public:
32 struct State {
33 bool doDelay;
34 int32_t userDelayRate;
35 int32_t delayFeedbackAmount;
36 int32_t analog_saturation = 8;
37 };
38
39 Delay() = default;
40 Delay(const Delay& other) = delete;
41
42 // was originally cloneFrom
43 Delay& operator=(const Delay& rhs) {
44 pingPong = rhs.pingPong;
45 analog = rhs.analog;
46 syncLevel = rhs.syncLevel;
47 return *this;
48 }
49
50 [[nodiscard]] constexpr bool isActive() const { return (primaryBuffer.isActive() || secondaryBuffer.isActive()); }
51
52 void informWhetherActive(bool newActive, int32_t userDelayRate = 0);
53 void copySecondaryToPrimary();
54 void copyPrimaryToSecondary();
55 void initializeSecondaryBuffer(int32_t newNativeRate, bool makeNativeRatePreciseRelativeToOtherBuffer);
56 void setupWorkingState(State& workingState, uint32_t timePerInternalTickInverse, bool anySoundComingIn = true);
57 void discardBuffers();
58 void setTimeToAbandon(const State& workingState);
59 void hasWrapped();
60
61 DelayBuffer primaryBuffer;
62 DelayBuffer secondaryBuffer;
63 ImpulseResponseProcessor ir_processor;
64
65 uint32_t countCyclesWithoutChange;
66 int32_t userRateLastTime;
67 bool pingPong = true;
68 bool analog = false;
69
70 SyncType syncType = SYNC_TYPE_EVEN;
71
72 // Basically, 0 is off, max value is 9. Higher numbers are shorter intervals (higher speed).
73 SyncLevel syncLevel = SYNC_LEVEL_16TH;
74
75 int32_t sizeLeftUntilBufferSwap;
76
77 int32_t postLPFL;
78 int32_t postLPFR;
79
80 int32_t prevFeedback = 0;
81
82 uint8_t repeatsUntilAbandon = 0; // 0 means never abandon
83
84 void process(StereoBuffer<q31_t> buffer, const State& delayWorkingState);
85
86private:
87 void prepareToBeginWriting();
88 [[nodiscard]] constexpr int32_t getAmountToWriteBeforeReadingBegins() const { return secondaryBuffer.size(); }
89};
90} // namespace deluge::dsp
Definition delay.h:32