mirror of
https://github.com/airwindows/airwindows.git
synced 2026-05-15 14:16:00 -06:00
552 lines
26 KiB
C++
Executable file
552 lines
26 KiB
C++
Executable file
/*
|
|
* File: ConsoleXSubOut.cpp
|
|
*
|
|
* Version: 1.0
|
|
*
|
|
* Created: 3/8/24
|
|
*
|
|
* Copyright: Copyright © 2024 Airwindows, Airwindows uses the MIT license
|
|
*
|
|
* 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.
|
|
*
|
|
*/
|
|
/*=============================================================================
|
|
ConsoleXSubOut.cpp
|
|
|
|
=============================================================================*/
|
|
#include "ConsoleXSubOut.h"
|
|
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
AUDIOCOMPONENT_ENTRY(AUBaseFactory, ConsoleXSubOut)
|
|
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// ConsoleXSubOut::ConsoleXSubOut
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
ConsoleXSubOut::ConsoleXSubOut(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 );
|
|
SetParameter(kParam_Six, kDefaultValue_ParamSix );
|
|
SetParameter(kParam_Seven, kDefaultValue_ParamSeven );
|
|
SetParameter(kParam_Eight, kDefaultValue_ParamEight );
|
|
|
|
#if AU_DEBUG_DISPATCHER
|
|
mDebugDispatcher = new AUDebugDispatcher (this);
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// ConsoleXSubOut::GetParameterValueStrings
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
ComponentResult ConsoleXSubOut::GetParameterValueStrings(AudioUnitScope inScope,
|
|
AudioUnitParameterID inParameterID,
|
|
CFArrayRef * outStrings)
|
|
{
|
|
|
|
return kAudioUnitErr_InvalidProperty;
|
|
}
|
|
|
|
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// ConsoleXSubOut::GetParameterInfo
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
ComponentResult ConsoleXSubOut::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;
|
|
case kParam_Six:
|
|
AUBase::FillInParameterName (outParameterInfo, kParameterSixName, false);
|
|
outParameterInfo.unit = kAudioUnitParameterUnit_Generic;
|
|
outParameterInfo.minValue = 70.0;
|
|
outParameterInfo.maxValue = 140.0;
|
|
outParameterInfo.defaultValue = kDefaultValue_ParamSix;
|
|
break;
|
|
case kParam_Seven:
|
|
AUBase::FillInParameterName (outParameterInfo, kParameterSevenName, false);
|
|
outParameterInfo.unit = kAudioUnitParameterUnit_Generic;
|
|
outParameterInfo.minValue = 0.0;
|
|
outParameterInfo.maxValue = 1.0;
|
|
outParameterInfo.defaultValue = kDefaultValue_ParamSeven;
|
|
break;
|
|
case kParam_Eight:
|
|
AUBase::FillInParameterName (outParameterInfo, kParameterEightName, false);
|
|
outParameterInfo.unit = kAudioUnitParameterUnit_Generic;
|
|
outParameterInfo.minValue = 0.0;
|
|
outParameterInfo.maxValue = 1.0;
|
|
outParameterInfo.defaultValue = kDefaultValue_ParamEight;
|
|
break;
|
|
default:
|
|
result = kAudioUnitErr_InvalidParameter;
|
|
break;
|
|
}
|
|
} else {
|
|
result = kAudioUnitErr_InvalidParameter;
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// ConsoleXSubOut::GetPropertyInfo
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
ComponentResult ConsoleXSubOut::GetPropertyInfo (AudioUnitPropertyID inID,
|
|
AudioUnitScope inScope,
|
|
AudioUnitElement inElement,
|
|
UInt32 & outDataSize,
|
|
Boolean & outWritable)
|
|
{
|
|
return AUEffectBase::GetPropertyInfo (inID, inScope, inElement, outDataSize, outWritable);
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// state that plugin supports only stereo-in/stereo-out processing
|
|
UInt32 ConsoleXSubOut::SupportedNumChannels(const AUChannelInfo ** outInfo)
|
|
{
|
|
if (outInfo != NULL)
|
|
{
|
|
static AUChannelInfo info;
|
|
info.inChannels = 2;
|
|
info.outChannels = 2;
|
|
*outInfo = &info;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// ConsoleXSubOut::GetProperty
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
ComponentResult ConsoleXSubOut::GetProperty( AudioUnitPropertyID inID,
|
|
AudioUnitScope inScope,
|
|
AudioUnitElement inElement,
|
|
void * outData )
|
|
{
|
|
return AUEffectBase::GetProperty (inID, inScope, inElement, outData);
|
|
}
|
|
|
|
// ConsoleXSubOut::Initialize
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
ComponentResult ConsoleXSubOut::Initialize()
|
|
{
|
|
ComponentResult result = AUEffectBase::Initialize();
|
|
if (result == noErr)
|
|
Reset(kAudioUnitScope_Global, 0);
|
|
return result;
|
|
}
|
|
|
|
#pragma mark ____ConsoleXSubOutEffectKernel
|
|
|
|
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// ConsoleXSubOut::ConsoleXSubOutKernel::Reset()
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
ComponentResult ConsoleXSubOut::Reset(AudioUnitScope inScope, AudioUnitElement inElement)
|
|
{
|
|
for (int x = 0; x < biq_total; x++) {biquad[x] = 0.0;}
|
|
for (int x = 0; x < air_total; x++) air[x] = 0.0;
|
|
for (int x = 0; x < kal_total; x++) kal[x] = 0.0;
|
|
|
|
for(int count = 0; count < 2004; count++) {mpkL[count] = 0.0; mpkR[count] = 0.0;}
|
|
for(int count = 0; count < 65; count++) {f[count] = 0.0;}
|
|
prevfreqMPeak = -1;
|
|
prevamountMPeak = -1;
|
|
mpc = 1;
|
|
|
|
for(int count = 0; count < dscBuf+2; count++) {
|
|
dBaL[count] = 0.0;
|
|
dBaR[count] = 0.0;
|
|
}
|
|
dBaPosL = 0.0;
|
|
dBaPosR = 0.0;
|
|
dBaXL = 1;
|
|
dBaXR = 1;
|
|
|
|
trebleGainA = 1.0; trebleGainB = 1.0;
|
|
midGainA = 1.0; midGainB = 1.0;
|
|
mPeakA = 1.0; mPeakB = 1.0;
|
|
bassGainA = 1.0; bassGainB = 1.0;
|
|
panA = 0.5; panB = 0.5;
|
|
inTrimA = 1.0; inTrimB = 1.0;
|
|
fpdL = 1.0; while (fpdL < 16386) fpdL = rand()*UINT32_MAX;
|
|
fpdR = 1.0; while (fpdR < 16386) fpdR = rand()*UINT32_MAX;
|
|
return noErr;
|
|
}
|
|
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// ConsoleXSubOut::ProcessBufferLists
|
|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
OSStatus ConsoleXSubOut::ProcessBufferLists(AudioUnitRenderActionFlags & ioActionFlags,
|
|
const AudioBufferList & inBuffer,
|
|
AudioBufferList & outBuffer,
|
|
UInt32 inFramesToProcess)
|
|
{
|
|
Float32 * inputL = (Float32*)(inBuffer.mBuffers[0].mData);
|
|
Float32 * inputR = (Float32*)(inBuffer.mBuffers[1].mData);
|
|
Float32 * outputL = (Float32*)(outBuffer.mBuffers[0].mData);
|
|
Float32 * outputR = (Float32*)(outBuffer.mBuffers[1].mData);
|
|
UInt32 nSampleFrames = inFramesToProcess;
|
|
double overallscale = 1.0;
|
|
overallscale /= 44100.0;
|
|
overallscale *= GetSampleRate();
|
|
int cycleEnd = floor(overallscale);
|
|
if (cycleEnd < 1) cycleEnd = 1;
|
|
if (cycleEnd > 3) cycleEnd = 3;
|
|
|
|
biquad[biq_freq] = 25000.0/GetSampleRate();
|
|
biquad[biq_reso] = 0.89997622;
|
|
double K = tan(M_PI * biquad[biq_freq]);
|
|
double norm = 1.0 / (1.0 + K / biquad[biq_reso] + K * K);
|
|
biquad[biq_a0] = K * K * norm;
|
|
biquad[biq_a1] = 2.0 * biquad[biq_a0];
|
|
biquad[biq_a2] = biquad[biq_a0];
|
|
biquad[biq_b1] = 2.0 * (K * K - 1.0) * norm;
|
|
biquad[biq_b2] = (1.0 - K / biquad[biq_reso] + K * K) * norm;
|
|
//ultrasonic nonlinear filter
|
|
|
|
trebleGainA = trebleGainB; trebleGainB = GetParameter( kParam_One )*2.0;
|
|
midGainA = midGainB; midGainB = GetParameter( kParam_Two )*2.0;
|
|
bassGainA = bassGainB; bassGainB = GetParameter( kParam_Three )*2.0;
|
|
//simple three band to adjust
|
|
|
|
//begin ResEQ2 Mid Boost
|
|
double freqMPeak = pow(GetParameter( kParam_Four )+0.16,3);
|
|
mPeakA = mPeakB; mPeakB = fabs(midGainB-1.0); //amount of mid peak leak through (or boost)
|
|
if (midGainB < 1.0) mPeakB *= 0.5;
|
|
int maxMPeak = (24.0*(2.0-freqMPeak))+16;
|
|
if ((freqMPeak != prevfreqMPeak)||(mPeakB != prevamountMPeak)) {
|
|
for (int x = 0; x < maxMPeak; x++) {
|
|
if (((double)x*freqMPeak) < M_PI_4) f[x] = sin(((double)x*freqMPeak)*4.0)*freqMPeak*sin(((double)(maxMPeak-x)/(double)maxMPeak)*M_PI_2);
|
|
else f[x] = cos((double)x*freqMPeak)*freqMPeak*sin(((double)(maxMPeak-x)/(double)maxMPeak)*M_PI_2);
|
|
}
|
|
prevfreqMPeak = freqMPeak; prevamountMPeak = mPeakB;
|
|
}//end ResEQ2 Mid Boost
|
|
//mid peak for either retaining during mid cut, or adding during mid boost
|
|
|
|
double kalman = 1.0-pow(GetParameter( kParam_Five ),2);
|
|
//crossover frequency between mid/bass
|
|
|
|
double refdB = GetParameter( kParam_Six );
|
|
double topdB = 0.000000075 * pow(10.0,refdB/20.0) * overallscale;
|
|
|
|
panA = panB; panB = GetParameter( kParam_Seven )*1.57079633;
|
|
inTrimA = inTrimB; inTrimB = GetParameter( kParam_Eight )*2.0;
|
|
|
|
while (nSampleFrames-- > 0) {
|
|
double inputSampleL = *inputL;
|
|
double inputSampleR = *inputR;
|
|
if (fabs(inputSampleL)<1.18e-23) inputSampleL = fpdL * 1.18e-17;
|
|
if (fabs(inputSampleR)<1.18e-23) inputSampleR = fpdR * 1.18e-17;
|
|
|
|
if (biquad[biq_freq] < 0.5) {
|
|
double nlBiq = fabs(biquad[biq_a0]*(1.0+(inputSampleL*0.25))); if (nlBiq > 1.0) nlBiq = 1.0;
|
|
double tmp = (inputSampleL * nlBiq) + biquad[biq_sL1];
|
|
biquad[biq_sL1] = (inputSampleL * biquad[biq_a1]) - (tmp * biquad[biq_b1]) + biquad[biq_sL2];
|
|
biquad[biq_sL2] = (inputSampleL * nlBiq) - (tmp * biquad[biq_b2]);
|
|
inputSampleL = tmp;
|
|
nlBiq = fabs(biquad[biq_a0]*(1.0+(inputSampleR*0.25))); if (nlBiq > 1.0) nlBiq = 1.0;
|
|
tmp = (inputSampleR * nlBiq) + biquad[biq_sR1];
|
|
biquad[biq_sR1] = (inputSampleR * biquad[biq_a1]) - (tmp * biquad[biq_b1]) + biquad[biq_sR2];
|
|
biquad[biq_sR2] = (inputSampleR * nlBiq) - (tmp * biquad[biq_b2]);
|
|
inputSampleR = tmp;
|
|
//ultrasonic filter before anything else is done
|
|
}
|
|
|
|
double drySampleL = inputSampleL;
|
|
double drySampleR = inputSampleR;
|
|
|
|
double temp = (double)nSampleFrames/inFramesToProcess;
|
|
double trebleGain = (trebleGainA*temp)+(trebleGainB*(1.0-temp));
|
|
if (trebleGain > 1.0) trebleGain = pow(trebleGain,3.0+sqrt(overallscale));
|
|
if (trebleGain < 1.0) trebleGain = 1.0-pow(1.0-trebleGain,2);
|
|
|
|
double midGain = (midGainA*temp)+(midGainB*(1.0-temp));
|
|
if (midGain > 1.0) midGain = 1.0;
|
|
if (midGain < 1.0) midGain = 1.0-pow(1.0-midGain,2);
|
|
double mPeak = pow((mPeakA*temp)+(mPeakB*(1.0-temp)),2);
|
|
|
|
double bassGain = (bassGainA*temp)+(bassGainB*(1.0-temp));
|
|
if (bassGain > 1.0) bassGain *= bassGain;
|
|
if (bassGain < 1.0) bassGain = 1.0-pow(1.0-bassGain,2);
|
|
|
|
double gainR = (panA*temp)+(panB*(1.0-temp));
|
|
double gainL = 1.57079633-gainR;
|
|
gainR = sin(gainR); gainL = sin(gainL);
|
|
|
|
double gain = (inTrimA*temp)+(inTrimB*(1.0-temp));
|
|
if (gain > 1.0) gain *= gain;
|
|
if (gain < 1.0) gain = 1.0-pow(1.0-gain,2);
|
|
gain *= 1.527864045000421;
|
|
|
|
//begin Air3L
|
|
air[pvSL4] = air[pvAL4] - air[pvAL3]; air[pvSL3] = air[pvAL3] - air[pvAL2];
|
|
air[pvSL2] = air[pvAL2] - air[pvAL1]; air[pvSL1] = air[pvAL1] - inputSampleL;
|
|
air[accSL3] = air[pvSL4] - air[pvSL3]; air[accSL2] = air[pvSL3] - air[pvSL2];
|
|
air[accSL1] = air[pvSL2] - air[pvSL1];
|
|
air[acc2SL2] = air[accSL3] - air[accSL2]; air[acc2SL1] = air[accSL2] - air[accSL1];
|
|
air[outAL] = -(air[pvAL1] + air[pvSL3] + air[acc2SL2] - ((air[acc2SL2] + air[acc2SL1])*0.5));
|
|
air[gainAL] *= 0.5; air[gainAL] += fabs(drySampleL-air[outAL])*0.5;
|
|
if (air[gainAL] > 0.3*sqrt(overallscale)) air[gainAL] = 0.3*sqrt(overallscale);
|
|
air[pvAL4] = air[pvAL3]; air[pvAL3] = air[pvAL2];
|
|
air[pvAL2] = air[pvAL1]; air[pvAL1] = (air[gainAL] * air[outAL]) + drySampleL;
|
|
double midL = drySampleL - ((air[outAL]*0.5)+(drySampleL*(0.457-(0.017*overallscale))));
|
|
temp = (midL + air[gndavgL])*0.5; air[gndavgL] = midL; midL = temp;
|
|
double trebleL = drySampleL-midL;
|
|
inputSampleL = midL;
|
|
//end Air3L
|
|
|
|
//begin Air3R
|
|
air[pvSR4] = air[pvAR4] - air[pvAR3]; air[pvSR3] = air[pvAR3] - air[pvAR2];
|
|
air[pvSR2] = air[pvAR2] - air[pvAR1]; air[pvSR1] = air[pvAR1] - inputSampleR;
|
|
air[accSR3] = air[pvSR4] - air[pvSR3]; air[accSR2] = air[pvSR3] - air[pvSR2];
|
|
air[accSR1] = air[pvSR2] - air[pvSR1];
|
|
air[acc2SR2] = air[accSR3] - air[accSR2]; air[acc2SR1] = air[accSR2] - air[accSR1];
|
|
air[outAR] = -(air[pvAR1] + air[pvSR3] + air[acc2SR2] - ((air[acc2SR2] + air[acc2SR1])*0.5));
|
|
air[gainAR] *= 0.5; air[gainAR] += fabs(drySampleR-air[outAR])*0.5;
|
|
if (air[gainAR] > 0.3*sqrt(overallscale)) air[gainAR] = 0.3*sqrt(overallscale);
|
|
air[pvAR4] = air[pvAR3]; air[pvAR3] = air[pvAR2];
|
|
air[pvAR2] = air[pvAR1]; air[pvAR1] = (air[gainAR] * air[outAR]) + drySampleR;
|
|
double midR = drySampleR - ((air[outAR]*0.5)+(drySampleR*(0.457-(0.017*overallscale))));
|
|
temp = (midR + air[gndavgR])*0.5; air[gndavgR] = midR; midR = temp;
|
|
double trebleR = drySampleR-midR;
|
|
inputSampleR = midR;
|
|
//end Air3R
|
|
|
|
//begin KalmanL
|
|
temp = inputSampleL = inputSampleL*(1.0-kalman)*0.777;
|
|
inputSampleL *= (1.0-kalman);
|
|
//set up gain levels to control the beast
|
|
kal[prevSlewL3] += kal[prevSampL3] - kal[prevSampL2]; kal[prevSlewL3] *= 0.5;
|
|
kal[prevSlewL2] += kal[prevSampL2] - kal[prevSampL1]; kal[prevSlewL2] *= 0.5;
|
|
kal[prevSlewL1] += kal[prevSampL1] - inputSampleL; kal[prevSlewL1] *= 0.5;
|
|
//make slews from each set of samples used
|
|
kal[accSlewL2] += kal[prevSlewL3] - kal[prevSlewL2]; kal[accSlewL2] *= 0.5;
|
|
kal[accSlewL1] += kal[prevSlewL2] - kal[prevSlewL1]; kal[accSlewL1] *= 0.5;
|
|
//differences between slews: rate of change of rate of change
|
|
kal[accSlewL3] += (kal[accSlewL2] - kal[accSlewL1]); kal[accSlewL3] *= 0.5;
|
|
//entering the abyss, what even is this
|
|
kal[kalOutL] += kal[prevSampL1] + kal[prevSlewL2] + kal[accSlewL3]; kal[kalOutL] *= 0.5;
|
|
//resynthesizing predicted result (all iir smoothed)
|
|
kal[kalGainL] += fabs(temp-kal[kalOutL])*kalman*8.0; kal[kalGainL] *= 0.5;
|
|
//madness takes its toll. Kalman Gain: how much dry to retain
|
|
if (kal[kalGainL] > kalman*0.5) kal[kalGainL] = kalman*0.5;
|
|
//attempts to avoid explosions
|
|
kal[kalOutL] += (temp*(1.0-(0.68+(kalman*0.157))));
|
|
//this is for tuning a really complete cancellation up around Nyquist
|
|
kal[prevSampL3] = kal[prevSampL2]; kal[prevSampL2] = kal[prevSampL1];
|
|
kal[prevSampL1] = (kal[kalGainL] * kal[kalOutL]) + ((1.0-kal[kalGainL])*temp);
|
|
//feed the chain of previous samples
|
|
if (kal[prevSampL1] > 1.0) kal[prevSampL1] = 1.0; if (kal[prevSampL1] < -1.0) kal[prevSampL1] = -1.0;
|
|
double bassL = kal[kalOutL]*0.777;
|
|
midL -= bassL;
|
|
//end KalmanL
|
|
|
|
//begin KalmanR
|
|
temp = inputSampleR = inputSampleR*(1.0-kalman)*0.777;
|
|
inputSampleR *= (1.0-kalman);
|
|
//set up gain levels to control the beast
|
|
kal[prevSlewR3] += kal[prevSampR3] - kal[prevSampR2]; kal[prevSlewR3] *= 0.5;
|
|
kal[prevSlewR2] += kal[prevSampR2] - kal[prevSampR1]; kal[prevSlewR2] *= 0.5;
|
|
kal[prevSlewR1] += kal[prevSampR1] - inputSampleR; kal[prevSlewR1] *= 0.5;
|
|
//make slews from each set of samples used
|
|
kal[accSlewR2] += kal[prevSlewR3] - kal[prevSlewR2]; kal[accSlewR2] *= 0.5;
|
|
kal[accSlewR1] += kal[prevSlewR2] - kal[prevSlewR1]; kal[accSlewR1] *= 0.5;
|
|
//differences between slews: rate of change of rate of change
|
|
kal[accSlewR3] += (kal[accSlewR2] - kal[accSlewR1]); kal[accSlewR3] *= 0.5;
|
|
//entering the abyss, what even is this
|
|
kal[kalOutR] += kal[prevSampR1] + kal[prevSlewR2] + kal[accSlewR3]; kal[kalOutR] *= 0.5;
|
|
//resynthesizing predicted result (all iir smoothed)
|
|
kal[kalGainR] += fabs(temp-kal[kalOutR])*kalman*8.0; kal[kalGainR] *= 0.5;
|
|
//madness takes its toll. Kalman Gain: how much dry to retain
|
|
if (kal[kalGainR] > kalman*0.5) kal[kalGainR] = kalman*0.5;
|
|
//attempts to avoid explosions
|
|
kal[kalOutR] += (temp*(1.0-(0.68+(kalman*0.157))));
|
|
//this is for tuning a really complete cancellation up around Nyquist
|
|
kal[prevSampR3] = kal[prevSampR2]; kal[prevSampR2] = kal[prevSampR1];
|
|
kal[prevSampR1] = (kal[kalGainR] * kal[kalOutR]) + ((1.0-kal[kalGainR])*temp);
|
|
//feed the chain of previous samples
|
|
if (kal[prevSampR1] > 1.0) kal[prevSampR1] = 1.0; if (kal[prevSampR1] < -1.0) kal[prevSampR1] = -1.0;
|
|
double bassR = kal[kalOutR]*0.777;
|
|
midR -= bassR;
|
|
//end KalmanR
|
|
|
|
//begin ResEQ2 Mid Boost
|
|
mpc++; if (mpc < 1 || mpc > 2001) mpc = 1;
|
|
mpkL[mpc] = midL;
|
|
mpkR[mpc] = midR;
|
|
double midPeakL = 0.0;
|
|
double midPeakR = 0.0;
|
|
for (int x = 0; x < maxMPeak; x++) {
|
|
int y = x*cycleEnd;
|
|
switch (cycleEnd)
|
|
{
|
|
case 1:
|
|
midPeakL += (mpkL[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x]);
|
|
midPeakR += (mpkR[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x]); break;
|
|
case 2:
|
|
midPeakL += ((mpkL[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.5);
|
|
midPeakR += ((mpkR[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.5); y--;
|
|
midPeakL += ((mpkL[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.5);
|
|
midPeakR += ((mpkR[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.5); break;
|
|
case 3:
|
|
midPeakL += ((mpkL[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.333);
|
|
midPeakR += ((mpkR[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.333); y--;
|
|
midPeakL += ((mpkL[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.333);
|
|
midPeakR += ((mpkR[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.333); y--;
|
|
midPeakL += ((mpkL[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.333);
|
|
midPeakR += ((mpkR[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.333); break;
|
|
case 4:
|
|
midPeakL += ((mpkL[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.25);
|
|
midPeakR += ((mpkR[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.25); y--;
|
|
midPeakL += ((mpkL[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.25);
|
|
midPeakR += ((mpkR[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.25); y--;
|
|
midPeakL += ((mpkL[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.25);
|
|
midPeakR += ((mpkR[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.25); y--;
|
|
midPeakL += ((mpkL[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.25);
|
|
midPeakR += ((mpkR[(mpc-y)+((mpc-y < 1)?2001:0)] * f[x])*0.25); //break
|
|
}
|
|
}//end ResEQ2 Mid Boost creating
|
|
|
|
inputSampleL = ((bassL*bassGain) + (midL*midGain) + (midPeakL*mPeak) + (trebleL*trebleGain)) * gainL * gain;
|
|
inputSampleR = ((bassR*bassGain) + (midR*midGain) + (midPeakR*mPeak) + (trebleR*trebleGain)) * gainR * gain;
|
|
//applies BitShiftPan pan section, and smoothed fader gain
|
|
|
|
inputSampleL *= topdB;
|
|
if (inputSampleL < -0.222) inputSampleL = -0.222; if (inputSampleL > 0.222) inputSampleL = 0.222;
|
|
dBaL[dBaXL] = inputSampleL; dBaPosL *= 0.5; dBaPosL += fabs((inputSampleL*((inputSampleL*0.25)-0.5))*0.5);
|
|
int dBdly = floor(dBaPosL*dscBuf);
|
|
double dBi = (dBaPosL*dscBuf)-dBdly;
|
|
inputSampleL = dBaL[dBaXL-dBdly +((dBaXL-dBdly < 0)?dscBuf:0)]*(1.0-dBi);
|
|
dBdly++; inputSampleL += dBaL[dBaXL-dBdly +((dBaXL-dBdly < 0)?dscBuf:0)]*dBi;
|
|
dBaXL++; if (dBaXL < 0 || dBaXL >= dscBuf) dBaXL = 0;
|
|
inputSampleL /= topdB;
|
|
inputSampleR *= topdB;
|
|
if (inputSampleR < -0.222) inputSampleR = -0.222; if (inputSampleR > 0.222) inputSampleR = 0.222;
|
|
dBaR[dBaXR] = inputSampleR; dBaPosR *= 0.5; dBaPosR += fabs((inputSampleR*((inputSampleR*0.25)-0.5))*0.5);
|
|
dBdly = floor(dBaPosR*dscBuf);
|
|
dBi = (dBaPosR*dscBuf)-dBdly;
|
|
inputSampleR = dBaR[dBaXR-dBdly +((dBaXR-dBdly < 0)?dscBuf:0)]*(1.0-dBi);
|
|
dBdly++; inputSampleR += dBaR[dBaXR-dBdly +((dBaXR-dBdly < 0)?dscBuf:0)]*dBi;
|
|
dBaXR++; if (dBaXR < 0 || dBaXR >= dscBuf) dBaXR = 0;
|
|
inputSampleR /= topdB;
|
|
//top dB processing for distributed discontinuity modeling air nonlinearity
|
|
|
|
inputSampleL *= 0.618033988749895;
|
|
if (inputSampleL > 1.0) inputSampleL = 1.0;
|
|
else if (inputSampleL > 0.0) inputSampleL = -expm1((log1p(-inputSampleL) * 1.618033988749895));
|
|
if (inputSampleL < -1.0) inputSampleL = -1.0;
|
|
else if (inputSampleL < 0.0) inputSampleL = expm1((log1p(inputSampleL) * 1.618033988749895));
|
|
|
|
inputSampleR *= 0.618033988749895;
|
|
if (inputSampleR > 1.0) inputSampleR = 1.0;
|
|
else if (inputSampleR > 0.0) inputSampleR = -expm1((log1p(-inputSampleR) * 1.618033988749895));
|
|
if (inputSampleR < -1.0) inputSampleR = -1.0;
|
|
else if (inputSampleR < 0.0) inputSampleR = expm1((log1p(inputSampleR) * 1.618033988749895));
|
|
|
|
//begin 32 bit stereo floating point dither
|
|
int expon; frexpf((float)inputSampleL, &expon);
|
|
fpdL ^= fpdL << 13; fpdL ^= fpdL >> 17; fpdL ^= fpdL << 5;
|
|
inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 5.5e-36l * pow(2,expon+62));
|
|
frexpf((float)inputSampleR, &expon);
|
|
fpdR ^= fpdR << 13; fpdR ^= fpdR >> 17; fpdR ^= fpdR << 5;
|
|
inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 5.5e-36l * pow(2,expon+62));
|
|
//end 32 bit stereo floating point dither
|
|
|
|
*outputL = inputSampleL;
|
|
*outputR = inputSampleR;
|
|
//direct stereo out
|
|
|
|
inputL += 1;
|
|
inputR += 1;
|
|
outputL += 1;
|
|
outputR += 1;
|
|
}
|
|
return noErr;
|
|
}
|
|
|