Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
stutterer.h
1/*
2 * Copyright © 2016-2024 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/delay/delay_buffer.h"
21#include <cstdint>
22#include <span>
23
25class ParamManager;
26class StereoSample;
27
29 bool useSongStutter = true;
30 bool quantized = true;
31 bool reversed = false;
32 bool pingPong = false;
33};
34
35class Stutterer {
36public:
37 Stutterer() = default;
38 static void initParams(ParamManager* paramManager);
39 inline bool isStuttering(void* source) { return stutterSource == source; }
40 // These calls are slightly awkward with the magniture & timePerTickInverse, but that's the price for not depending
41 // on currentSong and playbackhandler...
42 [[nodiscard]] Error beginStutter(void* source, ParamManagerForTimeline* paramManager, StutterConfig stutterConfig,
43 int32_t magnitude, uint32_t timePerTickInverse);
44 void processStutter(std::span<StereoSample> audio, ParamManager* paramManager, int32_t magnitude,
45 uint32_t timePerTickInverse);
46 void endStutter(ParamManagerForTimeline* paramManager = nullptr);
47
48private:
49 enum class Status {
50 OFF,
51 RECORDING,
52 PLAYING,
53 };
54 int32_t getStutterRate(ParamManager* paramManager, int32_t magnitude, uint32_t timePerTickInverse);
55 bool currentReverse;
56 DelayBuffer buffer;
57 Status status = Status::OFF;
58 // TODO: This is currently unused! It's set to 7 initially, and never modified. Either we should set it depending
59 // on sync, or get rid of it entirely.
60 uint8_t sync = 7;
61 StutterConfig stutterConfig;
62 int32_t sizeLeftUntilRecordFinished = 0;
63 int32_t valueBeforeStuttering = 0;
64 int32_t lastQuantizedKnobDiff = 0;
67 void* stutterSource = nullptr;
68};
69
70// There's only one stutter effect active at a time, so we have a global stutterer to save memory.
71extern Stutterer stutterer;
Definition delay_buffer.h:30
Definition param_manager.h:174
Definition param_manager.h:45
Definition stutterer.h:35
void * stutterSource
Definition stutterer.h:67
Definition stereo_sample.h:25
Definition stutterer.h:28