/[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 3611 by schoenebeck, Mon Sep 30 17:35:43 2019 UTC revision 3612 by schoenebeck, Mon Sep 30 18:03:43 2019 UTC
# Line 30  namespace LinuxSampler { Line 30  namespace LinuxSampler {
30       * This is a triangle Low Frequency Oscillator which uses pure integer       * This is a triangle Low Frequency Oscillator which uses pure integer
31       * math (without branches) to synthesize the triangular wave.       * math (without branches) to synthesize the triangular wave.
32       */       */
33      template<range_type_t RANGE>      template<LFO::range_type_t RANGE>
34      class LFOTriangleIntMath : public LFOBase<RANGE> {      class LFOTriangleIntMath : public LFOBase<RANGE> {
35          public:          public:
36    
# Line 51  namespace LinuxSampler { Line 51  namespace LinuxSampler {
51                  const int signshifts = (sizeof(int) * 8) - 1;                  const int signshifts = (sizeof(int) * 8) - 1;
52                  iLevel += c;                  iLevel += c;
53                  const int iSign  = (iLevel >> signshifts) | 1;                  const int iSign  = (iLevel >> signshifts) | 1;
54                  if (RANGE == range_unsigned)                  if (RANGE == LFO::range_unsigned)
55                      return normalizer * (float) (iSign * iLevel);                      return normalizer * (float) (iSign * iLevel);
56                  else /* signed range */                  else /* signed range */
57                      return normalizer * (float) (iSign * iLevel) + offset;                      return normalizer * (float) (iSign * iLevel) + offset;
# Line 67  namespace LinuxSampler { Line 67  namespace LinuxSampler {
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) * this->ScriptDepthFactor;                  const float max = (this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff) * this->ScriptDepthFactor;
70                  if (RANGE == range_unsigned) {                  if (RANGE == LFO::range_unsigned) {
71                      normalizer = max / (float) intLimit;                      normalizer = max / (float) intLimit;
72                  } else { // signed range                  } else { // signed range
73                      normalizer = max / (float) intLimit * 4.0f;                      normalizer = max / (float) intLimit * 4.0f;
# Line 89  namespace LinuxSampler { Line 89  namespace LinuxSampler {
89               * @param SampleRate      - current sample rate of the engines               * @param SampleRate      - current sample rate of the engines
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, LFO::start_level_t StartLevel, uint16_t InternalDepth, uint16_t ExtControlDepth, bool FlipPhase, unsigned int SampleRate) {
93                  this->Frequency            = Frequency;                  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                  this->ScriptFrequencyFactor = this->ScriptDepthFactor = 1.f; // reset for new voice
97                  if (RANGE == range_unsigned) {                  if (RANGE == LFO::range_unsigned) {
98                      this->InternalDepth        *= 2.0f;                      this->InternalDepth        *= 2.0f;
99                      this->ExtControlDepthCoeff *= 2.0f;                      this->ExtControlDepthCoeff *= 2.0f;
100                  }                  }
# Line 107  namespace LinuxSampler { Line 107  namespace LinuxSampler {
107                  c = (int) (intLimit * r);                  c = (int) (intLimit * r);
108    
109                  switch (StartLevel) {                  switch (StartLevel) {
110                      case start_level_max:                      case LFO::start_level_max:
111                          iLevel = (FlipPhase) ? 0 : intLimit >> 1;                          iLevel = (FlipPhase) ? 0 : intLimit >> 1;
112                          break;                          break;
113                      case start_level_mid:                      case LFO::start_level_mid:
114                          iLevel = (FlipPhase) ? intLimit / 4 * 3 : intLimit >> 2;                          iLevel = (FlipPhase) ? intLimit / 4 * 3 : intLimit >> 2;
115                          break;                          break;
116                      case start_level_min:                      case LFO::start_level_min:
117                          iLevel = (FlipPhase) ? intLimit >> 1 : 0;                          iLevel = (FlipPhase) ? intLimit >> 1 : 0;
118                          break;                          break;
119                  }                  }

Legend:
Removed from v.3611  
changed lines
  Added in v.3612

  ViewVC Help
Powered by ViewVC