/**************************************************************************
Copyright (C) 2019 Arnaud Champenois arthelion@free.fr
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
#include "TVF.h"
TVF::~TVF() {}
void TVF::init(double sampleRate) {
TimeVariant::init(sampleRate);
mLowCutFilter.parameters->type = juce::dsp::StateVariableFilter::Parameters<double>::Type::highPass;
mMaxCutoff = sampleRate * 0.5-10.0; // On Úvite le point singulier....
mCutoffValue = mMaxCutoff;
updateInternalValues();
}
void TVF::updateInternalValues(int controller) {
TimeVariant::updateInternalValues(controller);
if (controller != 0 && controller != mTVFParam.mControlNumber->getCtrl() &&
controller != AftrTouchCtrl && controller != PitchWheelCtrl)
return;
double powCoeff = float(*mTVFParam.mFrequency) +
float(*mTVFParam.mKeyFollowCutoffDepth) * (mNote - 69.0) +
float(*mTVFParam.mVelocityCutoffDepth) * mVelocity +
float(*mTVFParam.mAfterTouchCutoffDepth) * mAfterTouch +
float(*mTVFParam.mPitchWheelCutoffDepth) * mPitchWheel +
float(*mTVFParam.mControllerCutoffDepth) * mController[mTVFParam.mControlNumber->getCtrl()];
mCutoffValue = mMaxCutoff*0.001*pow(10.0, powCoeff);
if (mCutoffValue > mMaxCutoff)
mCutoffValue = mMaxCutoff;
else if (mCutoffValue < TVFLowestCutoffFrequency)
mCutoffValue = TVFLowestCutoffFrequency;
mResonanceValue = float(*mTVFParam.mResonance)*TVFDefaultResonance +
float(*mTVFParam.mKeyFollowResonanceDepth) * (mNote - 69.0) +
float(*mTVFParam.mVelocityResonanceDepth) * mVelocity +
float(*mTVFParam.mAfterTouchResonanceDepth) * mAfterTouch +
float(*mTVFParam.mPitchWheelResonanceDepth) * mPitchWheel +
float(*mTVFParam.mControllerResonanceDepth) * mController[mTVFParam.mControlNumber->getCtrl()];
if (mResonanceValue > TVFMaxResonance)
mResonanceValue = TVFMaxResonance;
else if (mResonanceValue < TVFDefaultResonance)
mResonanceValue = TVFDefaultResonance;
mFilter.parameters->setCutOffFrequency(mSampleRate, mCutoffValue, mResonanceValue);
if (controller == 0) {
mLowCutFrequency = TVFLowestCutoffFrequency*pow(10.0, float(*mTVFParam.mLowCutFrequency));
if (mLowCutFrequency >= TVFLowestCutoffFrequency)
mLowCutFilter.parameters->setCutOffFrequency(mSampleRate, mLowCutFrequency, TVFDefaultResonance);
if (*mTVFParam.mMidFrequency != mMidFreq || *mTVFParam.mMidQ != mMidQ || *mTVFParam.mMidGain != mMidGain) {
mMidFreq = *mTVFParam.mMidFrequency;
mMidQ = *mTVFParam.mMidQ;
mMidGain = *mTVFParam.mMidGain;
double freq = 20.0*pow(10.0, mMidFreq);
auto coeffs = dsp::IIR::Coefficients< double >::makePeakFilter(mSampleRate, freq, mMidQ, Decibels::decibelsToGain(mMidGain));
mBandFilter.coefficients = coeffs;
mBandFilter.reset();
}
}
}