/[svn]/linuxsampler/trunk/src/engines/common/LFOPulse.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/common/LFOPulse.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2223 by iliev, Fri Jul 29 13:39:58 2011 UTC revision 3561 by schoenebeck, Fri Aug 23 11:44:00 2019 UTC
# Line 61  namespace LinuxSampler { Line 61  namespace LinuxSampler {
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    
# Line 81  namespace LinuxSampler { Line 83  namespace LinuxSampler {
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                    this->pFinalDepth = NULL;
91                    this->pFinalFrequency = NULL;
92    
93                  const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF...                  const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF...
94                  const float r = Frequency / (float) SampleRate; // frequency alteration quotient                  const float freq = Frequency * this->ScriptFrequencyFactor;
95                    const float r = freq / (float) SampleRate; // frequency alteration quotient
96                  c = (int) (intLimit * r);                  c = (int) (intLimit * r);
97                  width = (PulseWidth / 100.0) * intLimit;                  width = (PulseWidth / 100.0) * intLimit;
98    
# Line 95  namespace LinuxSampler { Line 102  namespace LinuxSampler {
102              virtual void trigger(float Frequency, start_level_t StartLevel, uint16_t InternalDepth, uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate) {              virtual void trigger(float Frequency, start_level_t StartLevel, uint16_t InternalDepth, uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate) {
103                  trigger(Frequency, InternalDepth, ExtControlDepth, WIDTH / 10.0f, SampleRate);                  trigger(Frequency, InternalDepth, ExtControlDepth, WIDTH / 10.0f, SampleRate);
104              }              }
105                
106                /**
107                 * Should be invoked after the LFO is triggered.
108                 * @param phase From 0 to 360 degrees.
109                 */
110                void setPhase(float phase) {
111                    if (phase < 0) phase = 0;
112                    if (phase > 360) phase = 360;
113                    phase /= 360.0f;
114                    const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF...
115                    uiLevel = intLimit * phase;
116                }
117                
118                void setFrequency(float Frequency, unsigned int SampleRate) {
119                    this->Frequency = Frequency;
120                    const float freq = Frequency * this->ScriptFrequencyFactor;
121                    const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF...
122                    float r = freq / (float) SampleRate; // frequency alteration quotient
123                    c = (int) (intLimit * r);
124                }
125    
126                void setScriptDepthFactor(float factor, bool isFinal) {
127                    this->ScriptDepthFactor = factor;
128                    // set or reset this script depth parameter to be the sole
129                    // source for the LFO depth
130                    if (isFinal && !this->pFinalDepth)
131                        this->pFinalDepth = &this->ScriptDepthFactor;
132                    else if (!isFinal && this->pFinalDepth == &this->ScriptDepthFactor)
133                        this->pFinalDepth = NULL;
134                    // recalculate upon new depth
135                    updateByMIDICtrlValue(this->ExtControlValue);
136                }
137    
138                void setScriptFrequencyFactor(float factor, unsigned int SampleRate) {
139                    this->ScriptFrequencyFactor = factor;
140                    // in case script frequency was set as "final" value before,
141                    // reset it so that all sources are processed from now on
142                    if (this->pFinalFrequency == &this->ScriptFrequencyFactor)
143                        this->pFinalFrequency = NULL;
144                    // recalculate upon new frequency
145                    setFrequency(this->Frequency, SampleRate);
146                }
147    
148                void setScriptFrequencyFinal(float hz, unsigned int SampleRate) {
149                    this->ScriptFrequencyFactor = hz;
150                    // assign script's given frequency as sole source for the LFO
151                    // frequency, thus ignore all other sources
152                    if (!this->pFinalFrequency)
153                        this->pFinalFrequency = &this->ScriptFrequencyFactor;
154                    // recalculate upon new frequency
155                    setFrequency(this->Frequency, SampleRate);
156                }
157    
158          protected:          protected:
159              unsigned int uiLevel;              unsigned int uiLevel;

Legend:
Removed from v.2223  
changed lines
  Added in v.3561

  ViewVC Help
Powered by ViewVC