aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/MacAU/MV/MV.cpp
blob: 25c62b28941fb7c2a618cac4cc0fc93f1b1f7946 (plain) (blame)
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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
/*
*	File:		MV.cpp
*	
*	Version:	1.0
* 
*	Created:	2/14/19
*	
*	Copyright:  Copyright � 2019 Airwindows, All Rights Reserved
* 
*	Disclaimer:	IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in 
*				consideration of your agreement to the following terms, and your use, installation, modification 
*				or redistribution of this Apple software constitutes acceptance of these terms.  If you do 
*				not agree with these terms, please do not use, install, modify or redistribute this Apple 
*				software.
*
*				In consideration of your agreement to abide by the following terms, and subject to these terms, 
*				Apple grants you a personal, non-exclusive license, under Apple's copyrights in this 
*				original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the 
*				Apple Software, with or without modifications, in source and/or binary forms; provided that if you 
*				redistribute the Apple Software in its entirety and without modifications, you must retain this 
*				notice and the following text and disclaimers in all such redistributions of the Apple Software. 
*				Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to 
*				endorse or promote products derived from the Apple Software without specific prior written 
*				permission from Apple.  Except as expressly stated in this notice, no other rights or 
*				licenses, express or implied, are granted by Apple herein, including but not limited to any 
*				patent rights that may be infringed by your derivative works or by other works in which the 
*				Apple Software may be incorporated.
*
*				The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO WARRANTIES, EXPRESS OR 
*				IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY 
*				AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE 
*				OR IN COMBINATION WITH YOUR PRODUCTS.
*
*				IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL 
*				DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 
*				OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, 
*				REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER 
*				UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN 
*				IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*=============================================================================
	MV.cpp
	
=============================================================================*/
#include "MV.h"


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

COMPONENT_ENTRY(MV)


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	MV::MV
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MV::MV(AudioUnit component)
	: AUEffectBase(component)
{
	CreateElements();
	Globals()->UseIndexedParameters(kNumberOfParameters);
	SetParameter(kParam_One, kDefaultValue_ParamOne );
	SetParameter(kParam_Two, kDefaultValue_ParamTwo );
	SetParameter(kParam_Three, kDefaultValue_ParamThree );
	SetParameter(kParam_Four, kDefaultValue_ParamFour );
	SetParameter(kParam_Five, kDefaultValue_ParamFive );
         
#if AU_DEBUG_DISPATCHER
	mDebugDispatcher = new AUDebugDispatcher (this);
#endif
	
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	MV::GetParameterValueStrings
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult			MV::GetParameterValueStrings(AudioUnitScope		inScope,
                                                                AudioUnitParameterID	inParameterID,
                                                                CFArrayRef *		outStrings)
{
        
    return kAudioUnitErr_InvalidProperty;
}



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	MV::GetParameterInfo
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult			MV::GetParameterInfo(AudioUnitScope		inScope,
                                                        AudioUnitParameterID	inParameterID,
                                                        AudioUnitParameterInfo	&outParameterInfo )
{
	ComponentResult result = noErr;

	outParameterInfo.flags = 	kAudioUnitParameterFlag_IsWritable
						|		kAudioUnitParameterFlag_IsReadable;
    
    if (inScope == kAudioUnitScope_Global) {
        switch(inParameterID)
        {
           case kParam_One:
                AUBase::FillInParameterName (outParameterInfo, kParameterOneName, false);
                outParameterInfo.unit = kAudioUnitParameterUnit_Generic;
                outParameterInfo.minValue = 0.0;
                outParameterInfo.maxValue = 1.0;
                outParameterInfo.defaultValue = kDefaultValue_ParamOne;
                break;
            case kParam_Two:
                AUBase::FillInParameterName (outParameterInfo, kParameterTwoName, false);
                outParameterInfo.unit = kAudioUnitParameterUnit_Generic;
                outParameterInfo.minValue = 0.0;
                outParameterInfo.maxValue = 1.0;
                outParameterInfo.defaultValue = kDefaultValue_ParamTwo;
                break;
            case kParam_Three:
                AUBase::FillInParameterName (outParameterInfo, kParameterThreeName, false);
                outParameterInfo.unit = kAudioUnitParameterUnit_Generic;
                outParameterInfo.minValue = 0.0;
                outParameterInfo.maxValue = 1.0;
                outParameterInfo.defaultValue = kDefaultValue_ParamThree;
                break;
           case kParam_Four:
                AUBase::FillInParameterName (outParameterInfo, kParameterFourName, false);
                outParameterInfo.unit = kAudioUnitParameterUnit_Generic;
                outParameterInfo.minValue = 0.0;
                outParameterInfo.maxValue = 1.0;
                outParameterInfo.defaultValue = kDefaultValue_ParamFour;
                break;
           case kParam_Five:
                AUBase::FillInParameterName (outParameterInfo, kParameterFiveName, false);
                outParameterInfo.unit = kAudioUnitParameterUnit_Generic;
                outParameterInfo.minValue = 0.0;
                outParameterInfo.maxValue = 1.0;
                outParameterInfo.defaultValue = kDefaultValue_ParamFive;
                break;
           default:
                result = kAudioUnitErr_InvalidParameter;
                break;
            }
	} else {
        result = kAudioUnitErr_InvalidParameter;
    }
    


	return result;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	MV::GetPropertyInfo
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult			MV::GetPropertyInfo (AudioUnitPropertyID	inID,
                                                        AudioUnitScope		inScope,
                                                        AudioUnitElement	inElement,
                                                        UInt32 &		outDataSize,
                                                        Boolean &		outWritable)
{
	return AUEffectBase::GetPropertyInfo (inID, inScope, inElement, outDataSize, outWritable);
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	MV::GetProperty
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult			MV::GetProperty(	AudioUnitPropertyID inID,
                                                        AudioUnitScope 		inScope,
                                                        AudioUnitElement 	inElement,
                                                        void *			outData )
{
	return AUEffectBase::GetProperty (inID, inScope, inElement, outData);
}

//	MV::Initialize
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ComponentResult MV::Initialize()
{
    ComponentResult result = AUEffectBase::Initialize();
    if (result == noErr)
        Reset(kAudioUnitScope_Global, 0);
    return result;
}

#pragma mark ____MVEffectKernel



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	MV::MVKernel::Reset()
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void		MV::MVKernel::Reset()
{
	int count;
	for(count = 0; count < 15149; count++) {aA[count] = 0.0;}
	for(count = 0; count < 14617; count++) {aB[count] = 0.0;}
	for(count = 0; count < 14357; count++) {aC[count] = 0.0;}
	for(count = 0; count < 13817; count++) {aD[count] = 0.0;}
	for(count = 0; count < 13561; count++) {aE[count] = 0.0;}
	for(count = 0; count < 13045; count++) {aF[count] = 0.0;}
	for(count = 0; count < 11965; count++) {aG[count] = 0.0;}
	for(count = 0; count < 11129; count++) {aH[count] = 0.0;}
	for(count = 0; count < 10597; count++) {aI[count] = 0.0;}
	for(count = 0; count < 9809; count++) {aJ[count] = 0.0;}
	for(count = 0; count < 9521; count++) {aK[count] = 0.0;}
	for(count = 0; count < 8981; count++) {aL[count] = 0.0;}
	for(count = 0; count < 8785; count++) {aM[count] = 0.0;}
	for(count = 0; count < 8461; count++) {aN[count] = 0.0;}
	for(count = 0; count < 8309; count++) {aO[count] = 0.0;}
	for(count = 0; count < 7981; count++) {aP[count] = 0.0;}
	for(count = 0; count < 7321; count++) {aQ[count] = 0.0;}
	for(count = 0; count < 6817; count++) {aR[count] = 0.0;}
	for(count = 0; count < 6505; count++) {aS[count] = 0.0;}
	for(count = 0; count < 6001; count++) {aT[count] = 0.0;}
	for(count = 0; count < 5837; count++) {aU[count] = 0.0;}
	for(count = 0; count < 5501; count++) {aV[count] = 0.0;}
	for(count = 0; count < 5009; count++) {aW[count] = 0.0;}
	for(count = 0; count < 4849; count++) {aX[count] = 0.0;}
	for(count = 0; count < 4295; count++) {aY[count] = 0.0;}
	for(count = 0; count < 4179; count++) {aZ[count] = 0.0;}	
	
	alpA = 1; delayA = 7573; avgA = 0.0;
	alpB = 1; delayB = 7307; avgB = 0.0;
	alpC = 1; delayC = 7177; avgC = 0.0;
	alpD = 1; delayD = 6907; avgD = 0.0;
	alpE = 1; delayE = 6779; avgE = 0.0;
	alpF = 1; delayF = 6521; avgF = 0.0;
	alpG = 1; delayG = 5981; avgG = 0.0;
	alpH = 1; delayH = 5563; avgH = 0.0;
	alpI = 1; delayI = 5297; avgI = 0.0;
	alpJ = 1; delayJ = 4903; avgJ = 0.0;
	alpK = 1; delayK = 4759; avgK = 0.0;
	alpL = 1; delayL = 4489; avgL = 0.0;
	alpM = 1; delayM = 4391; avgM = 0.0;
	alpN = 1; delayN = 4229; avgN = 0.0;
	alpO = 1; delayO = 4153; avgO = 0.0;
	alpP = 1; delayP = 3989; avgP = 0.0;
	alpQ = 1; delayQ = 3659; avgQ = 0.0;
	alpR = 1; delayR = 3407; avgR = 0.0;
	alpS = 1; delayS = 3251; avgS = 0.0;
	alpT = 1; delayT = 2999; avgT = 0.0;
	alpU = 1; delayU = 2917; avgU = 0.0;
	alpV = 1; delayV = 2749; avgV = 0.0;
	alpW = 1; delayW = 2503; avgW = 0.0;
	alpX = 1; delayX = 2423; avgX = 0.0;
	alpY = 1; delayY = 2146; avgY = 0.0;
	alpZ = 1; delayZ = 2088; avgZ = 0.0;
	
	feedback = 0.0;
	
	fpd = 17;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	MV::MVKernel::Process
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void		MV::MVKernel::Process(	const Float32 	*inSourceP,
                                                    Float32		 	*inDestP,
                                                    UInt32 			inFramesToProcess,
                                                    UInt32			inNumChannels, 
                                                    bool			&ioSilence )
{
	UInt32 nSampleFrames = inFramesToProcess;
	const Float32 *sourceP = inSourceP;
	Float32 *destP = inDestP;	
	int allpasstemp;
	Float64 avgtemp;
	int stage = GetParameter( kParam_One ) * 27.0;
	int damp = (1.0-GetParameter( kParam_Two )) * stage;
	Float64 feedbacklevel = GetParameter( kParam_Three );
	if (feedbacklevel <= 0.0625) feedbacklevel = 0.0;
	if (feedbacklevel > 0.0625 && feedbacklevel <= 0.125) feedbacklevel = 0.0625; //-24db
	if (feedbacklevel > 0.125 && feedbacklevel <= 0.25) feedbacklevel = 0.125; //-18db
	if (feedbacklevel > 0.25 && feedbacklevel <= 0.5) feedbacklevel = 0.25; //-12db
	if (feedbacklevel > 0.5 && feedbacklevel <= 0.99) feedbacklevel = 0.5; //-6db
	if (feedbacklevel > 0.99) feedbacklevel = 1.0;
	//we're forcing even the feedback level to be Midiverb-ized
	Float64 gain = GetParameter( kParam_Four );
	Float64 wet = GetParameter( kParam_Five );
	
	while (nSampleFrames-- > 0) {
		long double inputSample = *sourceP;

		static int noisesource = 0;
		int residue;
		double applyresidue;
		noisesource = noisesource % 1700021; noisesource++;
		residue = noisesource * noisesource;
		residue = residue % 170003; residue *= residue;
		residue = residue % 17011; residue *= residue;
		residue = residue % 1709; residue *= residue;
		residue = residue % 173; residue *= residue;
		residue = residue % 17;
		applyresidue = residue;
		applyresidue *= 0.00000001;
		applyresidue *= 0.00000001;
		inputSample += applyresidue;
		if (inputSample<1.2e-38 && -inputSample<1.2e-38) {
			inputSample -= applyresidue;
		}
		//for live air, we always apply the dither noise. Then, if our result is 
		//effectively digital black, we'll subtract it again. We want a 'air' hiss
		double drySample = inputSample;
		
		inputSample += feedback;
		
		inputSample = sin(inputSample);

		
		switch (stage){
			case 27:
			case 26:
				allpasstemp = alpA - 1;
				if (allpasstemp < 0 || allpasstemp > delayA) {allpasstemp = delayA;}
				inputSample -= aA[allpasstemp]*0.5;
				aA[alpA] = inputSample;
				inputSample *= 0.5;
				alpA--; if (alpA < 0 || alpA > delayA) {alpA = delayA;}
				inputSample += (aA[alpA]);
				if (damp > 26) {
				avgtemp = inputSample;
				inputSample += avgA;
				inputSample *= 0.5;
				avgA = avgtemp;
				}
				//allpass filter A		
			case 25:
				allpasstemp = alpB - 1;
				if (allpasstemp < 0 || allpasstemp > delayB) {allpasstemp = delayB;}
				inputSample -= aB[allpasstemp]*0.5;
				aB[alpB] = inputSample;
				inputSample *= 0.5;
				alpB--; if (alpB < 0 || alpB > delayB) {alpB = delayB;}
				inputSample += (aB[alpB]);
				if (damp > 25) {
				avgtemp = inputSample;
				inputSample += avgB;
				inputSample *= 0.5;
				avgB = avgtemp;
				}
				//allpass filter B
			case 24:
				allpasstemp = alpC - 1;
				if (allpasstemp < 0 || allpasstemp > delayC) {allpasstemp = delayC;}
				inputSample -= aC[allpasstemp]*0.5;
				aC[alpC] = inputSample;
				inputSample *= 0.5;
				alpC--; if (alpC < 0 || alpC > delayC) {alpC = delayC;}
				inputSample += (aC[alpC]);
				if (damp > 24) {
				avgtemp = inputSample;
				inputSample += avgC;
				inputSample *= 0.5;
				avgC = avgtemp;
				}
				//allpass filter C
			case 23:
				allpasstemp = alpD - 1;
				if (allpasstemp < 0 || allpasstemp > delayD) {allpasstemp = delayD;}
				inputSample -= aD[allpasstemp]*0.5;
				aD[alpD] = inputSample;
				inputSample *= 0.5;
				alpD--; if (alpD < 0 || alpD > delayD) {alpD = delayD;}
				inputSample += (aD[alpD]);
				if (damp > 23) {
				avgtemp = inputSample;
				inputSample += avgD;
				inputSample *= 0.5;
				avgD = avgtemp;
				}
				//allpass filter D
			case 22:
				allpasstemp = alpE - 1;
				if (allpasstemp < 0 || allpasstemp > delayE) {allpasstemp = delayE;}
				inputSample -= aE[allpasstemp]*0.5;
				aE[alpE] = inputSample;
				inputSample *= 0.5;
				alpE--; if (alpE < 0 || alpE > delayE) {alpE = delayE;}
				inputSample += (aE[alpE]);
				if (damp > 22) {
				avgtemp = inputSample;
				inputSample += avgE;
				inputSample *= 0.5;
				avgE = avgtemp;
				}
				//allpass filter E
			case 21:
				allpasstemp = alpF - 1;
				if (allpasstemp < 0 || allpasstemp > delayF) {allpasstemp = delayF;}
				inputSample -= aF[allpasstemp]*0.5;
				aF[alpF] = inputSample;
				inputSample *= 0.5;
				alpF--; if (alpF < 0 || alpF > delayF) {alpF = delayF;}
				inputSample += (aF[alpF]);
				if (damp > 21) {
				avgtemp = inputSample;
				inputSample += avgF;
				inputSample *= 0.5;
				avgF = avgtemp;
				}
				//allpass filter F
			case 20:
				allpasstemp = alpG - 1;
				if (allpasstemp < 0 || allpasstemp > delayG) {allpasstemp = delayG;}
				inputSample -= aG[allpasstemp]*0.5;
				aG[alpG] = inputSample;
				inputSample *= 0.5;
				alpG--; if (alpG < 0 || alpG > delayG) {alpG = delayG;}
				inputSample += (aG[alpG]);
				if (damp > 20) {
				avgtemp = inputSample;
				inputSample += avgG;
				inputSample *= 0.5;
				avgG = avgtemp;
				}
				//allpass filter G
			case 19:
				allpasstemp = alpH - 1;
				if (allpasstemp < 0 || allpasstemp > delayH) {allpasstemp = delayH;}
				inputSample -= aH[allpasstemp]*0.5;
				aH[alpH] = inputSample;
				inputSample *= 0.5;
				alpH--; if (alpH < 0 || alpH > delayH) {alpH = delayH;}
				inputSample += (aH[alpH]);
				if (damp > 19) {
				avgtemp = inputSample;
				inputSample += avgH;
				inputSample *= 0.5;
				avgH = avgtemp;
				}
				//allpass filter H
			case 18:
				allpasstemp = alpI - 1;
				if (allpasstemp < 0 || allpasstemp > delayI) {allpasstemp = delayI;}
				inputSample -= aI[allpasstemp]*0.5;
				aI[alpI] = inputSample;
				inputSample *= 0.5;
				alpI--; if (alpI < 0 || alpI > delayI) {alpI = delayI;}
				inputSample += (aI[alpI]);
				if (damp > 18) {
				avgtemp = inputSample;
				inputSample += avgI;
				inputSample *= 0.5;
				avgI = avgtemp;
				}
				//allpass filter I
			case 17:
				allpasstemp = alpJ - 1;
				if (allpasstemp < 0 || allpasstemp > delayJ) {allpasstemp = delayJ;}
				inputSample -= aJ[allpasstemp]*0.5;
				aJ[alpJ] = inputSample;
				inputSample *= 0.5;
				alpJ--; if (alpJ < 0 || alpJ > delayJ) {alpJ = delayJ;}
				inputSample += (aJ[alpJ]);
				if (damp > 17) {
				avgtemp = inputSample;
				inputSample += avgJ;
				inputSample *= 0.5;
				avgJ = avgtemp;
				}
				//allpass filter J
			case 16:
				allpasstemp = alpK - 1;
				if (allpasstemp < 0 || allpasstemp > delayK) {allpasstemp = delayK;}
				inputSample -= aK[allpasstemp]*0.5;
				aK[alpK] = inputSample;
				inputSample *= 0.5;
				alpK--; if (alpK < 0 || alpK > delayK) {alpK = delayK;}
				inputSample += (aK[alpK]);
				if (damp > 16) {
				avgtemp = inputSample;
				inputSample += avgK;
				inputSample *= 0.5;
				avgK = avgtemp;
				}
				//allpass filter K
			case 15:
				allpasstemp = alpL - 1;
				if (allpasstemp < 0 || allpasstemp > delayL) {allpasstemp = delayL;}
				inputSample -= aL[allpasstemp]*0.5;
				aL[alpL] = inputSample;
				inputSample *= 0.5;
				alpL--; if (alpL < 0 || alpL > delayL) {alpL = delayL;}
				inputSample += (aL[alpL]);
				if (damp > 15) {
				avgtemp = inputSample;
				inputSample += avgL;
				inputSample *= 0.5;
				avgL = avgtemp;
				}
				//allpass filter L
			case 14:
				allpasstemp = alpM - 1;
				if (allpasstemp < 0 || allpasstemp > delayM) {allpasstemp = delayM;}
				inputSample -= aM[allpasstemp]*0.5;
				aM[alpM] = inputSample;
				inputSample *= 0.5;
				alpM--; if (alpM < 0 || alpM > delayM) {alpM = delayM;}
				inputSample += (aM[alpM]);
				if (damp > 14) {
				avgtemp = inputSample;
				inputSample += avgM;
				inputSample *= 0.5;
				avgM = avgtemp;
				}
				//allpass filter M
			case 13:
				allpasstemp = alpN - 1;
				if (allpasstemp < 0 || allpasstemp > delayN) {allpasstemp = delayN;}
				inputSample -= aN[allpasstemp]*0.5;
				aN[alpN] = inputSample;
				inputSample *= 0.5;
				alpN--; if (alpN < 0 || alpN > delayN) {alpN = delayN;}
				inputSample += (aN[alpN]);
				if (damp > 13) {
				avgtemp = inputSample;
				inputSample += avgN;
				inputSample *= 0.5;
				avgN = avgtemp;
				}
				//allpass filter N
			case 12:
				allpasstemp = alpO - 1;
				if (allpasstemp < 0 || allpasstemp > delayO) {allpasstemp = delayO;}
				inputSample -= aO[allpasstemp]*0.5;
				aO[alpO] = inputSample;
				inputSample *= 0.5;
				alpO--; if (alpO < 0 || alpO > delayO) {alpO = delayO;}
				inputSample += (aO[alpO]);
				if (damp > 12) {
				avgtemp = inputSample;
				inputSample += avgO;
				inputSample *= 0.5;
				avgO = avgtemp;
				}
				//allpass filter O
			case 11:
				allpasstemp = alpP - 1;
				if (allpasstemp < 0 || allpasstemp > delayP) {allpasstemp = delayP;}
				inputSample -= aP[allpasstemp]*0.5;
				aP[alpP] = inputSample;
				inputSample *= 0.5;
				alpP--; if (alpP < 0 || alpP > delayP) {alpP = delayP;}
				inputSample += (aP[alpP]);
				if (damp > 11) {
				avgtemp = inputSample;
				inputSample += avgP;
				inputSample *= 0.5;
				avgP = avgtemp;
				}
				//allpass filter P
			case 10:
				allpasstemp = alpQ - 1;
				if (allpasstemp < 0 || allpasstemp > delayQ) {allpasstemp = delayQ;}
				inputSample -= aQ[allpasstemp]*0.5;
				aQ[alpQ] = inputSample;
				inputSample *= 0.5;
				alpQ--; if (alpQ < 0 || alpQ > delayQ) {alpQ = delayQ;}
				inputSample += (aQ[alpQ]);
				if (damp > 10) {
				avgtemp = inputSample;
				inputSample += avgQ;
				inputSample *= 0.5;
				avgQ = avgtemp;
				}
				//allpass filter Q
			case 9:
				allpasstemp = alpR - 1;
				if (allpasstemp < 0 || allpasstemp > delayR) {allpasstemp = delayR;}
				inputSample -= aR[allpasstemp]*0.5;
				aR[alpR] = inputSample;
				inputSample *= 0.5;
				alpR--; if (alpR < 0 || alpR > delayR) {alpR = delayR;}
				inputSample += (aR[alpR]);
				if (damp > 9) {
				avgtemp = inputSample;
				inputSample += avgR;
				inputSample *= 0.5;
				avgR = avgtemp;
				}
				//allpass filter R
			case 8:
				allpasstemp = alpS - 1;
				if (allpasstemp < 0 || allpasstemp > delayS) {allpasstemp = delayS;}
				inputSample -= aS[allpasstemp]*0.5;
				aS[alpS] = inputSample;
				inputSample *= 0.5;
				alpS--; if (alpS < 0 || alpS > delayS) {alpS = delayS;}
				inputSample += (aS[alpS]);
				if (damp > 8) {
				avgtemp = inputSample;
				inputSample += avgS;
				inputSample *= 0.5;
				avgS = avgtemp;
				}
				//allpass filter S
			case 7:
				allpasstemp = alpT - 1;
				if (allpasstemp < 0 || allpasstemp > delayT) {allpasstemp = delayT;}
				inputSample -= aT[allpasstemp]*0.5;
				aT[alpT] = inputSample;
				inputSample *= 0.5;
				alpT--; if (alpT < 0 || alpT > delayT) {alpT = delayT;}
				inputSample += (aT[alpT]);
				if (damp > 7) {
				avgtemp = inputSample;
				inputSample += avgT;
				inputSample *= 0.5;
				avgT = avgtemp;
				}
				//allpass filter T
			case 6:
				allpasstemp = alpU - 1;
				if (allpasstemp < 0 || allpasstemp > delayU) {allpasstemp = delayU;}
				inputSample -= aU[allpasstemp]*0.5;
				aU[alpU] = inputSample;
				inputSample *= 0.5;
				alpU--; if (alpU < 0 || alpU > delayU) {alpU = delayU;}
				inputSample += (aU[alpU]);
				if (damp > 6) {
				avgtemp = inputSample;
				inputSample += avgU;
				inputSample *= 0.5;
				avgU = avgtemp;
				}
				//allpass filter U
			case 5:
				allpasstemp = alpV - 1;
				if (allpasstemp < 0 || allpasstemp > delayV) {allpasstemp = delayV;}
				inputSample -= aV[allpasstemp]*0.5;
				aV[alpV] = inputSample;
				inputSample *= 0.5;
				alpV--; if (alpV < 0 || alpV > delayV) {alpV = delayV;}
				inputSample += (aV[alpV]);
				if (damp > 5) {
				avgtemp = inputSample;
				inputSample += avgV;
				inputSample *= 0.5;
				avgV = avgtemp;
				}
				//allpass filter V
			case 4:
				allpasstemp = alpW - 1;
				if (allpasstemp < 0 || allpasstemp > delayW) {allpasstemp = delayW;}
				inputSample -= aW[allpasstemp]*0.5;
				aW[alpW] = inputSample;
				inputSample *= 0.5;
				alpW--; if (alpW < 0 || alpW > delayW) {alpW = delayW;}
				inputSample += (aW[alpW]);
				if (damp > 4) {
				avgtemp = inputSample;
				inputSample += avgW;
				inputSample *= 0.5;
				avgW = avgtemp;
				}
				//allpass filter W
			case 3:
				allpasstemp = alpX - 1;
				if (allpasstemp < 0 || allpasstemp > delayX) {allpasstemp = delayX;}
				inputSample -= aX[allpasstemp]*0.5;
				aX[alpX] = inputSample;
				inputSample *= 0.5;
				alpX--; if (alpX < 0 || alpX > delayX) {alpX = delayX;}
				inputSample += (aX[alpX]);
				if (damp > 3) {
				avgtemp = inputSample;
				inputSample += avgX;
				inputSample *= 0.5;
				avgX = avgtemp;
				}
				//allpass filter X
			case 2:
				allpasstemp = alpY - 1;
				if (allpasstemp < 0 || allpasstemp > delayY) {allpasstemp = delayY;}
				inputSample -= aY[allpasstemp]*0.5;
				aY[alpY] = inputSample;
				inputSample *= 0.5;
				alpY--; if (alpY < 0 || alpY > delayY) {alpY = delayY;}
				inputSample += (aY[alpY]);
				if (damp > 2) {
				avgtemp = inputSample;
				inputSample += avgY;
				inputSample *= 0.5;
				avgY = avgtemp;
				}
				//allpass filter Y
			case 1:
				allpasstemp = alpZ - 1;
				if (allpasstemp < 0 || allpasstemp > delayZ) {allpasstemp = delayZ;}
				inputSample -= aZ[allpasstemp]*0.5;
				aZ[alpZ] = inputSample;
				inputSample *= 0.5;
				alpZ--; if (alpZ < 0 || alpZ > delayZ) {alpZ = delayZ;}
				inputSample += (aZ[alpZ]);
				if (damp > 1) {
				avgtemp = inputSample;
				inputSample += avgZ;
				inputSample *= 0.5;
				avgZ = avgtemp;
				}
				//allpass filter Z
		}
		
		feedback = inputSample * feedbacklevel;
				
		if (gain != 1.0) {
			inputSample *= gain;
		}
		//we can pad with the gain to tame distortyness from the PurestConsole code
		
		if (inputSample > 1.0) inputSample = 1.0;
		if (inputSample < -1.0) inputSample = -1.0;
		//without this, you can get a NaN condition where it spits out DC offset at full blast!
		
		inputSample = asin(inputSample);
		
		
		if (wet !=1.0) {
			inputSample = (inputSample * wet) + (drySample * (1.0-wet));
		}
		//Dry/Wet control, defaults to the last slider

		//begin 32 bit floating point dither
		int expon; frexpf((float)inputSample, &expon);
		fpd ^= fpd << 13; fpd ^= fpd >> 17; fpd ^= fpd << 5;
		inputSample += static_cast<int32_t>(fpd) * 5.960464655174751e-36L * pow(2,expon+62);
		//end 32 bit floating point dither
		
		*destP = inputSample;
		
		sourceP += inNumChannels; destP += inNumChannels;
	}
}