3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* 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 * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
|
// Note: the assembly code is currently disabled, as it doesn't fit into |
25 |
|
// the new synthesis core introduced by LS 0.4.0 |
26 |
|
|
27 |
#ifndef __LS_RESAMPLER_H__ |
#ifndef __LS_RESAMPLER_H__ |
28 |
#define __LS_RESAMPLER_H__ |
#define __LS_RESAMPLER_H__ |
29 |
|
|
30 |
#include "../../common/global.h" |
#include "../../common/global_private.h" |
31 |
|
|
32 |
// TODO: cubic interpolation is not yet supported by the MMX/SSE(1) version though |
// TODO: cubic interpolation is not yet supported by the MMX/SSE(1) version though |
33 |
#ifndef USE_LINEAR_INTERPOLATION |
#ifndef USE_LINEAR_INTERPOLATION |
52 |
* for linear and cubic interpolation for pitching a mono or stereo |
* for linear and cubic interpolation for pitching a mono or stereo |
53 |
* input signal. |
* input signal. |
54 |
*/ |
*/ |
55 |
template<bool INTERPOLATE> |
template<bool INTERPOLATE,bool BITDEPTH24> |
56 |
class Resampler { |
class Resampler { |
57 |
public: |
public: |
58 |
inline static float GetNextSampleMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) { |
inline static float GetNextSampleMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) { |
77 |
} |
} |
78 |
} |
} |
79 |
|
|
80 |
#if ARCH_X86 |
#if 0 // CONFIG_ASM && ARCH_X86 |
81 |
inline static void GetNext4SamplesMonoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) { |
inline static void GetNext4SamplesMonoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) { |
82 |
if (INTERPOLATE) Interpolate4StepsMonoMMXSSE(pSrc, Pos, Pitch); |
if (INTERPOLATE) Interpolate4StepsMonoMMXSSE(pSrc, Pos, Pitch); |
83 |
else { // no pitch, so no interpolation necessary |
else { // no pitch, so no interpolation necessary |
145 |
); |
); |
146 |
} |
} |
147 |
} |
} |
148 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
149 |
|
|
150 |
protected: |
protected: |
151 |
|
|
152 |
|
inline static int32_t getSample(sample_t* src, int pos) { |
153 |
|
if (BITDEPTH24) { |
154 |
|
pos *= 3; |
155 |
|
#if WORDS_BIGENDIAN |
156 |
|
unsigned char* p = (unsigned char*)src; |
157 |
|
return p[pos] << 8 | p[pos + 1] << 16 | p[pos + 2] << 24; |
158 |
|
#else |
159 |
|
// 24bit read optimization: |
160 |
|
// a misaligned 32bit read and subquent 8 bit shift is faster (on x86) than reading 3 single bytes and shifting them |
161 |
|
return (*((int32_t *)(&((char *)(src))[pos])))<<8; |
162 |
|
#endif |
163 |
|
} else { |
164 |
|
return src[pos]; |
165 |
|
} |
166 |
|
} |
167 |
|
|
168 |
inline static float Interpolate1StepMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) { |
inline static float Interpolate1StepMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) { |
169 |
int pos_int = (int) *Pos; // integer position |
int pos_int = (int) *Pos; // integer position |
170 |
float pos_fract = *Pos - pos_int; // fractional part of position |
float pos_fract = *Pos - pos_int; // fractional part of position |
171 |
|
|
172 |
#if USE_LINEAR_INTERPOLATION |
#if USE_LINEAR_INTERPOLATION |
173 |
float samplePoint = pSrc[pos_int] + pos_fract * (pSrc[pos_int+1] - pSrc[pos_int]); |
int x1 = getSample(pSrc, pos_int); |
174 |
|
int x2 = getSample(pSrc, pos_int + 1); |
175 |
|
float samplePoint = (x1 + pos_fract * (x2 - x1)); |
176 |
#else // polynomial interpolation |
#else // polynomial interpolation |
177 |
float xm1 = pSrc[pos_int]; |
float xm1 = getSample(pSrc, pos_int); |
178 |
float x0 = pSrc[pos_int+1]; |
float x0 = getSample(pSrc, pos_int + 1); |
179 |
float x1 = pSrc[pos_int+2]; |
float x1 = getSample(pSrc, pos_int + 2); |
180 |
float x2 = pSrc[pos_int+3]; |
float x2 = getSample(pSrc, pos_int + 3); |
181 |
float a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f; |
float a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f; |
182 |
float b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f; |
float b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f; |
183 |
float c = (x1 - xm1) * 0.5f; |
float c = (x1 - xm1) * 0.5f; |
197 |
|
|
198 |
#if USE_LINEAR_INTERPOLATION |
#if USE_LINEAR_INTERPOLATION |
199 |
// left channel |
// left channel |
200 |
samplePoint.left = pSrc[pos_int] + pos_fract * (pSrc[pos_int+2] - pSrc[pos_int]); |
int x1 = getSample(pSrc, pos_int); |
201 |
|
int x2 = getSample(pSrc, pos_int + 2); |
202 |
|
samplePoint.left = (x1 + pos_fract * (x2 - x1)); |
203 |
// right channel |
// right channel |
204 |
samplePoint.right = pSrc[pos_int+1] + pos_fract * (pSrc[pos_int+3] - pSrc[pos_int+1]); |
x1 = getSample(pSrc, pos_int + 1); |
205 |
|
x2 = getSample(pSrc, pos_int + 3); |
206 |
|
samplePoint.right = (x1 + pos_fract * (x2 - x1)); |
207 |
#else // polynomial interpolation |
#else // polynomial interpolation |
208 |
// calculate left channel |
// calculate left channel |
209 |
float xm1 = pSrc[pos_int]; |
float xm1 = getSample(pSrc, pos_int); |
210 |
float x0 = pSrc[pos_int+2]; |
float x0 = getSample(pSrc, pos_int + 2); |
211 |
float x1 = pSrc[pos_int+4]; |
float x1 = getSample(pSrc, pos_int + 4); |
212 |
float x2 = pSrc[pos_int+6]; |
float x2 = getSample(pSrc, pos_int + 6); |
213 |
float a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f; |
float a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f; |
214 |
float b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f; |
float b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f; |
215 |
float c = (x1 - xm1) * 0.5f; |
float c = (x1 - xm1) * 0.5f; |
216 |
samplePoint.left = (((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0; |
samplePoint.left = (((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0; |
217 |
|
|
218 |
//calculate right channel |
//calculate right channel |
219 |
xm1 = pSrc[pos_int+1]; |
xm1 = getSample(pSrc, pos_int + 1); |
220 |
x0 = pSrc[pos_int+3]; |
x0 = getSample(pSrc, pos_int + 3); |
221 |
x1 = pSrc[pos_int+5]; |
x1 = getSample(pSrc, pos_int + 5); |
222 |
x2 = pSrc[pos_int+7]; |
x2 = getSample(pSrc, pos_int + 7); |
223 |
a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f; |
a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f; |
224 |
b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f; |
b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f; |
225 |
c = (x1 - xm1) * 0.5f; |
c = (x1 - xm1) * 0.5f; |
230 |
return samplePoint; |
return samplePoint; |
231 |
} |
} |
232 |
|
|
233 |
#if ARCH_X86 |
#if 0 // CONFIG_ASM && ARCH_X86 |
234 |
// TODO: no support for cubic interpolation yet |
// TODO: no support for cubic interpolation yet |
235 |
inline static void Interpolate4StepsMonoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) { |
inline static void Interpolate4StepsMonoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) { |
236 |
/* calculate playback position of each of the 4 samples by adding the associated pitch */ |
/* calculate playback position of each of the 4 samples by adding the associated pitch */ |
433 |
"%xmm3" /* holds linear interpolated sample of right channel (of all 4 samples) at the end */ |
"%xmm3" /* holds linear interpolated sample of right channel (of all 4 samples) at the end */ |
434 |
); |
); |
435 |
} |
} |
436 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
437 |
}; |
}; |
438 |
|
|
439 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |