-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaudioobject_allfilter.h
363 lines (276 loc) · 6.91 KB
/
audioobject_allfilter.h
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#ifndef CAMX_AUDIOINTERN_ALLPASSFILTER
#define CAMX_AUDIOINTERN_ALLPASSFILTER 1
#include "intern_audiofx.h"
#include "audiohardware.h"
#include "audiohardwarebuffer.h"
#include "camxfile.h"
#include "audioeffectparameter.h"
#include <cmath>
#define EQ_MAXDB 18 // +18db <-> -18dB
class audioobject_Intern_Allpass:public audioobject_Intern
{
public:
audioobject_Intern_Allpass()
{
internid=INTERNAUDIO_ID_ALLPASS;
ins=outs=MAXCHANNELSPERCHANNEL;
InitAllPass();
}
void InitSampleRateAndSize(int rate,int size)
{
Init();
}
bool InitIOChannels(int channels)
{
FreeMemory();
for(int i=0;i<channels;i++)
{
bufferstart[i] = new ARES[bufferLength];
bufferused[i]=true;
if(bufferstart[i])
bufferend[i] = bufferstart[i] + bufferLength;//set up pointers for delay line
}
ClearBuffer();
return true;
}
AudioObject *CloneEffect(int flag,Seq_Song *s)
{
audioobject_Intern_Allpass *clone=new audioobject_Intern_Allpass;
if(clone)
{
clone->delayTime=delayTime;
clone->feedbackGain=feedbackGain;
}
return clone;
}
AudioObject *InitOpenEffect(){return this;}
void InitAllPass()
{
numberofparameter=2;
delayTime=100; // ms
feedbackGain=0.2f;
for(int i=0;i<GetSetOutputPins();i++)
bufferstart[i]=0;
}
char *GetParmName(int index)
{
switch(index)
{
case 0:
return "delayTime";
case 1:
return "feedbackGain";
}
return 0;
}
void Delete(bool full)
{
//DeleteDefaultParms();
FreeMemory();
delete this;
}
void FreeMemory()
{
for(int i=0;i<GetSetOutputPins();i++)
{
if(bufferstart[i]){
delete bufferstart[i];
bufferstart[i]=0;
}
}
bufferok=false;
}
void Load(camxFile *file)
{
file->ReadChunk(&delayTime);
file->ReadChunk(&feedbackGain); // delayTime is in milliseconds
}
void Save(camxFile *file)
{
file->Save_Chunk(delayTime);
file->Save_Chunk(feedbackGain); // delayTime is in milliseconds
}
void ClearBuffer()
{
for(int i=0;i<GetSetOutputPins();i++)
{
if(bufferused[i]==true)
{
readPtr[i] = bufferstart[i];
if(bufferstart[i])
{
//zero out the buffer (silence)
do {
*readPtr[i] = 0;
}
while (++readPtr[i] < bufferend[i]);
}
bufferused[i]=false;
}
//reset read pointer to start of delayline
readPtr[i] = bufferstart[i];
}
}
void Init() //v
{
bufferLength = (int)(delayTime*(setSampleRate/1000));
}
char *GetEffectName(){return "AllPass";} //v
char *GetName(){return "AllPass";}
bool DoEffect(AudioEffectParameter *par,AudioObject *automation) // virtual
{
LockAudioObject();
if(bufferok==true)
{
ARES *input=par->in->outputbufferARES,*output=par->out->outputbufferARES;
int ins=GetSetInputPins();
for(int chl=0;chl<ins;chl++)
{
ARES temp;
for(int i=0; i<setSize; i++)
{
//for each sample...
temp = *readPtr[chl];
*readPtr[chl] = (feedbackGain * temp) + *input++;
*output++ = temp - (feedbackGain * *readPtr[chl]);
if(++readPtr[chl] >= bufferend[chl]) //if reach end of buffer, wrap
readPtr[chl] = bufferstart[chl];
}
bufferused[chl]=true;
}
UnlockAudioObject();
return true;
}
UnlockAudioObject();
return false;
}
//void InitEffectGUI(guiWindow *ed,int x,int y,int x2,int y2); // v
guiWindow *OpenGUI(Seq_Song *song,InsertAudioEffect *ieffect,guiWindowSetting *settings); //v
bool CloseGUI();
void Gadget(guiGadget *); //v
int GetEditorSizeX(){return 180;} //v
void ResetGadgets()
{
time=timestring=0;
feedback=feedbackstring=0;
}
protected:
void ShowTimeGadget();
void ShowFeedbackGadget();
bool bufferok;
int bufferLength;
guiGadget *time,*timestring,*feedback,*feedbackstring;
int delayTime; //ms
ARES feedbackGain;
ARES *bufferstart[MAXCHANNELSPERCHANNEL], *bufferend[MAXCHANNELSPERCHANNEL], *readPtr[MAXCHANNELSPERCHANNEL];
bool bufferused[MAXCHANNELSPERCHANNEL];
};
/*
class audioobject_Intern_Allpass_Stereo:public audioobject_Intern_Allpass
{
public:
audioobject_Intern_Allpass_Stereo()
{
internid=INTERNAUDIO_ID_ALLPASS_Stereo;
InitAllPass();
}
AudioObject *CloneEffect(int flag,Seq_Song *s)
{
audioobject_Intern_Allpass_Stereo *clone=new audioobject_Intern_Allpass_Stereo;
if(clone)
{
clone->delayTime=delayTime;
clone->feedbackGain=feedbackGain;
}
return clone;
}
AudioObject *CreateAudioObject(Seq_Song *song)
{
audioobject_Intern_Allpass_Stereo *apf=new audioobject_Intern_Allpass_Stereo;
if(apf)
{
apf->SetSampleRate(mainaudio->GetGlobalSampleRate());
}
return apf;
}
int GetInputs(){return 2;}
int GetOutputs(){return 2;}
char *GetEffectName(){return "AllPass [Stereo]";} //v
char *GetName(){return "AllPass [Stereo]";}
};
#endif
*/
/*
Allpass.h
Allpass.h - An allpass filter designed to build reverberators
Copyright (c) 1998, Scott Lehman, [email protected]
This code may be used and modified freely provided that credit
is given to the author in any public release. Any derivative
programs must be distributed freely and/or the modified source
code made publicly available. All code is provided AS IS and
without warranty of any kind.
class Allpass : public Processor {
public:
Allpass(float delay, float gain); //delay in milliseconds
void Initialize(void);
void Process(void);
void Cleanup(void);
~Allpass(){;}
private:
float delay, gain;
float * bufferStart, * bufferEnd, * readPtr;
float * inputSignal, * outputSignal;
int i, numSamples;
Allpass(Allpass&){};
};
Allpass.cpp
Allpass.cpp - An allpass filter designed to build reverberators
Copyright (c) 1998, Scott Lehman, [email protected]
This code may be used and modified freely provided that credit
is given to the author in any public release. Any derivative
programs must be distributed freely and/or the modified source
code made publicly available. All code is provided AS IS and
without warranty of any kind.
Allpass :: Allpass(float delayTime, float feedbackGain)
{
SetNumInputs(1);
SetNumOutputs(1);
gain = feedbackGain;
delay = delayTime; //delay time is in milliseconds
}
// *************** Initialize(void) ********************
void Allpass :: Initialize (void)
{
int bufferLength = int(delay*samplingRate/1000);
bufferStart = new float[bufferLength];
bufferEnd = bufferStart + bufferLength;
//zero out the buffer (create silence)
for(i=0; i<bufferLength; i++)
bufferStart[i] = 0.0;
//set read pointer to start of buffer
readPtr = bufferStart;
//assign pointers to the only input and output
inputSignal = inputs[0];
outputSignal = outputs[0];
return;
}
// **************** Process(void) ********************
void Allpass :: Process (void)
{
float temp;
for(i=0; i<frameLength; i++) { //for each sample...
temp = *readPtr;
*readPtr = gain * temp + inputSignal[i];
outputSignal[i] = temp - gain * *readPtr;
if(++readPtr >= bufferEnd) //if reach end of buffer, wrap
readPtr = bufferStart;
}
}
// ***************** Cleanup(void) ******************
void Allpass :: Cleanup (void)
{
delete [] bufferStart;
return;
}
*/
#endif