forked from xffff/fbdelay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbdelay.cpp
executable file
·188 lines (164 loc) · 5.54 KB
/
fbdelay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//--------------------------------------------------------------------------------------------
// 14/07/13
// Filename : fbdelay.cpp
// Created by : Michael Murphy
// Description : Feedback delay line
//
//-------------------------------------------------------------------------------------------
#include "fbdelay.h"
//-------------------------------------------------------------------------------------------
AudioEffect* createEffectInstance (audioMasterCallback audioMaster)
{
return new FBdelay (audioMaster);
}
//-------------------------------------------------------------------------------------------
FBdelay::FBdelay (audioMasterCallback audioMaster)
: AudioEffectX (audioMaster, 1, 3)
{
setNumInputs (1); // stereo in
setNumOutputs (1); // stereo out
setUniqueID ('delay'); // identify
canProcessReplacing (); // supports replacing output
canDoubleReplacing (); // supports double precision processing
i0 = 1; // gain
i1 = 0.5f; // delay
i2 = 0.7f; // fb
maxdlyms = 10000;
maxbufsize = maxdlyms * getSampleRate() * 0.001;
rpos = 0;
wpos = 0;
dlybuf = new double[maxbufsize];
lsamp = 0;
memset(dlybuf, 0, maxbufsize * sizeof(double));
vst_strncpy (programName, "Default", kVstMaxProgNameLen); // default program name
}
//--------------------------------------------------------------------------------------------
FBdelay::~FBdelay ()
{
if(dlybuf)
{ delete [] dlybuf; }
}
//-------------------------------------------------------------------------------------------
void FBdelay::setProgramName (char* name)
{
vst_strncpy (programName, name, kVstMaxProgNameLen);
}
//-----------------------------------------------------------------------------------------
void FBdelay::getProgramName (char* name)
{
vst_strncpy (name, programName, kVstMaxProgNameLen);
}
//-----------------------------------------------------------------------------------------
void FBdelay::setParameter (VstInt32 index, float value)
{
int temp;
switch(index) {
case 0: i0 = value; break;
case 1: i1 = value; break;
case 2: i2 = value; break;
}
gain = i0;
dly = (int)(i1 * maxdlyms);
fb = 0.9f * i2;
temp = (int)(wpos - dly * getSampleRate() * 0.001);
if(rpos != temp){
rpos = temp;
if(rpos < 0)
{ rpos += maxbufsize; }
}
}
//-----------------------------------------------------------------------------------------
float FBdelay::getParameter (VstInt32 index)
{
switch(index) {
case 0: return i0; break;
case 1: return i1; break;
case 2: return i2; break;
}
}
//-----------------------------------------------------------------------------------------
void FBdelay::getParameterName (VstInt32 index, char* label)
{
switch(index) {
case 0: vst_strncpy (label, "Gain", kVstMaxParamStrLen); break;
case 1: vst_strncpy (label, "Delay", kVstMaxParamStrLen); break;
case 2: vst_strncpy (label, "Feedback", kVstMaxParamStrLen); break;
}
}
//-----------------------------------------------------------------------------------------
void FBdelay::getParameterDisplay (VstInt32 index, char* text)
{
switch(index) {
case 0: dB2string (gain, text, kVstMaxParamStrLen); break;
case 1: int2string (dly, text, kVstMaxParamStrLen); break;
case 2: int2string (99 * i2, text, kVstMaxParamStrLen); break;
}
}
//-----------------------------------------------------------------------------------------
void FBdelay::getParameterLabel (VstInt32 index, char* label)
{
switch(index) {
case 0: vst_strncpy (label, "dB", kVstMaxParamStrLen); break;
case 1: vst_strncpy (label, "ms", kVstMaxParamStrLen); break;
case 2: vst_strncpy (label, "%", kVstMaxParamStrLen); break;
}
}
//------------------------------------------------------------------------
bool FBdelay::getEffectName (char* name)
{
vst_strncpy (name, "delay", kVstMaxEffectNameLen);
return true;
}
//------------------------------------------------------------------------
bool FBdelay::getProductString (char* text)
{
vst_strncpy (text, "delay", kVstMaxProductStrLen);
return true;
}
//------------------------------------------------------------------------
bool FBdelay::getVendorString (char* text)
{
vst_strncpy (text, "xffff", kVstMaxVendorStrLen);
return true;
}
//-----------------------------------------------------------------------------------------
VstInt32 FBdelay::getVendorVersion ()
{
return 1000;
}
//-----------------------------------------------------------------------------------------
void FBdelay::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames)
{
float* in = inputs[0];
float* out = outputs[0];
float s;
for(int i=0; i<sampleFrames; i++) {
dlybuf[wpos++] = in[i] + lsamp;
if(wpos == maxbufsize)
{ wpos = 0; }
s = dlybuf[rpos];
lsamp = s * fb;
rpos++;
if(rpos >= maxbufsize)
{ rpos -= maxbufsize; }
out[i] = s * gain;
}
}
//-----------------------------------------------------------------------------------------
void FBdelay::processDoubleReplacing (double** inputs, double** outputs, VstInt32 sampleFrames)
{
double* in = inputs[0];
double* out = outputs[0];
double s;
for(int i=0; i<sampleFrames; i++) {
dlybuf[wpos++] = in[i] + lsamp;
if(wpos == maxbufsize)
{ wpos = 0; }
s = dlybuf[rpos];
lsamp = s * fb;
rpos++;
if(rpos >= maxbufsize)
{ rpos -= maxbufsize; }
out[i] = s * gain;
}
}