Debian Codegraph @

plugins/dragonfly-hall-reverb/DSP.cpp

raw
1 /*
2 * Dragonfly Reverb, a hall-style reverb plugin
3 * Copyright (c) 2018 Michael Willis, Rob van den Berg
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 3 of
8 * the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * For a full copy of the GNU General Public License see the LICENSE file.
16 */
17
18 #include "DistrhoPlugin.hpp"
19 #include "DistrhoPluginInfo.h"
20 #include "extra/ScopedDenormalDisable.hpp"
21
22 #include "DSP.hpp"
23
24 DragonflyReverbDSP::DragonflyReverbDSP(double sampleRate) {
25 early.loadPresetReflection(FV3_EARLYREF_PRESET_1);
26 early.setMuteOnChange(false);
27 early.setdryr(0); // mute dry signal
28 early.setwet(0); // 0dB
29 early.setwidth(0.8);
30 early.setLRDelay(0.3);
31 early.setLRCrossApFreq(750, 4);
32 early.setDiffusionApFreq(150, 4);
33 early.setSampleRate(sampleRate);
34 early_send = 0.20;
35
36 late.setMuteOnChange(false);
37 late.setwet(0); // 0dB
38 late.setdryr(0); // mute dry signal
39 late.setwidth(1.0);
40 late.setSampleRate(sampleRate);
41
42 for (uint32_t param = 0; param < paramCount; param++) {
43 newParams[param] = banks[DEFAULT_BANK].presets[DEFAULT_PRESET].params[param];
44 oldParams[param] = -1.0;
45 }
46 }
47
48 float DragonflyReverbDSP::getParameterValue(uint32_t index) const {
49 if (index < paramCount) {
50 return newParams[index];
51 }
52
53 return 0.0;
54 }
55
56 void DragonflyReverbDSP::setParameterValue(uint32_t index, float value) {
57 if (index < paramCount) {
58 newParams[index] = value;
59 }
60 }
61
62 void DragonflyReverbDSP::run(const float** inputs, float** outputs, uint32_t frames) {
63 const ScopedDenormalDisable sdd;
64 for (uint32_t index = 0; index < paramCount; index++) {
65 if (d_isNotEqual(oldParams[index], newParams[index])) {
66 oldParams[index] = newParams[index];
67 float value = newParams[index];
68
69 switch(index) {
70 case paramDry: dryLevel = (value / 100.0); break;
71 case paramEarly: earlyLevel = (value / 100.0); break;
72 case paramLate: lateLevel = (value / 100.0); break;
73 case paramSize: early.setRSFactor (value / 10.0);
74 late.setRSFactor (value / 80.0); break;
75 case paramWidth: early.setwidth (value / 100.0);
76 late.setwidth (value / 100.0); break;
77 case paramPredelay:
78 // Freeverb doesn't handle zero predelay properly
79 // Instead of modifying the library, avoid it here
80 if (value < 0.1) {
81 value = 0.1;
82 }
83 late.setPreDelay (value);
84 break;
85 case paramDiffuse: late.setidiffusion1(value / 140.0);
86 late.setapfeedback (value / 140.0); break;
87 case paramLowCut: early.setoutputhpf (value);
88 late.setoutputhpf (value); break;
89 case paramLowXover: late.setxover_low (value); break;
90 case paramLowMult: late.setrt60_factor_low(value); break;
91 case paramHighCut: early.setoutputlpf (value);
92 late.setoutputlpf (value); break;
93 case paramHighXover: late.setxover_high (value); break;
94 case paramHighMult: late.setrt60_factor_high(value); break;
95 case paramSpin: late.setspin (value); break;
96 case paramWander: late.setwander (value); break;
97 case paramDecay: late.setrt60 (value); break;
98 case paramEarlySend: early_send = (value / 100.0); break;
99 case paramModulation:
100 // Avoid ill effects of zero modulation, set to one tenth of a percent instead
101 float mod = value == 0.0 ? 0.001 : value / 100.0;
102 late.setspinfactor (mod);
103 late.setlfofactor (mod);
104 break;
105 }
106 }
107 }
108
109 for (uint32_t offset = 0; offset < frames; offset += BUFFER_SIZE) {
110 long int buffer_frames = frames - offset < BUFFER_SIZE ? frames - offset : BUFFER_SIZE;
111
112 early.processreplace(
113 const_cast<float *>(inputs[0] + offset),
114 const_cast<float *>(inputs[1] + offset),
115 early_out_buffer[0],
116 early_out_buffer[1],
117 buffer_frames);
118
119 for (uint32_t i = 0; i < buffer_frames; i++) {
120 late_in_buffer[0][i] = early_send * early_out_buffer[0][i] + inputs[0][offset + i];
121 late_in_buffer[1][i] = early_send * early_out_buffer[1][i] + inputs[1][offset + i];
122 }
123
124 late.processreplace(
125 const_cast<float *>(late_in_buffer[0]),
126 const_cast<float *>(late_in_buffer[1]),
127 late_out_buffer[0],
128 late_out_buffer[1],
129 buffer_frames);
130
131 for (uint32_t i = 0; i < buffer_frames; i++) {
132 outputs[0][offset + i] = dryLevel * inputs[0][offset + i];
133 outputs[1][offset + i] = dryLevel * inputs[1][offset + i];
134 }
135
136 if( earlyLevel > 0.0 ){
137 for (uint32_t i = 0; i < buffer_frames; i++) {
138 outputs[0][offset + i] += earlyLevel * early_out_buffer[0][i];
139 outputs[1][offset + i] += earlyLevel * early_out_buffer[1][i];
140 }
141 }
142
143 if( lateLevel > 0.0 ){
144 for (uint32_t i = 0; i < buffer_frames; i++) {
145 outputs[0][offset + i] += lateLevel * late_out_buffer[0][i];
146 outputs[1][offset + i] += lateLevel * late_out_buffer[1][i];
147 }
148 }
149 }
150 }
151
152 void DragonflyReverbDSP::sampleRateChanged(double newSampleRate) {
153 early.setSampleRate(newSampleRate);
154 late.setSampleRate(newSampleRate);
155 }
156
157 void DragonflyReverbDSP::mute() {
158 early.mute();
159 late.mute();
160 }