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 Christian Schoenebeck * |
* Copyright (C) 2005, 2006 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 * |
75 |
return pCentsToFreqTable[index_int] + index_fract * (pCentsToFreqTable[index_int+1] - pCentsToFreqTable[index_int]); |
return pCentsToFreqTable[index_int] + index_fract * (pCentsToFreqTable[index_int+1] - pCentsToFreqTable[index_int]); |
76 |
} |
} |
77 |
|
|
78 |
|
/** |
79 |
|
* Inverse function to CentsToFreqRatio(). This function is a bit |
80 |
|
* slow, so it should not be called too frequently. |
81 |
|
*/ |
82 |
|
static double FreqRatioToCents(double FreqRatio) { |
83 |
|
return log(FreqRatio) / log(TWELVEHUNDREDTH_ROOT_OF_TWO); |
84 |
|
} |
85 |
|
|
86 |
private: |
private: |
87 |
static float CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; |
static float CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; |
88 |
static float* pCentsToFreqTable; |
static float* pCentsToFreqTable; |
103 |
// conversion using truncate |
// conversion using truncate |
104 |
inline static int Int(const float a) { |
inline static int Int(const float a) { |
105 |
switch (IMPL) { |
switch (IMPL) { |
106 |
case CPP: { |
#if CONFIG_ASM && ARCH_X86 |
|
return (int) a; |
|
|
} |
|
|
#if ARCH_X86 |
|
107 |
case ASM_X86_MMX_SSE: { |
case ASM_X86_MMX_SSE: { |
108 |
int ret; |
int ret; |
109 |
asm ( |
asm ( |
113 |
); |
); |
114 |
return ret; |
return ret; |
115 |
} |
} |
116 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
117 |
|
default: { |
118 |
|
return (int) a; |
119 |
|
} |
120 |
} |
} |
121 |
} |
} |
122 |
|
|
127 |
|
|
128 |
inline static float Float(const int a) { |
inline static float Float(const int a) { |
129 |
switch (IMPL) { |
switch (IMPL) { |
130 |
case CPP: { |
#if CONFIG_ASM && ARCH_X86 |
|
return (float) a; |
|
|
} |
|
|
#if ARCH_X86 |
|
131 |
case ASM_X86_MMX_SSE: { |
case ASM_X86_MMX_SSE: { |
132 |
float ret; |
float ret; |
133 |
asm ( |
asm ( |
138 |
); |
); |
139 |
return ret; |
return ret; |
140 |
} |
} |
141 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
142 |
|
default: { |
143 |
|
return (float) a; |
144 |
|
} |
145 |
} |
} |
146 |
} |
} |
147 |
|
|
154 |
|
|
155 |
inline static float Sum(const float& a, const float& b) { |
inline static float Sum(const float& a, const float& b) { |
156 |
switch (IMPL) { |
switch (IMPL) { |
157 |
case CPP: { |
#if CONFIG_ASM && ARCH_X86 |
|
return (a + b); |
|
|
} |
|
|
#if ARCH_X86 |
|
158 |
case ASM_X86_MMX_SSE: { |
case ASM_X86_MMX_SSE: { |
159 |
float ret; |
float ret; |
160 |
asm ( |
asm ( |
166 |
); |
); |
167 |
return ret; |
return ret; |
168 |
} |
} |
169 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
170 |
|
default: { |
171 |
|
return (a + b); |
172 |
|
} |
173 |
} |
} |
174 |
} |
} |
175 |
|
|
179 |
|
|
180 |
inline static float Sub(const float& a, const float& b) { |
inline static float Sub(const float& a, const float& b) { |
181 |
switch (IMPL) { |
switch (IMPL) { |
182 |
case CPP: { |
#if CONFIG_ASM && ARCH_X86 |
|
return (a - b); |
|
|
} |
|
|
#if ARCH_X86 |
|
183 |
case ASM_X86_MMX_SSE: { |
case ASM_X86_MMX_SSE: { |
184 |
float ret; |
float ret; |
185 |
asm ( |
asm ( |
191 |
); |
); |
192 |
return ret; |
return ret; |
193 |
} |
} |
194 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
195 |
|
default: { |
196 |
|
return (a - b); |
197 |
|
} |
198 |
} |
} |
199 |
} |
} |
200 |
|
|
204 |
|
|
205 |
inline static float Mul(const float a, const float b) { |
inline static float Mul(const float a, const float b) { |
206 |
switch (IMPL) { |
switch (IMPL) { |
207 |
case CPP: { |
#if CONFIG_ASM && ARCH_X86 |
|
return (a * b); |
|
|
} |
|
|
#if ARCH_X86 |
|
208 |
case ASM_X86_MMX_SSE: { |
case ASM_X86_MMX_SSE: { |
209 |
float ret; |
float ret; |
210 |
asm ( |
asm ( |
216 |
); |
); |
217 |
return ret; |
return ret; |
218 |
} |
} |
219 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
220 |
|
default: { |
221 |
|
return (a * b); |
222 |
|
} |
223 |
} |
} |
224 |
} |
} |
225 |
|
|
229 |
|
|
230 |
inline static float Div(const float a, const float b) { |
inline static float Div(const float a, const float b) { |
231 |
switch (IMPL) { |
switch (IMPL) { |
232 |
case CPP: { |
#if CONFIG_ASM && ARCH_X86 |
|
return (a / b); |
|
|
} |
|
|
#if ARCH_X86 |
|
233 |
case ASM_X86_MMX_SSE: { |
case ASM_X86_MMX_SSE: { |
234 |
float ret; |
float ret; |
235 |
asm ( |
asm ( |
241 |
); |
); |
242 |
return ret; |
return ret; |
243 |
} |
} |
244 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
245 |
|
default: { |
246 |
|
return (a / b); |
247 |
|
} |
248 |
} |
} |
249 |
} |
} |
250 |
|
|
254 |
|
|
255 |
inline static float Min(const float a, const float b) { |
inline static float Min(const float a, const float b) { |
256 |
switch (IMPL) { |
switch (IMPL) { |
257 |
case CPP: { |
#if CONFIG_ASM && ARCH_X86 |
|
return (b < a) ? b : a; |
|
|
} |
|
|
#if ARCH_X86 |
|
258 |
case ASM_X86_MMX_SSE: { |
case ASM_X86_MMX_SSE: { |
259 |
float ret; |
float ret; |
260 |
asm ( |
asm ( |
266 |
); |
); |
267 |
return ret; |
return ret; |
268 |
} |
} |
269 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
270 |
|
default: { |
271 |
|
return std::min(a, b); |
272 |
|
} |
273 |
} |
} |
274 |
} |
} |
275 |
|
|
279 |
|
|
280 |
inline static float Max(const float a, const float b) { |
inline static float Max(const float a, const float b) { |
281 |
switch (IMPL) { |
switch (IMPL) { |
282 |
case CPP: { |
#if CONFIG_ASM && ARCH_X86 |
|
return (b > a) ? b : a; |
|
|
} |
|
|
#if ARCH_X86 |
|
283 |
case ASM_X86_MMX_SSE: { |
case ASM_X86_MMX_SSE: { |
284 |
float ret; |
float ret; |
285 |
asm ( |
asm ( |
291 |
); |
); |
292 |
return ret; |
return ret; |
293 |
} |
} |
294 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
295 |
|
default: { |
296 |
|
return std::max(a, b); |
297 |
|
} |
298 |
} |
} |
299 |
} |
} |
300 |
|
|
304 |
|
|
305 |
inline static float Fmodf(const float &a, const float &b) { |
inline static float Fmodf(const float &a, const float &b) { |
306 |
switch (IMPL) { |
switch (IMPL) { |
307 |
case CPP: { |
#if CONFIG_ASM && ARCH_X86 |
|
return fmodf(a, b); |
|
|
} |
|
|
#if ARCH_X86 |
|
308 |
case ASM_X86_MMX_SSE: { |
case ASM_X86_MMX_SSE: { |
309 |
float ret; |
float ret; |
310 |
asm ( |
asm ( |
323 |
); |
); |
324 |
return ret; |
return ret; |
325 |
} |
} |
326 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
327 |
|
default: { |
328 |
|
return fmodf(a, b); |
329 |
|
} |
330 |
} |
} |
331 |
} |
} |
332 |
}; |
}; |