61 |
* |
* |
62 |
* @param ExtControlValue - new external controller value |
* @param ExtControlValue - new external controller value |
63 |
*/ |
*/ |
64 |
inline void update(const uint16_t& ExtControlValue) { |
inline void updateByMIDICtrlValue(const uint16_t& ExtControlValue) { |
65 |
const float max = this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff; |
this->ExtControlValue = ExtControlValue; |
66 |
|
|
67 |
|
const float max = (this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff) * this->ScriptDepthFactor; |
68 |
normalizer = max; |
normalizer = max; |
69 |
} |
} |
70 |
|
|
83 |
* @param PulseWidth - the pulse width in percents |
* @param PulseWidth - the pulse width in percents |
84 |
*/ |
*/ |
85 |
void trigger(float Frequency, uint16_t InternalDepth, uint16_t ExtControlDepth, float PulseWidth, unsigned int SampleRate) { |
void trigger(float Frequency, uint16_t InternalDepth, uint16_t ExtControlDepth, float PulseWidth, unsigned int SampleRate) { |
86 |
|
this->Frequency = Frequency; |
87 |
this->InternalDepth = (InternalDepth / 1200.0f) * this->Max; |
this->InternalDepth = (InternalDepth / 1200.0f) * this->Max; |
88 |
this->ExtControlDepthCoeff = (((float) ExtControlDepth / 1200.0f) / 127.0f) * this->Max; |
this->ExtControlDepthCoeff = (((float) ExtControlDepth / 1200.0f) / 127.0f) * this->Max; |
89 |
|
this->ScriptFrequencyFactor = this->ScriptDepthFactor = 1.f; // reset for new voice |
90 |
|
|
91 |
const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF... |
const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF... |
92 |
const float r = Frequency / (float) SampleRate; // frequency alteration quotient |
const float freq = Frequency * this->ScriptFrequencyFactor; |
93 |
|
const float r = freq / (float) SampleRate; // frequency alteration quotient |
94 |
c = (int) (intLimit * r); |
c = (int) (intLimit * r); |
95 |
width = (PulseWidth / 100.0) * intLimit; |
width = (PulseWidth / 100.0) * intLimit; |
96 |
|
|
114 |
} |
} |
115 |
|
|
116 |
void setFrequency(float Frequency, unsigned int SampleRate) { |
void setFrequency(float Frequency, unsigned int SampleRate) { |
117 |
|
this->Frequency = Frequency; |
118 |
|
const float freq = Frequency * this->ScriptFrequencyFactor; |
119 |
const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF... |
const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF... |
120 |
float r = Frequency / (float) SampleRate; // frequency alteration quotient |
float r = freq / (float) SampleRate; // frequency alteration quotient |
121 |
c = (int) (intLimit * r); |
c = (int) (intLimit * r); |
122 |
} |
} |
123 |
|
|
124 |
|
void setScriptDepthFactor(float factor) { |
125 |
|
this->ScriptDepthFactor = factor; |
126 |
|
updateByMIDICtrlValue(this->ExtControlValue); |
127 |
|
} |
128 |
|
|
129 |
|
void setScriptFrequencyFactor(float factor, unsigned int SampleRate) { |
130 |
|
this->ScriptFrequencyFactor = factor; |
131 |
|
setFrequency(this->Frequency, SampleRate); |
132 |
|
} |
133 |
|
|
134 |
protected: |
protected: |
135 |
unsigned int uiLevel; |
unsigned int uiLevel; |
136 |
unsigned int width; |
unsigned int width; |