1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* Copyright (C) 2005, 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2017 Christian Schoenebeck * |
4 |
* * |
* * |
5 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
6 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
67 |
* |
* |
68 |
* @param ExtControlValue - new external controller value |
* @param ExtControlValue - new external controller value |
69 |
*/ |
*/ |
70 |
inline void update(const uint16_t& ExtControlValue) { |
inline void updateByMIDICtrlValue(const uint16_t& ExtControlValue) { |
71 |
const float max = this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff; |
this->ExtControlValue = ExtControlValue; |
72 |
|
|
73 |
|
const float max = (this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff) * this->ScriptDepthFactor; |
74 |
if (RANGE == range_unsigned) { |
if (RANGE == range_unsigned) { |
75 |
const float harmonicCompensation = 1.0f + fabsf(AMP2); // to compensate the compensation ;) (see trigger()) |
const float harmonicCompensation = 1.0f + fabsf(AMP2); // to compensate the compensation ;) (see trigger()) |
76 |
normalizer = max * 0.5f; |
normalizer = max * 0.5f; |
95 |
* audio output signal |
* audio output signal |
96 |
*/ |
*/ |
97 |
void trigger(float Frequency, start_level_t StartLevel, uint16_t InternalDepth, uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate) { |
void trigger(float Frequency, start_level_t StartLevel, uint16_t InternalDepth, uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate) { |
98 |
|
this->Frequency = Frequency; |
99 |
|
this->ScriptFrequencyFactor = this->ScriptDepthFactor = 1.f; // reset for new voice |
100 |
const float harmonicCompensation = 1.0f + fabsf(AMP2); // to compensate the 2nd harmonic's amplitude overhead |
const float harmonicCompensation = 1.0f + fabsf(AMP2); // to compensate the 2nd harmonic's amplitude overhead |
101 |
this->InternalDepth = (InternalDepth / 1200.0f) * this->Max / harmonicCompensation; |
this->InternalDepth = (InternalDepth / 1200.0f) * this->Max / harmonicCompensation; |
102 |
this->ExtControlDepthCoeff = (((float) ExtControlDepth / 1200.0f) / 127.0f) * this->Max / harmonicCompensation; |
this->ExtControlDepthCoeff = (((float) ExtControlDepth / 1200.0f) / 127.0f) * this->Max / harmonicCompensation; |
103 |
|
|
104 |
c1 = 2.0f * M_PI * Frequency / (float) SampleRate; |
const float freq = Frequency * this->ScriptFrequencyFactor; |
105 |
c2 = 2.0f * M_PI * Frequency / (float) SampleRate * 3.0f; |
c1 = 2.0f * M_PI * freq / (float) SampleRate; |
106 |
|
c2 = 2.0f * M_PI * freq / (float) SampleRate * 3.0f; |
107 |
|
|
108 |
double phi; // phase displacement |
double phi; // phase displacement |
109 |
switch (StartLevel) { |
switch (StartLevel) { |
139 |
} |
} |
140 |
|
|
141 |
void setFrequency(float Frequency, unsigned int SampleRate) { |
void setFrequency(float Frequency, unsigned int SampleRate) { |
142 |
c1 = 2.0f * M_PI * Frequency / (float) SampleRate; |
this->Frequency = Frequency; |
143 |
c2 = 2.0f * M_PI * Frequency / (float) SampleRate * 3.0f; |
const float freq = Frequency * this->ScriptFrequencyFactor; |
144 |
|
c1 = 2.0f * M_PI * freq / (float) SampleRate; |
145 |
|
c2 = 2.0f * M_PI * freq / (float) SampleRate * 3.0f; |
146 |
|
} |
147 |
|
|
148 |
|
void setScriptDepthFactor(float factor) { |
149 |
|
this->ScriptDepthFactor = factor; |
150 |
|
updateByMIDICtrlValue(this->ExtControlValue); |
151 |
|
} |
152 |
|
|
153 |
|
void setScriptFrequencyFactor(float factor, unsigned int SampleRate) { |
154 |
|
this->ScriptFrequencyFactor = factor; |
155 |
|
setFrequency(this->Frequency, SampleRate); |
156 |
} |
} |
157 |
|
|
158 |
private: |
private: |