/[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 3611 by schoenebeck, Fri Aug 23 11:44:00 2019 UTC revision 3612 by schoenebeck, Mon Sep 30 18:03:43 2019 UTC
# Line 33  namespace LinuxSampler { Line 33  namespace LinuxSampler {
33       * This is a triangle Low Frequency Oscillator implementation which uses       * This is a triangle Low Frequency Oscillator implementation which uses
34       * a di-harmonic solution. This means it sums up two harmonics       * a di-harmonic solution. This means it sums up two harmonics
35       * (sinusoids) to approximate a triangular wave.       * (sinusoids) to approximate a triangular wave.
36         *
37         * @deprecated This class will probably be removed in future. Reason: The
38         * resulting wave form is not similar enough to a triangular wave. to
39         * achieve a more appropriate triangular wave form, this class would need
40         * to use more harmonics, but that in turn would make runtime performance of
41         * this class even worse. And since it currently seems to perform worst
42         * already among all triangular wave implementations on all known
43         * architectures, doing that required harmonics change currently does not
44         * make sense. Furthermore the detailed behaviour of the other triangular
45         * LFO implementations had been fixed in the meantime; this one not.
46       */       */
47      template<range_type_t RANGE>      template<LFO::range_type_t RANGE>
48      class LFOTriangleDiHarmonic : public LFOBase<RANGE> {      class DEPRECATED_API LFOTriangleDiHarmonic : public LFOBase<RANGE> {
49          public:          public:
50    
51              /**              /**
# Line 56  namespace LinuxSampler { Line 66  namespace LinuxSampler {
66                  imag1 += c1 * real1;                  imag1 += c1 * real1;
67                  real2 -= c2 * imag2;                  real2 -= c2 * imag2;
68                  imag2 += c2 * real2;                  imag2 += c2 * real2;
69                  if (RANGE == range_unsigned)                  if (RANGE == LFO::range_unsigned)
70                      return (real1 + real2 * AMP2) * normalizer + offset;                      return (real1 + real2 * AMP2) * normalizer + offset;
71                  else /* signed range */                  else /* signed range */
72                      return (real1 + real2 * AMP2) * normalizer;                      return (real1 + real2 * AMP2) * normalizer;
# Line 71  namespace LinuxSampler { Line 81  namespace LinuxSampler {
81                  this->ExtControlValue = ExtControlValue;                  this->ExtControlValue = ExtControlValue;
82    
83                  const float max = (this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff) * this->ScriptDepthFactor;                  const float max = (this->InternalDepth + ExtControlValue * this->ExtControlDepthCoeff) * this->ScriptDepthFactor;
84                  if (RANGE == range_unsigned) {                  if (RANGE == LFO::range_unsigned) {
85                      const float harmonicCompensation = 1.0f + fabsf(AMP2); // to compensate the compensation ;) (see trigger())                      const float harmonicCompensation = 1.0f + fabsf(AMP2); // to compensate the compensation ;) (see trigger())
86                      normalizer = max * 0.5f;                      normalizer = max * 0.5f;
87                      offset     = normalizer * harmonicCompensation;                      offset     = normalizer * harmonicCompensation;
# Line 94  namespace LinuxSampler { Line 104  namespace LinuxSampler {
104               * @param SampleRate      - current sample rate of the engines               * @param SampleRate      - current sample rate of the engines
105               *                          audio output signal               *                          audio output signal
106               */               */
107              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) {
108                  this->Frequency = Frequency;                  this->Frequency = Frequency;
109                  this->ScriptFrequencyFactor = this->ScriptDepthFactor = 1.f; // reset for new voice                  this->ScriptFrequencyFactor = this->ScriptDepthFactor = 1.f; // reset for new voice
110                  const float harmonicCompensation = 1.0f + fabsf(AMP2); // to compensate the 2nd harmonic's amplitude overhead                  const float harmonicCompensation = 1.0f + fabsf(AMP2); // to compensate the 2nd harmonic's amplitude overhead
# Line 109  namespace LinuxSampler { Line 119  namespace LinuxSampler {
119    
120                  double phi; // phase displacement                  double phi; // phase displacement
121                  switch (StartLevel) {                  switch (StartLevel) {
122                      case start_level_mid:                      case LFO::start_level_mid:
123                          //FIXME: direct jumping to 90° and 270° doesn't work out due to numeric accuracy problems (causes wave deformation)                          //FIXME: direct jumping to 90° and 270° doesn't work out due to numeric accuracy problems (causes wave deformation)
124                          //phi = (FlipPhase) ? 0.5 * M_PI : 1.5 * M_PI; // 90° or 270°                          //phi = (FlipPhase) ? 0.5 * M_PI : 1.5 * M_PI; // 90° or 270°
125                          //break;                          //break;
126                      case start_level_max:                      case LFO::start_level_max:
127                          phi = (FlipPhase) ? M_PI : 0.0; // 180° or 0°                          phi = (FlipPhase) ? M_PI : 0.0; // 180° or 0°
128                          break;                          break;
129                      case start_level_min:                      case LFO::start_level_min:
130                          phi = (FlipPhase) ? 0.0 : M_PI; // 0° or 180°                          phi = (FlipPhase) ? 0.0 : M_PI; // 0° or 180°
131                          break;                          break;
132                  }                  }

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

  ViewVC Help
Powered by ViewVC