Deluge Firmware
1.3.0
Build date: 2026.10.05
Toggle main menu visibility
Loading...
Searching...
No Matches
GranularProcessor.h
1
/*
2
* Copyright © 2024 Mark Adams and Alter-Alter
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 "GranularProcessor.h"
21
#include "OSLikeStuff/scheduler_api.h"
22
#include "definitions_cxx.hpp"
23
#include "dsp/filter/ladder_components.h"
24
#include "dsp/stereo_sample.h"
25
#include "memory/stealable.h"
26
#include "modulation/lfo.h"
27
#include <span>
28
29
class
UnpatchedParamSet
;
30
31
struct
Grain
{
32
int32_t length;
// in samples 0=OFF
33
int32_t startPoint;
// starttimepos in samples
34
int32_t counter;
// relative pos in samples
35
uint16_t pitch;
// 1024=1.0
36
int32_t volScale;
37
int32_t volScaleMax;
38
bool
rev;
// 0=normal, 1 =reverse
39
int32_t panVolL;
// 0 - 1073741823
40
int32_t panVolR;
// 0 - 1073741823
41
};
42
class
GrainBuffer
;
43
46
class
GranularProcessor {
47
public
:
48
GranularProcessor();
49
GranularProcessor(
const
GranularProcessor& other);
// copy constructor
50
~GranularProcessor();
51
[[nodiscard]] int32_t getSamplesToShutdown()
const
{
return
wrapsToShutdown * kModFXGrainBufferSize; }
52
54
void
startSkippingRendering
();
55
57
void
processGrainFX
(std::span<StereoSample> buffer, int32_t grainRate, int32_t grainMix, int32_t grainDensity,
58
int32_t pitchRandomness, int32_t* postFXVolume,
bool
anySoundComingIn,
float
tempoBPM,
59
q31_t reverbAmount);
60
61
void
clearGrainFXBuffer();
62
void
grainBufferStolen() { grainBuffer =
nullptr
; }
63
64
private
:
65
void
setupGrainFX(int32_t grainRate, int32_t grainMix, int32_t grainDensity, int32_t pitchRandomness,
66
int32_t* postFXVolume,
float
timePerInternalTick);
67
StereoSample
processOneGrainSample(
StereoSample
currentSample);
68
void
getBuffer();
69
void
setWrapsToShutdown();
70
void
setupGrainsIfNeeded(int32_t writeIndex);
71
// parameters
72
uint32_t bufferWriteIndex;
73
int32_t _grainSize;
74
int32_t _grainRate;
75
int32_t _grainShift;
76
int32_t _grainFeedbackVol;
77
int32_t _grainVol;
78
int32_t _grainDryVol;
79
int32_t _pitchRandomness;
80
81
bool
grainLastTickCountIsZero;
82
bool
grainInitialized;
83
84
Grain
grains[8]{};
85
86
int32_t wrapsToShutdown;
87
GrainBuffer
* grainBuffer{};
88
int32_t _densityKnobPos{0};
89
int32_t _rateKnobPos{0};
90
int32_t _mixKnobPos{0};
91
deluge::dsp::filter::BasicFilterComponent
lpf_l{};
92
deluge::dsp::filter::BasicFilterComponent
lpf_r{};
93
bool
tempoSync{
true
};
94
bool
bufferFull{
false
};
95
};
96
97
class
GrainBuffer :
public
Stealable {
98
public
:
99
GrainBuffer() =
delete
;
100
GrainBuffer(GrainBuffer& other) =
delete
;
101
GrainBuffer(
const
GrainBuffer& other) =
delete
;
102
explicit
GrainBuffer(
GranularProcessor
* grainFX) { owner = grainFX; }
103
bool
mayBeStolen(
void
* thingNotToStealFrom)
override
{
104
if
(thingNotToStealFrom !=
this
) {
105
return
!inUse;
106
}
107
return
false
;
108
};
109
void
steal(
char
const
* errorCode)
override
{ owner->grainBufferStolen(); };
110
111
// gives it a high priority - these are huge so reallocating them can be slow
112
StealableQueue getAppropriateQueue()
override
{
return
StealableQueue::CURRENT_SONG_SAMPLE_DATA_REPITCHED_CACHE; };
113
StereoSample
& operator[](int32_t i) {
return
sampleBuffer[i]; }
114
StereoSample
operator[](int32_t i)
const
{
return
sampleBuffer[i]; }
115
bool
inUse{
true
};
116
117
private
:
118
GranularProcessor
* owner;
119
StereoSample
sampleBuffer[kModFXGrainBufferSize];
120
};
GrainBuffer
Definition
GranularProcessor.h:97
GranularProcessor
Definition
GranularProcessor.h:46
GranularProcessor::startSkippingRendering
void startSkippingRendering()
allows the buffer to be stolen
Definition
GranularProcessor.cpp:343
GranularProcessor::processGrainFX
void processGrainFX(std::span< StereoSample > buffer, int32_t grainRate, int32_t grainMix, int32_t grainDensity, int32_t pitchRandomness, int32_t *postFXVolume, bool anySoundComingIn, float tempoBPM, q31_t reverbAmount)
preset is currently converted from a param to a 0-4 preset inside the grain, which is probably not gr...
Definition
GranularProcessor.cpp:47
UnpatchedParamSet
Definition
param_set.h:98
deluge::dsp::filter::BasicFilterComponent
Definition
ladder_components.h:23
Grain
Definition
GranularProcessor.h:31
StereoSample
Definition
stereo_sample.h:25