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 "../../common/global.h" |
#include "../../common/global.h" |
28 |
|
|
29 |
#if DEBUG_HEADERS |
#include <gig.h> |
|
# warning Filter.h included |
|
|
#endif // DEBUG_HEADERS |
|
30 |
|
|
31 |
#include "../common/BiquadFilter.h" |
#include "../common/BiquadFilter.h" |
32 |
|
|
33 |
// TODO: Gigasampler's "Turbo Lowpass" and "Bandreject" filters not implemented yet |
// TODO: Gigasampler's "Turbo Lowpass" and "Bandreject" filters not implemented yet |
34 |
|
|
|
#include "../../lib/fileloader/libgig/gig.h" |
|
|
|
|
35 |
#define LSF_BW 0.9 |
#define LSF_BW 0.9 |
36 |
#define LSF_FB 0.9f |
#define LSF_FB 0.9f |
37 |
|
|
51 |
bq_t resonance; |
bq_t resonance; |
52 |
bq_t cutoff; |
bq_t cutoff; |
53 |
::gig::vcf_type_t Type; |
::gig::vcf_type_t Type; |
54 |
|
#if __GNUC__ >= 4 |
55 |
|
float fFB; |
56 |
|
#else |
57 |
static const float fFB = LSF_FB; |
static const float fFB = LSF_FB; |
58 |
|
#endif |
59 |
|
|
60 |
public: |
public: |
61 |
|
|
62 |
Filter() { |
Filter() { |
63 |
// set filter type to 'lowpass' by default |
// set filter type to 'lowpass' by default |
64 |
pFilter = &LPFilter; |
pFilter = &LPFilter; |
65 |
Type = ::gig::vcf_type_lowpass; |
Type = ::gig::vcf_type_lowpass; |
66 |
|
#if __GNUC__ >= 4 |
67 |
|
fFB = LSF_FB; |
68 |
|
#endif |
69 |
} |
} |
70 |
|
|
71 |
inline bq_t Cutoff() { return cutoff; } |
inline bq_t Cutoff() { return cutoff; } |
96 |
BasicBPFilter.SetParameters(cutoff, 0.7, fs); |
BasicBPFilter.SetParameters(cutoff, 0.7, fs); |
97 |
switch (Type) { |
switch (Type) { |
98 |
case ::gig::vcf_type_highpass: |
case ::gig::vcf_type_highpass: |
99 |
HPFilter.SetParameters(cutoff, 1.0 - resonance * LSF_BW, fs); |
HPFilter.SetParameters(cutoff, 1.87 - resonance * 1.7526, fs); |
100 |
break; |
break; |
101 |
case ::gig::vcf_type_bandpass: |
case ::gig::vcf_type_bandpass: |
102 |
BPFilter.SetParameters(cutoff, 1.0 - resonance * LSF_BW, fs); |
BPFilter.SetParameters(cutoff, 1.87 - resonance * 1.7526, fs); |
103 |
break; |
break; |
104 |
case ::gig::vcf_type_lowpass: |
case ::gig::vcf_type_lowpass: |
105 |
LPFilter.SetParameters(cutoff, 1.0 - resonance * LSF_BW, fs); |
LPFilter.SetParameters(cutoff, 1.87 - resonance * 1.7526, fs); |
106 |
break; |
break; |
107 |
} |
} |
108 |
this->scale = 1.0f - resonance * 0.7f; |
this->scale = resonance < 0.4 ? 1.0f : 1.4f - resonance * 1.016f; |
109 |
this->resonance = resonance; |
this->resonance = resonance; |
110 |
this->cutoff = cutoff; |
this->cutoff = cutoff; |
111 |
} |
} |
114 |
BasicBPFilter.SetParameters(base, cutoff, 0.7, fs); |
BasicBPFilter.SetParameters(base, cutoff, 0.7, fs); |
115 |
switch (Type) { |
switch (Type) { |
116 |
case ::gig::vcf_type_highpass: |
case ::gig::vcf_type_highpass: |
117 |
HPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs); |
HPFilter.SetParameters(main, cutoff, 1.87 - resonance * 1.7526, fs); |
118 |
break; |
break; |
119 |
case ::gig::vcf_type_bandpass: |
case ::gig::vcf_type_bandpass: |
120 |
BPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs); |
BPFilter.SetParameters(main, cutoff, 1.87 - resonance * 1.7526, fs); |
121 |
break; |
break; |
122 |
case ::gig::vcf_type_lowpass: |
case ::gig::vcf_type_lowpass: |
123 |
LPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs); |
LPFilter.SetParameters(main, cutoff, 1.87 - resonance * 1.7526, fs); |
124 |
break; |
break; |
125 |
} |
} |
126 |
this->scale = 1.0f - resonance * 0.7f; |
this->scale = resonance < 0.4 ? 1.0f : 1.4f - resonance * 1.016f; |
127 |
this->resonance = resonance; |
this->resonance = resonance; |
128 |
this->cutoff = cutoff; |
this->cutoff = cutoff; |
129 |
} |
} |
136 |
} |
} |
137 |
|
|
138 |
inline bq_t Apply(const bq_t in) { |
inline bq_t Apply(const bq_t in) { |
139 |
return pFilter->Apply(in) * this->scale + |
return pFilter->Apply(in) * this->scale; |
140 |
BasicBPFilter.ApplyFB(in, this->resonance * LSF_FB) * this->resonance; |
// + BasicBPFilter.ApplyFB(in, this->resonance * LSF_FB) * this->resonance; |
141 |
} |
} |
142 |
|
|
143 |
inline bq_t Apply(biquad_param_t* base, biquad_param_t* main, const bq_t in) { |
inline bq_t Apply(biquad_param_t* base, biquad_param_t* main, const bq_t in) { |
144 |
return pFilter->Apply(main, in) * this->scale + |
return pFilter->Apply(main, in) * this->scale; |
145 |
BasicBPFilter.ApplyFB(base, in, this->resonance * LSF_FB) * this->resonance; |
// + BasicBPFilter.ApplyFB(base, in, this->resonance * LSF_FB) * this->resonance; |
146 |
} |
} |
147 |
|
|
148 |
#if ARCH_X86 |
#if CONFIG_ASM && ARCH_X86 |
149 |
// expects to find input in xmm0 and leaves output in xmm7 |
// expects to find input in xmm0 and leaves output in xmm7 |
150 |
inline void Apply4StepsSSE(biquad_param_t* base, biquad_param_t* main) { |
inline void Apply4StepsSSE(biquad_param_t* base, biquad_param_t* main) { |
151 |
float fb; |
float fb; |
173 |
:: "m" (scale) /* %0 */ |
:: "m" (scale) /* %0 */ |
174 |
); |
); |
175 |
} |
} |
176 |
#endif // ARCH_X86 |
#endif // CONFIG_ASM && ARCH_X86 |
177 |
|
|
178 |
}; |
}; |
179 |
|
|