Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
global_effectable_for_clip.h
1/*
2 * Copyright © 2016-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/stereo_sample.h"
22#include "model/global_effectable/global_effectable.h"
23#include "model/sample/sample_recorder.h"
24#include <optional>
25
27class TimelineCounter;
28class Output;
29class Clip;
30class ModelStack;
33
34class GlobalEffectableForClip : public GlobalEffectable {
35public:
36 GlobalEffectableForClip();
37
38 int32_t getSidechainVolumeAmountAsPatchCableDepth(ParamManager* paramManager);
39 void modButtonAction(uint8_t whichModButton, bool on, ParamManagerForTimeline* paramManager) final;
40 bool modEncoderButtonAction(uint8_t whichModEncoder, bool on, ModelStackWithThreeMainThings* modelStack) final;
41 virtual Output* toOutput() = 0;
42 void getThingWithMostReverb(Clip* activeClip, Sound** soundWithMostReverb,
43 ParamManager** paramManagerWithMostReverb,
44 GlobalEffectableForClip** globalEffectableWithMostReverb,
45 int32_t* highestReverbAmountFound);
46
47 int32_t getShiftAmountForSaturation() { return (clippingAmount >= 3) ? (clippingAmount - 3) : 0; }
48
51 [[gnu::always_inline]] q31_t saturate(q31_t data, uint32_t* workingValue, int32_t shiftAmount) {
52 // Clipping
53 return getTanHAntialiased(data, workingValue, 3 + clippingAmount) << (shiftAmount);
54 }
55
56 std::array<uint32_t, 2> lastSaturationTanHWorkingValue = {2147483648u, 2147483648u};
57
58protected:
59 // The clip's volume and pitch adjust, and the reverb amount for what renderGlobalEffectableForClip() renders.
60 // Worked out on first use: an idle clip renders nothing, and reading its params and their cached conversions
61 // (cold memory) every render was most of what skipping it cost
62 class RenderAdjustments {
63 public:
64 RenderAdjustments(GlobalEffectableForClip& owner, ParamManager& paramManager, int32_t reverbAmountAdjust,
65 bool reverbFollowsVolume)
66 : owner_(owner), paramManager_(paramManager), reverbAmountAdjust_(reverbAmountAdjust),
67 reverbFollowsVolume_(reverbFollowsVolume) {}
68 int32_t volume();
69 int32_t pitch();
70 int32_t reverbAmount() {
71 return reverbFollowsVolume_ ? multiply_32x32_rshift32_rounded(reverbAmountAdjust_, volume()) << 5
72 : reverbAmountAdjust_;
73 }
74
75 private:
76 GlobalEffectableForClip& owner_;
77 ParamManager& paramManager_;
78 int32_t reverbAmountAdjust_;
79 bool reverbFollowsVolume_;
80 std::optional<int32_t> volume_;
81 std::optional<int32_t> pitch_;
82 };
83
84 int32_t getParameterFromKnob(int32_t whichModEncoder) final;
85 void renderOutput(ModelStackWithTimelineCounter* modelStack, ParamManager* paramManagerForClip,
86 std::span<StereoSample> output, int32_t* reverbBuffer, int32_t reverbAmountAdjust,
87 int32_t sideChainHitPending, bool shouldLimitDelayFeedback, bool isClipActive,
88 OutputType outputType, SampleRecorder* recorder);
89
90 virtual bool renderGlobalEffectableForClip(ModelStackWithTimelineCounter* modelStack,
91 std::span<StereoSample> globalEffectableBuffer,
92 int32_t* bufferToTransferTo, int32_t* reverbBuffer,
93 RenderAdjustments& adjustments, int32_t sideChainHitPending,
94 bool shouldLimitDelayFeedback, bool isClipActive,
95 int32_t amplitudeAtStart, int32_t amplitudeAtEnd) = 0;
96
97 virtual bool willRenderAsOneChannelOnlyWhichWillNeedCopying() { return false; }
98
99 bool renderedLastTime = false;
100
101private:
102 // Render skipping once nothing renders and the FX tails have died away, renderOutput()
103 // skips the FX chain only asking renderGlobalEffectableForClip() whether it has anything yet
104 bool skippingRendering = false;
105 bool compressorClearedWhileSkipping = false; // Next to skippingRendering, so checking it costs no cache miss
106 uint32_t startSkippingRenderingAtTime = 0; // Valid when not 0: when to start skipping, after mod FX / comp tails
107 uint32_t timeStartedSkippingRendering = 0;
108 void reassessRenderSkippingStatus(ParamManager* paramManager, SampleRecorder* recorder);
109 void startSkippingRendering();
110 void stopSkippingRendering(ParamManager* paramManager);
111 void tickParamAutomation(ModelStackWithTimelineCounter* modelStack, ParamManager* paramManagerForClip,
112 size_t numSamples, bool isClipActive);
113};
Definition clip.h:46
Definition global_effectable_for_clip.h:62
q31_t saturate(q31_t data, uint32_t *workingValue, int32_t shiftAmount)
Definition global_effectable_for_clip.h:51
Definition model_stack.h:227
Definition model_stack.h:129
Definition model_stack.h:123
Definition output.h:81
Definition param_manager.h:156
Definition param_manager.h:45
Definition sample_recorder.h:53
Definition sound.h:78
Definition timeline_counter.h:28