1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* Copyright (C) 2005 Christian Schoenebeck * |
* Copyright (C) 2005, 2008 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 * |
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 |
#define AMP2 0.11425509f |
#define AMP2 -0.11425509f |
28 |
|
|
29 |
namespace LinuxSampler { |
namespace LinuxSampler { |
30 |
|
|
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()) |
const float harmonicCompensation = 1.0f + fabsf(AMP2); // to compensate the compensation ;) (see trigger()) |
74 |
normalizer = max * 0.5f; |
normalizer = max * 0.5f; |
75 |
offset = normalizer * harmonicCompensation; |
offset = normalizer * harmonicCompensation; |
76 |
} else { // signed range |
} else { // signed range |
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 |
const float harmonicCompensation = 1.0f + AMP2; // to compensate the 2nd harmonic's amplitude overhead |
const float harmonicCompensation = 1.0f + fabsf(AMP2); // to compensate the 2nd harmonic's amplitude overhead |
97 |
this->InternalDepth = (InternalDepth / 1200.0f) * this->Max / harmonicCompensation; |
this->InternalDepth = (InternalDepth / 1200.0f) * this->Max / harmonicCompensation; |
98 |
this->ExtControlDepthCoeff = (((float) ExtControlDepth / 1200.0f) / 127.0f) * this->Max / harmonicCompensation; |
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; |