[go: up one dir, main page]

Menu

[r40]: / Source / StereoDelay.h  Maximize  Restore  History

Download this file

102 lines (80 with data), 2.9 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
/**************************************************************************
Copyright (C) 2020 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/>.
**************************************************************************/
#pragma once
#include "AudioParameters.h"
#include "../JuceLibraryCode/JuceHeader.h"
#include "WaveGenerator.h"
class StereoDelay {
public:
StereoDelay(const SynthParameters&param) :
mP(param), mLeftLine(MaxDelayTime), mRightLine(MaxDelayTime) {
}
~StereoDelay() {}
void init(double sampleRate) {
mSampleRate = sampleRate;
mLeftLine.init(sampleRate);
mRightLine.init(sampleRate);
auto coeffs = dsp::IIR::Coefficients< double >::makeLowPass(mSampleRate, 6000);
mLPFilterL.coefficients = coeffs;
mLPFilterL.reset();
mLPFilterR.coefficients = coeffs;
mLPFilterR.reset();
updateInternalValues();
}
void next(double&outL, double&outR) {
const ScopedLock slock(lock);
double valueL = mLPFilterL.processSample(outL);
double valueR = mLPFilterR.processSample(outR);
double lastL = mLeftLine.next();
double lastR = mRightLine.next();
mLeftLine.push(lastL*mFeed + valueL);
mRightLine.push(lastR*mFeed + valueR);
outL = mMix * lastL + outL;
outR = mMix * lastR + outR;
}
bool isActive() const { return mMix != 0.0; }
void updateInternalValues() {
const ScopedLock slock(lock);
double timeCoeff = 1.0;
if (*mP.mDlySync) {
timeCoeff = 60.0 / *mP.mMetronomTempo;
}
double prevLeft = mDelayLeft;
mDelayLeft = timeCoeff * (*mP.mDlyLeftTime);
if (mDelayLeft < 0.010f)
mDelayLeft = 0.010f;
if (prevLeft != mDelayLeft)
mLeftLine.setDelay(mDelayLeft);
double prevRight = mDelayRight;
mDelayRight = timeCoeff * (*mP.mDlyRightTime);
if (mDelayRight < 0.010f)
mDelayRight = 0.010f;
if (prevRight != mDelayRight)
mRightLine.setDelay(mDelayRight);
mMix = *mP.mDlyMix;
mFeed = *mP.mDlyFeed;
}
private:
const SynthParameters & mP;
juce::dsp::IIR::Filter<double> mLPFilterL;
juce::dsp::IIR::Filter<double> mLPFilterR;
double mSampleRate = 44100.0;
double mFeed = 0.2;
double mMix = 0.0;
double mDelayLeft = 0.0;
double mDelayRight = 0.0;
DelayLine mLeftLine;
DelayLine mRightLine;
CriticalSection lock;
};