[go: up one dir, main page]

Menu

[r99]: / MolossII / Source / TVF.cpp  Maximize  Restore  History

Download this file

95 lines (71 with data), 3.8 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
/**************************************************************************
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.41; // On Úvite le point singulier....
if (mMaxCutoff > TVFHighestCutoffFrequency)
mMaxCutoff = TVFHighestCutoffFrequency;
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 - KFNoteSplit) +
float(*mTVFParam.mVelocityCutoffDepth) * mVelocity;
mCutoffValue = mMaxCutoff * 0.001*pow(10.0, powCoeff);
powCoeff =
float(*mTVFParam.mAfterTouchCutoffDepth) * mAfterTouch +
float(*mTVFParam.mPitchWheelCutoffDepth) * mPitchWheel +
float(*mTVFParam.mControllerCutoffDepth) * mController[mTVFParam.mControlNumber->getCtrl()];
if(powCoeff<0)
mCutoffCtrlOffset = -float(mMaxCutoff * 0.001*(pow(10.0, -powCoeff*0.5) - 1.0f));
else
mCutoffCtrlOffset = float(mMaxCutoff * 0.001*(pow(10.0, powCoeff)-1.0f));
if (mCutoffValue > mMaxCutoff)
mCutoffValue = mMaxCutoff;
else if (mCutoffValue < TVFLowestCutoffFrequency)
mCutoffValue = TVFLowestCutoffFrequency;
mResonanceValue = float(*mTVFParam.mResonance)*TVFDefaultResonance +
float(*mTVFParam.mKeyFollowResonanceDepth) * (mNote - KFNoteSplit) +
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);
mLastCutoff = mCutoffValue;
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;
}
}
}