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 * |
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 * |
26 |
|
|
27 |
#include <math.h> |
#include <math.h> |
28 |
|
|
29 |
|
#include "../../common/global.h" |
30 |
|
|
31 |
/// ln(2) / 2 |
/// ln(2) / 2 |
32 |
#define LN_2_2 0.34657359f |
#define LN_2_2 0.34657359f |
33 |
|
|
47 |
* between multiple filters. |
* between multiple filters. |
48 |
*/ |
*/ |
49 |
struct biquad_param_t { |
struct biquad_param_t { |
|
bq_t a1; |
|
|
bq_t a2; |
|
50 |
bq_t b0; |
bq_t b0; |
51 |
bq_t b1; |
bq_t b1; |
52 |
bq_t b2; |
bq_t b2; |
53 |
|
bq_t a1; |
54 |
|
bq_t a2; |
55 |
}; |
}; |
56 |
|
|
57 |
/** |
/** |
61 |
class BiquadFilter { |
class BiquadFilter { |
62 |
protected: |
protected: |
63 |
// following five variables are only used if no external biquad_param_t reference is used |
// following five variables are only used if no external biquad_param_t reference is used |
|
bq_t a1; |
|
|
bq_t a2; |
|
64 |
bq_t b0; |
bq_t b0; |
65 |
bq_t b1; |
bq_t b1; |
66 |
bq_t b2; |
bq_t b2; |
67 |
|
bq_t a1; |
68 |
|
bq_t a2; |
69 |
// following four variables are used to buffer the feedback |
// following four variables are used to buffer the feedback |
70 |
bq_t x1; |
bq_t x1; |
71 |
bq_t x2; |
bq_t x2; |
124 |
return y; |
return y; |
125 |
} |
} |
126 |
|
|
127 |
|
#if CONFIG_ASM && ARCH_X86 |
128 |
// expects to find input in xmm0 (xmm0 stays unmodified) and finally leaves output in xmm6 |
// expects to find input in xmm0 (xmm0 stays unmodified) and finally leaves output in xmm6 |
129 |
inline void Apply4StepsSSE(biquad_param_t* param) { |
inline void Apply4StepsSSE(biquad_param_t* param) { |
130 |
__asm__ __volatile__ ( |
__asm__ __volatile__ ( |
211 |
"r" (¶m->b0) /* %2 */ |
"r" (¶m->b0) /* %2 */ |
212 |
); |
); |
213 |
} |
} |
214 |
|
#endif // CONFIG_ASM && ARCH_X86 |
215 |
|
|
216 |
inline bq_t ApplyFB(bq_t x, const bq_t fb) { |
inline bq_t ApplyFB(bq_t x, const bq_t fb) { |
217 |
bq_t y; |
bq_t y; |
243 |
return y; |
return y; |
244 |
} |
} |
245 |
|
|
246 |
|
#if CONFIG_ASM && ARCH_X86 |
247 |
// expects to find input in xmm0 (xmm0 stays unmodified) and finally leaves output in xmm7 |
// expects to find input in xmm0 (xmm0 stays unmodified) and finally leaves output in xmm7 |
248 |
inline void ApplyFB4StepsSSE(biquad_param_t* param, const bq_t &fb) { |
inline void ApplyFB4StepsSSE(biquad_param_t* param, const bq_t &fb) { |
249 |
float xs, ys; |
float xs, ys; |
439 |
:: |
:: |
440 |
); |
); |
441 |
} |
} |
442 |
|
#endif // CONFIG_ASM && ARCH_X86 |
443 |
}; |
}; |
444 |
|
|
445 |
|
/** @brief Lowpass Filter |
446 |
|
* |
447 |
|
* Lowpass filter based on biquad filter implementation. |
448 |
|
*/ |
449 |
class LowpassFilter : public BiquadFilter { |
class LowpassFilter : public BiquadFilter { |
450 |
public: |
public: |
451 |
inline LowpassFilter() : BiquadFilter() {} |
inline LowpassFilter() : BiquadFilter() {} |
479 |
} |
} |
480 |
}; |
}; |
481 |
|
|
482 |
|
/** @brief Bandpass Filter |
483 |
|
* |
484 |
|
* Bandpass filter based on biquad filter implementation. |
485 |
|
*/ |
486 |
class BandpassFilter : public BiquadFilter { |
class BandpassFilter : public BiquadFilter { |
487 |
public: |
public: |
488 |
inline BandpassFilter() : BiquadFilter() {} |
inline BandpassFilter() : BiquadFilter() {} |
516 |
} |
} |
517 |
}; |
}; |
518 |
|
|
519 |
|
/** @brief Highpass Filter |
520 |
|
* |
521 |
|
* Highpass filter based on biquad filter implementation. |
522 |
|
*/ |
523 |
class HighpassFilter : public BiquadFilter { |
class HighpassFilter : public BiquadFilter { |
524 |
public: |
public: |
525 |
inline HighpassFilter() : BiquadFilter() {} |
inline HighpassFilter() : BiquadFilter() {} |