27 |
#include "../../common/global.h" |
#include "../../common/global.h" |
28 |
|
|
29 |
// 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 |
30 |
|
// TODO: cubic interpolation is not supported for 24 bit samples |
31 |
#ifndef USE_LINEAR_INTERPOLATION |
#ifndef USE_LINEAR_INTERPOLATION |
32 |
# define USE_LINEAR_INTERPOLATION 1 ///< set to 0 if you prefer cubic interpolation (slower, better quality) |
# define USE_LINEAR_INTERPOLATION 1 ///< set to 0 if you prefer cubic interpolation (slower, better quality) |
33 |
#endif |
#endif |
50 |
* for linear and cubic interpolation for pitching a mono or stereo |
* for linear and cubic interpolation for pitching a mono or stereo |
51 |
* input signal. |
* input signal. |
52 |
*/ |
*/ |
53 |
template<bool INTERPOLATE> |
template<bool INTERPOLATE,bool BITDEPTH24> |
54 |
class Resampler { |
class Resampler { |
55 |
public: |
public: |
56 |
inline static float GetNextSampleMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) { |
inline static float GetNextSampleMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) { |
147 |
|
|
148 |
protected: |
protected: |
149 |
|
|
150 |
|
static int getSample(sample_t* src, int pos) { |
151 |
|
if (BITDEPTH24) { |
152 |
|
pos *= 3; |
153 |
|
unsigned char* p = (unsigned char*)src; |
154 |
|
return p[pos] << 8 | p[pos + 1] << 16 | p[pos + 2] << 24; |
155 |
|
} else { |
156 |
|
return src[pos]; |
157 |
|
} |
158 |
|
} |
159 |
|
|
160 |
inline static float Interpolate1StepMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) { |
inline static float Interpolate1StepMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) { |
161 |
int pos_int = (int) *Pos; // integer position |
int pos_int = (int) *Pos; // integer position |
162 |
float pos_fract = *Pos - pos_int; // fractional part of position |
float pos_fract = *Pos - pos_int; // fractional part of position |
163 |
|
|
164 |
#if USE_LINEAR_INTERPOLATION |
#if USE_LINEAR_INTERPOLATION |
165 |
float samplePoint = pSrc[pos_int] + pos_fract * (pSrc[pos_int+1] - pSrc[pos_int]); |
int x1 = getSample(pSrc, pos_int); |
166 |
|
int x2 = getSample(pSrc, pos_int + 1); |
167 |
|
float samplePoint = (x1 + pos_fract * (x2 - x1)); |
168 |
#else // polynomial interpolation |
#else // polynomial interpolation |
169 |
float xm1 = pSrc[pos_int]; |
float xm1 = pSrc[pos_int]; |
170 |
float x0 = pSrc[pos_int+1]; |
float x0 = pSrc[pos_int+1]; |
189 |
|
|
190 |
#if USE_LINEAR_INTERPOLATION |
#if USE_LINEAR_INTERPOLATION |
191 |
// left channel |
// left channel |
192 |
samplePoint.left = pSrc[pos_int] + pos_fract * (pSrc[pos_int+2] - pSrc[pos_int]); |
int x1 = getSample(pSrc, pos_int); |
193 |
|
int x2 = getSample(pSrc, pos_int + 2); |
194 |
|
samplePoint.left = (x1 + pos_fract * (x2 - x1)); |
195 |
// right channel |
// right channel |
196 |
samplePoint.right = pSrc[pos_int+1] + pos_fract * (pSrc[pos_int+3] - pSrc[pos_int+1]); |
x1 = getSample(pSrc, pos_int + 1); |
197 |
|
x2 = getSample(pSrc, pos_int + 3); |
198 |
|
samplePoint.right = (x1 + pos_fract * (x2 - x1)); |
199 |
#else // polynomial interpolation |
#else // polynomial interpolation |
200 |
// calculate left channel |
// calculate left channel |
201 |
float xm1 = pSrc[pos_int]; |
float xm1 = pSrc[pos_int]; |