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

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

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

revision 2227 by iliev, Wed Aug 3 17:11:40 2011 UTC revision 3118 by schoenebeck, Fri Apr 21 13:33:03 2017 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2   *                                                                         *   *                                                                         *
3   *   Copyright (C) 2005 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  *
# Line 62  namespace LinuxSampler { Line 62  namespace LinuxSampler {
62               *               *
63               * @param ExtControlValue - new external controller value               * @param ExtControlValue - new external controller value
64               */               */
65              inline void update(const uint16_t& ExtControlValue) {              inline void updateByMIDICtrlValue(const uint16_t& ExtControlValue) {
66                    this->ExtControlValue = ExtControlValue;
67    
68                  const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF...                  const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF...
69                  const float max = this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff;                  const float max = (this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff) * this->ScriptDepthFactor;
70                  if (RANGE == range_unsigned) {                  if (RANGE == range_unsigned) {
71                      normalizer = max / (float) intLimit;                      normalizer = max / (float) intLimit;
72                  } else { // signed range                  } else { // signed range
# Line 88  namespace LinuxSampler { Line 90  namespace LinuxSampler {
90               *                          audio output signal               *                          audio output signal
91               */               */
92              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) {
93                    this->Frequency            = Frequency;
94                  this->InternalDepth        = (InternalDepth / 1200.0f) * this->Max;                  this->InternalDepth        = (InternalDepth / 1200.0f) * this->Max;
95                  this->ExtControlDepthCoeff = (((float) ExtControlDepth / 1200.0f) / 127.0f) * this->Max;                  this->ExtControlDepthCoeff = (((float) ExtControlDepth / 1200.0f) / 127.0f) * this->Max;
96                    this->ScriptFrequencyFactor = this->ScriptDepthFactor = 1.f; // reset for new voice
97                  if (RANGE == range_unsigned) {                  if (RANGE == range_unsigned) {
98                      this->InternalDepth        *= 2.0f;                      this->InternalDepth        *= 2.0f;
99                      this->ExtControlDepthCoeff *= 2.0f;                      this->ExtControlDepthCoeff *= 2.0f;
100                  }                  }
101    
102                  const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF...                  const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF...
103                  const float r = Frequency / (float) SampleRate; // frequency alteration quotient                  const float freq = Frequency * this->ScriptFrequencyFactor;
104                    const float r = freq / (float) SampleRate; // frequency alteration quotient
105                  c = (int) (intLimit * r);                  c = (int) (intLimit * r);
106    
107                  switch (StartLevel) {                  switch (StartLevel) {
# Line 128  namespace LinuxSampler { Line 133  namespace LinuxSampler {
133              }              }
134                            
135              void setFrequency(float Frequency, unsigned int SampleRate) {              void setFrequency(float Frequency, unsigned int SampleRate) {
136                    this->Frequency = Frequency;
137                    const float freq = Frequency * this->ScriptFrequencyFactor;
138                  const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF...                  const unsigned int intLimit = (unsigned int) -1; // all 0xFFFF...
139                  float r = Frequency / (float) SampleRate; // frequency alteration quotient                  float r = freq / (float) SampleRate; // frequency alteration quotient
140                  c = (int) (intLimit * r);                  c = (int) (intLimit * r);
141              }              }
142    
143                void setScriptDepthFactor(float factor) {
144                    this->ScriptDepthFactor = factor;
145                    updateByMIDICtrlValue(this->ExtControlValue);
146                }
147    
148                void setScriptFrequencyFactor(float factor, unsigned int SampleRate) {
149                    this->ScriptFrequencyFactor = factor;
150                    setFrequency(this->Frequency, SampleRate);
151                }
152    
153          protected:          protected:
154              int   iLevel;              int   iLevel;
155              int   c;              int   c;

Legend:
Removed from v.2227  
changed lines
  Added in v.3118

  ViewVC Help
Powered by ViewVC