32 |
#include "../../common/RTMath.h" |
#include "../../common/RTMath.h" |
33 |
#include "../../common/RingBuffer.h" |
#include "../../common/RingBuffer.h" |
34 |
#include "../../common/RTELMemoryPool.h" |
#include "../../common/RTELMemoryPool.h" |
35 |
#include "../../audiodriver/AudioOutputDevice.h" |
#include "../../drivers/audio/AudioOutputDevice.h" |
36 |
#include "../../lib/fileloader/libgig/gig.h" |
#include "../../lib/fileloader/libgig/gig.h" |
37 |
#include "../common/BiquadFilter.h" |
#include "../common/BiquadFilter.h" |
38 |
#include "Engine.h" |
#include "Engine.h" |
156 |
float pos_fract = this->Pos - pos_int; // fractional part of position |
float pos_fract = this->Pos - pos_int; // fractional part of position |
157 |
pos_int <<= 1; |
pos_int <<= 1; |
158 |
|
|
|
#if 0 //ENABLE_FILTER |
|
|
UpdateFilter_Stereo(cutoff + FILTER_CUTOFF_MIN, resonance); |
|
|
#endif // ENABLE_FILTER |
|
|
|
|
159 |
#if USE_LINEAR_INTERPOLATION |
#if USE_LINEAR_INTERPOLATION |
160 |
#if ENABLE_FILTER |
#if ENABLE_FILTER |
161 |
// left channel |
// left channel |
174 |
float x0 = pSrc[pos_int+2]; |
float x0 = pSrc[pos_int+2]; |
175 |
float x1 = pSrc[pos_int+4]; |
float x1 = pSrc[pos_int+4]; |
176 |
float x2 = pSrc[pos_int+6]; |
float x2 = pSrc[pos_int+6]; |
177 |
float a = (3 * (x0 - x1) - xm1 + x2) / 2; |
float a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f; |
178 |
float b = 2 * x1 + xm1 - (5 * x0 + x2) / 2; |
float b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f; |
179 |
float c = (x1 - xm1) / 2; |
float c = (x1 - xm1) * 0.5f; |
180 |
#if ENABLE_FILTER |
#if ENABLE_FILTER |
181 |
pOutputLeft[i] += this->FilterLeft.Apply(&bq_base, &bq_main, effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0)); |
pOutputLeft[i] += this->FilterLeft.Apply(&bq_base, &bq_main, effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0)); |
182 |
#else // no filter |
#else // no filter |
183 |
pOutputRight[i] += effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0); |
pOutputLeft[i] += effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0); |
184 |
#endif // ENABLE_FILTER |
#endif // ENABLE_FILTER |
185 |
|
|
186 |
//calculate right channel |
//calculate right channel |
188 |
x0 = pSrc[pos_int+3]; |
x0 = pSrc[pos_int+3]; |
189 |
x1 = pSrc[pos_int+5]; |
x1 = pSrc[pos_int+5]; |
190 |
x2 = pSrc[pos_int+7]; |
x2 = pSrc[pos_int+7]; |
191 |
a = (3 * (x0 - x1) - xm1 + x2) / 2; |
a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f; |
192 |
b = 2 * x1 + xm1 - (5 * x0 + x2) / 2; |
b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f; |
193 |
c = (x1 - xm1) / 2; |
c = (x1 - xm1) * 0.5f; |
194 |
#if ENABLE_FILTER |
#if ENABLE_FILTER |
195 |
pOutputLeft[i++] += this->FilterRight.Apply(&bq_base, &bq_main, effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0)); |
pOutputRight[i++] += this->FilterRight.Apply(&bq_base, &bq_main, effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0)); |
196 |
#else // no filter |
#else // no filter |
197 |
pOutputRight[i++] += effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0); |
pOutputRight[i++] += effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0); |
198 |
#endif // ENABLE_FILTER |
#endif // ENABLE_FILTER |
200 |
|
|
201 |
this->Pos += pitch; |
this->Pos += pitch; |
202 |
} |
} |
203 |
|
|
204 |
inline void InterpolateOneStep_Mono(sample_t* pSrc, int& i, float& effective_volume, float& pitch, biquad_param_t& bq_base, biquad_param_t& bq_main) { |
inline void InterpolateOneStep_Mono(sample_t* pSrc, int& i, float& effective_volume, float& pitch, biquad_param_t& bq_base, biquad_param_t& bq_main) { |
205 |
int pos_int = RTMath::DoubleToInt(this->Pos); // integer position |
int pos_int = RTMath::DoubleToInt(this->Pos); // integer position |
206 |
float pos_fract = this->Pos - pos_int; // fractional part of position |
float pos_fract = this->Pos - pos_int; // fractional part of position |
207 |
|
|
|
#if 0 //ENABLE_FILTER |
|
|
UpdateFilter_Mono(cutoff + FILTER_CUTOFF_MIN, resonance); |
|
|
#endif // ENABLE_FILTER |
|
|
|
|
208 |
#if USE_LINEAR_INTERPOLATION |
#if USE_LINEAR_INTERPOLATION |
209 |
float sample_point = effective_volume * (pSrc[pos_int] + pos_fract * (pSrc[pos_int+1] - pSrc[pos_int])); |
float sample_point = effective_volume * (pSrc[pos_int] + pos_fract * (pSrc[pos_int+1] - pSrc[pos_int])); |
210 |
#else // polynomial interpolation |
#else // polynomial interpolation |
212 |
float x0 = pSrc[pos_int+1]; |
float x0 = pSrc[pos_int+1]; |
213 |
float x1 = pSrc[pos_int+2]; |
float x1 = pSrc[pos_int+2]; |
214 |
float x2 = pSrc[pos_int+3]; |
float x2 = pSrc[pos_int+3]; |
215 |
float a = (3 * (x0 - x1) - xm1 + x2) / 2; |
float a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f; |
216 |
float b = 2 * x1 + xm1 - (5 * x0 + x2) / 2; |
float b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f; |
217 |
float c = (x1 - xm1) / 2; |
float c = (x1 - xm1) * 0.5f; |
218 |
float sample_point = effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0); |
float sample_point = effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0); |
219 |
#endif // USE_LINEAR_INTERPOLATION |
#endif // USE_LINEAR_INTERPOLATION |
220 |
|
|
227 |
|
|
228 |
this->Pos += pitch; |
this->Pos += pitch; |
229 |
} |
} |
230 |
#if 0 |
|
|
inline void UpdateFilter_Stereo(float cutoff, float& resonance) { |
|
|
if (!(++FilterUpdateCounter % FILTER_UPDATE_PERIOD) && (cutoff != FilterLeft.Cutoff() || resonance != FilterLeft.Resonance())) { |
|
|
FilterLeft.SetParameters(cutoff, resonance, SampleRate); |
|
|
FilterRight.SetParameters(cutoff, resonance, SampleRate); |
|
|
} |
|
|
} |
|
|
inline void UpdateFilter_Mono(float cutoff, float& resonance) { |
|
|
if (!(++FilterUpdateCounter % FILTER_UPDATE_PERIOD) && (cutoff != FilterLeft.Cutoff() || resonance != FilterLeft.Resonance())) { |
|
|
FilterLeft.SetParameters(cutoff, resonance, SampleRate); |
|
|
} |
|
|
} |
|
|
#endif |
|
231 |
inline float Constrain(float ValueToCheck, float Min, float Max) { |
inline float Constrain(float ValueToCheck, float Min, float Max) { |
232 |
if (ValueToCheck > Max) ValueToCheck = Max; |
if (ValueToCheck > Max) ValueToCheck = Max; |
233 |
else if (ValueToCheck < Min) ValueToCheck = Min; |
else if (ValueToCheck < Min) ValueToCheck = Min; |