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

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

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

revision 720 by senkov, Sun Jul 24 16:48:11 2005 UTC revision 721 by schoenebeck, Sun Jul 24 19:44:44 2005 UTC
# Line 24  Line 24 
24  #include "LFOBase.h"  #include "LFOBase.h"
25    
26  // amplitue of 2nd harmonic (to approximate the triangular wave)  // amplitue of 2nd harmonic (to approximate the triangular wave)
27  // TODO: this was just a quick head calculation, needs to be recalculated exactly (DFT)  #define AMP2    0.11425509f
 #define AMP2    0.1f  
28    
29  namespace LinuxSampler {  namespace LinuxSampler {
30    
# Line 58  namespace LinuxSampler { Line 57  namespace LinuxSampler {
57                  real2 -= c2 * imag2;                  real2 -= c2 * imag2;
58                  imag2 += c2 * real2;                  imag2 += c2 * real2;
59                  if (RANGE == range_unsigned)                  if (RANGE == range_unsigned)
60                      return (real1 + real2 * AMP2) * normalizer + normalizer;                      return (real1 + real2 * AMP2) * normalizer + offset;
61                  else /* signed range */                  else /* signed range */
62                      return (real1 + real2 * AMP2) * normalizer;                      return (real1 + real2 * AMP2) * normalizer;
63              }              }
# Line 70  namespace LinuxSampler { Line 69  namespace LinuxSampler {
69               */               */
70              inline void update(const uint16_t& ExtControlValue) {              inline void update(const uint16_t& ExtControlValue) {
71                  const float max = this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff;                  const float max = this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff;
72                  if (RANGE == range_unsigned)                  if (RANGE == range_unsigned) {
73                        const float harmonicCompensation = 1.0f + AMP2; // to compensate the compensation ;) (see trigger())
74                      normalizer = max * 0.5f;                      normalizer = max * 0.5f;
75                  else /* signed range */                      offset     = normalizer * harmonicCompensation;
76                    } else { // signed range
77                      normalizer = max;                      normalizer = max;
78                    }
79              }              }
80    
81              /**              /**
# Line 85  namespace LinuxSampler { Line 87  namespace LinuxSampler {
87               * @param ExtControlDepth - defines how strong the external MIDI               * @param ExtControlDepth - defines how strong the external MIDI
88               *                          controller has influence on the               *                          controller has influence on the
89               *                          oscillator amplitude               *                          oscillator amplitude
90               * @param FlipPhase       - inverts the oscillator wave               * @param FlipPhase       - inverts the oscillator wave against
91                 *                          a horizontal axis
92               * @param SampleRate      - current sample rate of the engines               * @param SampleRate      - current sample rate of the engines
93               *                          audio output signal               *                          audio output signal
94               */               */
95              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) {
96                  this->InternalDepth        = (InternalDepth / 1200.0f) * this->Max;                  const float harmonicCompensation = 1.0f + AMP2; // to compensate the 2nd harmonic's amplitude overhead
97                  this->ExtControlDepthCoeff = (((float) ExtControlDepth / 1200.0f) / 127.0f) * this->Max;                  this->InternalDepth        = (InternalDepth / 1200.0f) * this->Max / harmonicCompensation;
98                    this->ExtControlDepthCoeff = (((float) ExtControlDepth / 1200.0f) / 127.0f) * this->Max / harmonicCompensation;
99    
100                  c1 = 2.0f * M_PI * Frequency / (float) SampleRate;                  c1 = 2.0f * M_PI * Frequency / (float) SampleRate;
101                  c2 = 2.0f * M_PI * Frequency / (float) SampleRate * 3.0f;                  c2 = 2.0f * M_PI * Frequency / (float) SampleRate * 3.0f;
102    
103                  float phi; // phase displacement                  double phi; // phase displacement
104                  switch (StartLevel) {                  switch (StartLevel) {
                     case start_level_max:  
                         phi = 0.0f; // 0°  
                         break;  
105                      case start_level_mid:                      case start_level_mid:
106                          phi = (FlipPhase) ? 3.0f * M_PI : M_PI; // 270° or 90°                          //FIXME: direct jumping to 90° and 270° doesn't work out due to numeric accuracy problems (causes wave deformation)
107                            //phi = (FlipPhase) ? 0.5 * M_PI : 1.5 * M_PI; // 90° or 270°
108                            //break;
109                        case start_level_max:
110                            phi = (FlipPhase) ? M_PI : 0.0; // 180° or 0°
111                          break;                          break;
112                      case start_level_min:                      case start_level_min:
113                          phi = 2.0f * M_PI; // 180°                          phi = (FlipPhase) ? 0.0 : M_PI; // 0° or 180°
114                          break;                          break;
115                  }                  }
116                  real1 = real2 = cos(phi);                  real1 = real2 = cos(phi);
# Line 120  namespace LinuxSampler { Line 125  namespace LinuxSampler {
125              float real2;              float real2;
126              float imag2;              float imag2;
127              float normalizer;              float normalizer;
128                float offset;
129      };      };
130    
131  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.720  
changed lines
  Added in v.721

  ViewVC Help
Powered by ViewVC