[go: up one dir, main page]

Menu

[r40]: / Source / VCO.cpp  Maximize  Restore  History

Download this file

129 lines (106 with data), 3.6 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
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
/**************************************************************************
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 "VCO.h"
/*!
* Initializes the Wave Generators in 2 threads (for the first call).
*
* \param sampleRate Sample rate of audio flow
*/
void VCO::init(double sampleRate)
{
LFOModulated::init(sampleRate);
juce::Random random;
if (mSineGenerator.getSamplingFreq() != sampleRate) {
// Complete recompute
std::thread t1([this, sampleRate]() {
mSineGenerator.init(sampleRate);
mHOddGenerator.init(sampleRate);
mHEvenGenerator.init(sampleRate);
mNoiseGenerator.init(sampleRate);
});
std::thread t2([this, sampleRate]() {
mSawtoothGenerator.init(sampleRate);
mSubGenerator.init(sampleRate);
mPWMGenerator.init(sampleRate);
mPhaseNoiseGenerator.init(sampleRate);
mPhaseSineGenerator.init(sampleRate);
});
t1.join();
t2.join();
}
else
{
// Only table reaffectation
mSineGenerator.init(sampleRate);
mHOddGenerator.init(sampleRate);
mHEvenGenerator.init(sampleRate);
mSawtoothGenerator.init(sampleRate);
mSubGenerator.init(sampleRate);
mPWMGenerator.init(sampleRate);
mNoiseGenerator.init(sampleRate);
mPhaseNoiseGenerator.init(sampleRate);
mPhaseSineGenerator.init(sampleRate);
mPhaseSineGenerator.move(random.nextDouble()*sampleRate);
}
mPhaseShiftFreq = 1.0/(RndPhaseShiftPeriodMin+(RndPhaseShiftPeriodMax-RndPhaseShiftPeriodMin)*random.nextDouble());
}
void VCO::noteOn(int note)
{
LFOModulated::noteOn(note);
resetPhase();
mSlope = 0.0f;
}
void VCO::updateInternalValues(int controller)
{
LFOModulated::updateInternalValues(controller);
if (controller != 0)
return;
mSineGain = float(*mVCOParam.mSineGain);
mNoiseGain = float(*mVCOParam.mNoiseGain);
mHOddGain = float(*mVCOParam.mHOddGain);
mHEvenGain = float(*mVCOParam.mHEvenGain);
mSawGain = float(*mVCOParam.mSawGain);
mSubGain = float(*mVCOParam.mSubGain);
mPWMGain = float(*mVCOParam.mPWMGain);
mPWMRate = float(*mVCOParam.mPWMRate);
bool phaseHasChanged = false;
double phase;
mPhaseJitter = float(*mVCOParam.mPhaseJitter);
phase = float(*mVCOParam.mSawPhase);
if (phase != mSawPhase) {
phaseHasChanged = true;
mSawPhase = phase;
}
phase = float(*mVCOParam.mSubPhase);
if (phase != mSubPhase) {
phaseHasChanged = true;
mSubPhase = phase;
}
phase = float(*mVCOParam.mPWMPhase);
if (phase != mPWMPhase) {
phaseHasChanged = true;
mPWMPhase = phase;
}
if(phaseHasChanged)
resetPhase();
}
void VCO::resetPhase()
{
mSineGenerator.setPhase(0);
mHOddGenerator.setPhase(0);
mHEvenGenerator.setPhase(0);
mSawtoothGenerator.setPhase(mSawPhase);
mSubGenerator.setPhase(mSubPhase);
mPWMGenerator.setPhase(mPWMPhase);
}