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