-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSFCEcho.cpp
More file actions
491 lines (436 loc) · 18.6 KB
/
SFCEcho.cpp
File metadata and controls
491 lines (436 loc) · 18.6 KB
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
/*
* File: SFCEcho.cpp
*
* Version: 1.0
*
* Created: 06/08/28
*
* Copyright: Copyright 2006 Vermicelli Magic, All Rights Reserved
*
*/
#include "SFCEcho.h"
#include <AudioToolbox/AudioToolbox.h>
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
COMPONENT_ENTRY(SFCEcho)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::SFCEcho
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SFCEcho::SFCEcho(AudioUnit component)
: AUEffectBase(component)
{
CreateElements();
Globals()->UseIndexedParameters(kNumberOfParameters);
SetParameter(kParam_mainvol_L, kDefaultValue_mainvol_L );
SetParameter(kParam_mainvol_R, kDefaultValue_mainvol_R );
SetParameter(kParam_echovol_L, kDefaultValue_echovol_L );
SetParameter(kParam_echovol_R, kDefaultValue_echovol_R );
SetParameter(kParam_echoFB, kDefaultValue_echoFB );
SetParameter(kParam_echodelay, kDefaultValue_echodelay );
SetParameter(kParam_fir0, kDefaultValue_fir0 );
SetParameter(kParam_fir1, kDefaultValue_fir1 );
SetParameter(kParam_fir2, kDefaultValue_fir2 );
SetParameter(kParam_fir3, kDefaultValue_fir3 );
SetParameter(kParam_fir4, kDefaultValue_fir4 );
SetParameter(kParam_fir5, kDefaultValue_fir5 );
SetParameter(kParam_fir6, kDefaultValue_fir6 );
SetParameter(kParam_fir7, kDefaultValue_fir7 );
for (int i=0; i<5; i++) {
mFilterBand[i] = 1.0f;
}
#if AU_DEBUG_DISPATCHER
mDebugDispatcher = new AUDebugDispatcher (this);
#endif
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::Initialize
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult SFCEcho::Initialize(void)
{
UInt32 in = GetInput(0)->GetStreamFormat().NumberChannels();
UInt32 out = GetOutput(0)->GetStreamFormat().NumberChannels();
if ((in != 2) || (out != 2)) {
return kAudioUnitErr_FormatNotSupported;
}
return AUEffectBase::Initialize();
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::SupportedNumChannels
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
UInt32 SFCEcho::SupportedNumChannels (const AUChannelInfo** outInfo)
{
static AUChannelInfo info[] = {{2, 2}};
if (outInfo) {
*outInfo = info;
}
return sizeof(info)/sizeof(*info);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::ChangeStreamFormat
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult SFCEcho::ChangeStreamFormat(AudioUnitScope iScope, AudioUnitElement iElem, const CAStreamBasicDescription& sOld, const CAStreamBasicDescription& sNew)
{
// const UInt32 iCha=sNew.NumberChannels();
if (sOld.NumberChannels()!=sNew.NumberChannels())
{
const UInt32 iCha=sNew.NumberChannels();
if ((iCha != 2) || (sNew.NumberInterleavedChannels()>1)) {
return kAudioUnitErr_FormatNotSupported;
}
}
return AUEffectBase::ChangeStreamFormat(iScope, iElem, sOld, sNew);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::GetParameterValueStrings
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult SFCEcho::GetParameterValueStrings(AudioUnitScope inScope,
AudioUnitParameterID inParameterID,
CFArrayRef * outStrings)
{
return kAudioUnitErr_InvalidProperty;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::GetParameterInfo
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult SFCEcho::GetParameterInfo(AudioUnitScope inScope,
AudioUnitParameterID inParameterID,
AudioUnitParameterInfo &outParameterInfo )
{
ComponentResult result = noErr;
outParameterInfo.flags = kAudioUnitParameterFlag_IsWritable
| kAudioUnitParameterFlag_IsReadable;
if (inScope == kAudioUnitScope_Global) {
switch(inParameterID)
{
case kParam_mainvol_L:
AUBase::FillInParameterName (outParameterInfo, kParameter_mainvol_L_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_mainvol_L;
break;
case kParam_mainvol_R:
AUBase::FillInParameterName (outParameterInfo, kParameter_mainvol_R_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_mainvol_R;
break;
case kParam_echovol_L:
AUBase::FillInParameterName (outParameterInfo, kParameter_echovol_L_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_echovol_L;
break;
case kParam_echovol_R:
AUBase::FillInParameterName (outParameterInfo, kParameter_echovol_R_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_echovol_R;
break;
case kParam_echoFB:
AUBase::FillInParameterName (outParameterInfo, kParameter_echoFB_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_echoFB;
break;
case kParam_echodelay:
AUBase::FillInParameterName (outParameterInfo, kParameter_echodelay_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_UInt4;
outParameterInfo.maxValue = kMaximumValue_UInt4;
outParameterInfo.defaultValue = kDefaultValue_echodelay;
break;
case kParam_fir0:
AUBase::FillInParameterName (outParameterInfo, kParameter_firC0_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_fir0;
break;
case kParam_fir1:
AUBase::FillInParameterName (outParameterInfo, kParameter_firC1_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_fir1;
break;
case kParam_fir2:
AUBase::FillInParameterName (outParameterInfo, kParameter_firC2_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_fir2;
break;
case kParam_fir3:
AUBase::FillInParameterName (outParameterInfo, kParameter_firC3_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_fir3;
break;
case kParam_fir4:
AUBase::FillInParameterName (outParameterInfo, kParameter_firC4_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_fir4;
break;
case kParam_fir5:
AUBase::FillInParameterName (outParameterInfo, kParameter_firC5_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_fir5;
break;
case kParam_fir6:
AUBase::FillInParameterName (outParameterInfo, kParameter_firC6_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_fir6;
break;
case kParam_fir7:
AUBase::FillInParameterName (outParameterInfo, kParameter_firC7_Name, false);
outParameterInfo.unit = kAudioUnitParameterUnit_Indexed;
outParameterInfo.minValue = kMinimumValue_SInt8;
outParameterInfo.maxValue = kMaximumValue_SInt8;
outParameterInfo.defaultValue = kDefaultValue_fir7;
break;
default:
result = kAudioUnitErr_InvalidParameter;
break;
}
} else {
result = kAudioUnitErr_InvalidParameter;
}
return result;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::GetPropertyInfo
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult SFCEcho::GetPropertyInfo (AudioUnitPropertyID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
UInt32 & outDataSize,
Boolean & outWritable)
{
if (inScope == kAudioUnitScope_Global) {
switch (inID) {
case kAudioUnitProperty_CocoaUI:
outWritable = false;
outDataSize = sizeof(AudioUnitCocoaViewInfo);
return noErr;
case kAudioUnitCustomProperty_Band1:
case kAudioUnitCustomProperty_Band2:
case kAudioUnitCustomProperty_Band3:
case kAudioUnitCustomProperty_Band4:
case kAudioUnitCustomProperty_Band5:
outWritable = false;
outDataSize = sizeof(Float32);
return noErr;
}
}
return AUEffectBase::GetPropertyInfo(inID, inScope, inElement, outDataSize, outWritable);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::GetProperty
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult SFCEcho::GetProperty( AudioUnitPropertyID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
void * outData )
{
if (inScope == kAudioUnitScope_Global) {
switch (inID) {
case kAudioUnitProperty_CocoaUI:
{
CFBundleRef bundle = CFBundleGetBundleWithIdentifier( CFSTR("com.VeMa.audiounit.SFCEcho") );
if (bundle == NULL) return fnfErr;
CFURLRef bundleURL = CFBundleCopyResourceURL( bundle,
CFSTR("SFCEcho_ViewFactory"),
CFSTR("bundle"),
NULL);
if (bundleURL == NULL) return fnfErr;
CFStringRef className = CFSTR("SFCEcho_ViewFactory");
AudioUnitCocoaViewInfo cocoaInfo = { bundleURL, className };
*((AudioUnitCocoaViewInfo *)outData) = cocoaInfo;
return noErr;
}
case kAudioUnitCustomProperty_Band1:
case kAudioUnitCustomProperty_Band2:
case kAudioUnitCustomProperty_Band3:
case kAudioUnitCustomProperty_Band4:
case kAudioUnitCustomProperty_Band5:
*((Float32 *)outData) = mFilterBand[inID-kAudioUnitCustomProperty_Band1];
return noErr;
}
}
return AUEffectBase::GetProperty(inID, inScope, inElement, outData);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::SetProperty
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult SFCEcho::SetProperty( AudioUnitPropertyID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
const void * inData,
UInt32 inDataSize)
{
float bandfactor[8][5] = {
{0.0625,0.125, 0.12500, 0.25, 0.4375},
{0.0625,0.11548, 0.08839, 0.04784, -0.314209},
{0.0625,0.08839, 0.00000, -0.21339, 0.0625},
{0.0625,0.04784, -0.08839, -0.11548, 0.093538},
{0.0625,0.00000, -0.12500, 0.125, -0.0625},
{0.0625,-0.04784, -0.08839, 0.11548, -0.041761},
{0.0625,-0.08839, 0.00000, -0.03661, 0.0625},
{0.0625,-0.11548, 0.08839, -0.04784, 0.012432}
};
float temp;
AudioUnitEvent auEvent;
if (inScope == kAudioUnitScope_Global) {
switch (inID) {
case kAudioUnitCustomProperty_Band1:
case kAudioUnitCustomProperty_Band2:
case kAudioUnitCustomProperty_Band3:
case kAudioUnitCustomProperty_Band4:
case kAudioUnitCustomProperty_Band5:
mFilterBand[inID-kAudioUnitCustomProperty_Band1] = *((Float32*)inData);
for (int j=0; j<8; j++) {
temp = 0;
for (int i=0; i<5; i++) {
temp += mFilterBand[i] * bandfactor[j][i];
}
if (temp < 0)
temp = ceil(temp*127);
else
temp = floor(temp*127);
SetParameter(kParam_fir0+j, temp);
auEvent.mEventType = kAudioUnitEvent_ParameterValueChange;
auEvent.mArgument.mParameter.mAudioUnit = (AudioUnit)GetComponentInstance();
auEvent.mArgument.mParameter.mScope = kAudioUnitScope_Global;
auEvent.mArgument.mParameter.mParameterID = kParam_fir0+j;
auEvent.mArgument.mParameter.mElement = 0;
AUEventListenerNotify(NULL, NULL, &auEvent);
}
return noErr;
}
}
return AUEffectBase::SetProperty(inID, inScope, inElement, inData, inDataSize);
}
#pragma mark ____SFCEchoEffectKernel
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::SFCEchoKernel::Reset()
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void SFCEcho::SFCEchoKernel::Reset()
{
mEchoBuffer.Clear();
mFIRbuf.Clear();
mEchoIndex=0;
mFIRIndex=0;
mPrevFilterDigest=0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SFCEcho::SFCEchoKernel::Process
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void SFCEcho::SFCEchoKernel::Process( const Float32 *inSourceP,
Float32 *inDestP,
UInt32 inFramesToProcess,
UInt32 inNumChannels, //inNumChannelには1しかこない
bool &ioSilence )
{
UInt32 nSampleFrames = inFramesToProcess;
const Float32 *sourceP = inSourceP;
Float32 *destP = inDestP;
Float32 gain=0.0,echo_vol=0.0,fb_lev,fir_taps[8];
int i, delay_samples, filter_digest=0;
//パラメータの読み込み
if (GetChannelNum() == 0) { //Lチャンネル
gain = GetParameter( kParam_mainvol_L ) / 128.0;
echo_vol = GetParameter( kParam_echovol_L ) / 128.0;
}
else if (GetChannelNum() == 1) { //Rチャンネル
gain = GetParameter( kParam_mainvol_R ) / 128.0;
echo_vol = GetParameter( kParam_echovol_R ) / 128.0;
}
fb_lev = GetParameter( kParam_echoFB ) / 128.0;
delay_samples = GetParameter( kParam_echodelay ) * mDelayUnit;
if (delay_samples < 0) delay_samples=0;
for (i=0; i<8; i++) {
fir_taps[i] = GetParameter( kParam_fir0+i ) / 128.0;
filter_digest ^= (int)(fir_taps[i]*128);
}
if (filter_digest != mPrevFilterDigest) {
setWeights(fir_taps);
}
mPrevFilterDigest = filter_digest;
while (nSampleFrames-- > 0) {
Float32 input = *sourceP;
sourceP += inNumChannels;
Float32 output,temp,echo;
UInt32 echoabs;
echo = input;
output = input * gain;
mEchoIndex &= 0x7fff;
//ディレイ信号にFIRフィルタを掛けてから出力に加算する
mFIRbuf[mFIRIndex] = mEchoBuffer[mEchoIndex];
temp =0;
for (i=0; i<mFIRLength-1; i++) {
temp += mFIRbuf[mFIRIndex] * mFIRweights[i];
mFIRIndex = (mFIRIndex + 1)%mFIRLength;
}
temp += mFIRbuf[mFIRIndex] * mFIRweights[i];
//mFIRbufへの書き込みは、右から左へと行われる
output += temp*echo_vol;
//入力にフィードバックを加算したものをバッファキューに入れる
echo += temp*fb_lev;
echoabs = (*(int*)&echo)&0x7fffffff;
if (*(float*)&echoabs < 1.0/32768.0)
echo = 0;
mEchoBuffer[mEchoIndex++] = echo;
if (mEchoIndex >= delay_samples)
mEchoIndex=0;
*destP = output;
destP += inNumChannels;
}
}
const float onepi = 3.14159265358979;
void SFCEcho::SFCEchoKernel::setWeights(Float32 *paramtaps)
{
Float32 temp,pos,pix,flat=0;
int i,min,max;
if (paramtaps[0] == 127.0/128.0) {
for (i=1; i<8; i++) {
flat += paramtaps[i];
}
if (flat == 0) {
mFIRweights[0] = 1.0;
for (i=1; i<mFIRLength; i++) {
mFIRweights[i] = 0;
}
return;
}
}
for (i=0; i<mFIRLength; i++) {
pos=(i-mFIRLength/2)*mFilterStride;
temp=0;
min=pos+0.5;
max=min+8;
min-=8;
for (int j=min; j<max; j++) {
pix=(pos-j)*onepi;
if (j>=0 && j<8) {
if (pix == .0)
temp+=paramtaps[j];
else
temp+=paramtaps[j]*sinf(pix)/pix;
}
}
//temp*=0.5-0.5*cosf((2.0*onepi*i)/mFIRLength);
temp*=expf(-4.5*((2*i-mFIRLength)/(float)mFIRLength)*((2*i-mFIRLength)/(float)mFIRLength));
mFIRweights[i]=temp;
}
}