2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* * |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
8 |
* 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 * |
41 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
42 |
|
|
43 |
/** |
/** |
44 |
* This is a filter similar to the ones from Gigasampler. |
* These are filters similar to the ones from Gigasampler. |
45 |
*/ |
*/ |
46 |
class Filter { |
class Filter { |
47 |
protected: |
protected: |
54 |
bq_t resonance; |
bq_t resonance; |
55 |
bq_t cutoff; |
bq_t cutoff; |
56 |
::gig::vcf_type_t Type; |
::gig::vcf_type_t Type; |
57 |
|
static const float fFB = LSF_FB; |
58 |
public: |
public: |
|
bool Enabled; |
|
59 |
|
|
60 |
inline Filter() { |
Filter() { |
61 |
// set filter type to 'lowpass' by default |
// set filter type to 'lowpass' by default |
62 |
pFilter = &LPFilter; |
pFilter = &LPFilter; |
63 |
Type = ::gig::vcf_type_lowpass; |
Type = ::gig::vcf_type_lowpass; |
73 |
pFilter = &HPFilter; |
pFilter = &HPFilter; |
74 |
break; |
break; |
75 |
case ::gig::vcf_type_bandreject: //TODO: not implemented yet |
case ::gig::vcf_type_bandreject: //TODO: not implemented yet |
76 |
Type = ::gig::vcf_type_bandpass; |
FilterType = ::gig::vcf_type_bandpass; |
77 |
case ::gig::vcf_type_bandpass: |
case ::gig::vcf_type_bandpass: |
78 |
pFilter = &BPFilter; |
pFilter = &BPFilter; |
79 |
break; |
break; |
80 |
case ::gig::vcf_type_lowpassturbo: //TODO: not implemented yet |
case ::gig::vcf_type_lowpassturbo: //TODO: not implemented yet |
81 |
default: |
default: |
82 |
Type = ::gig::vcf_type_lowpass; |
FilterType = ::gig::vcf_type_lowpass; |
83 |
case ::gig::vcf_type_lowpass: |
case ::gig::vcf_type_lowpass: |
84 |
pFilter = &LPFilter; |
pFilter = &LPFilter; |
85 |
|
|
105 |
this->cutoff = cutoff; |
this->cutoff = cutoff; |
106 |
} |
} |
107 |
|
|
108 |
|
inline void SetParameters(biquad_param_t* base, biquad_param_t* main, bq_t cutoff, bq_t resonance, bq_t fs) { |
109 |
|
BasicBPFilter.SetParameters(base, cutoff, 0.7, fs); |
110 |
|
switch (Type) { |
111 |
|
case ::gig::vcf_type_highpass: |
112 |
|
HPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs); |
113 |
|
break; |
114 |
|
case ::gig::vcf_type_bandpass: |
115 |
|
BPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs); |
116 |
|
break; |
117 |
|
case ::gig::vcf_type_lowpass: |
118 |
|
LPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs); |
119 |
|
break; |
120 |
|
} |
121 |
|
this->scale = 1.0f - resonance * 0.7f; |
122 |
|
this->resonance = resonance; |
123 |
|
this->cutoff = cutoff; |
124 |
|
} |
125 |
|
|
126 |
|
void Reset() { |
127 |
|
BasicBPFilter.Reset(); |
128 |
|
HPFilter.Reset(); |
129 |
|
BPFilter.Reset(); |
130 |
|
LPFilter.Reset(); |
131 |
|
} |
132 |
|
|
133 |
inline bq_t Apply(const bq_t in) { |
inline bq_t Apply(const bq_t in) { |
134 |
return (Enabled) ? pFilter->Apply(in) * this->scale + |
return pFilter->Apply(in) * this->scale + |
135 |
BasicBPFilter.ApplyFB(in, this->resonance * LSF_FB) * this->resonance |
BasicBPFilter.ApplyFB(in, this->resonance * LSF_FB) * this->resonance; |
|
: in; |
|
136 |
} |
} |
137 |
|
|
138 |
|
inline bq_t Apply(biquad_param_t* base, biquad_param_t* main, const bq_t in) { |
139 |
|
return pFilter->Apply(main, in) * this->scale + |
140 |
|
BasicBPFilter.ApplyFB(base, in, this->resonance * LSF_FB) * this->resonance; |
141 |
|
} |
142 |
|
|
143 |
|
#if ARCH_X86 |
144 |
|
// expects to find input in xmm0 and leaves output in xmm7 |
145 |
|
inline void Apply4StepsSSE(biquad_param_t* base, biquad_param_t* main) { |
146 |
|
float fb; |
147 |
|
__asm__ __volatile__ ( |
148 |
|
"movss %0, %%xmm4\n\t" |
149 |
|
"mulss %1, %%xmm4 # this->resonance * LSF_FB\n\t" |
150 |
|
"movss %%xmm4, %2\n\t" |
151 |
|
:: "m" (fFB), /* %0 */ |
152 |
|
"m" (resonance), /* %1 */ |
153 |
|
"m" (fb) /* %2 */ |
154 |
|
); |
155 |
|
BasicBPFilter.ApplyFB4StepsSSE(base, fb); // leaves output in xmm7 |
156 |
|
__asm__ __volatile__ ( |
157 |
|
"movss %0, %%xmm4\n\t" |
158 |
|
"shufps $0, %%xmm4, %%xmm4 # copy to other 3 cells\n\t" |
159 |
|
"mulps %%xmm4, %%xmm7 # ApplyFB() * this->resonance\n\t" |
160 |
|
:: "m" (resonance) /* %0 */ |
161 |
|
); |
162 |
|
pFilter->Apply4StepsSSE(main); // leaves output in xmm6 |
163 |
|
__asm__ __volatile__ ( |
164 |
|
"movss %0, %%xmm5\n\t" |
165 |
|
"shufps $0, %%xmm5, %%xmm5 # copy to other 3 cells\n\t" |
166 |
|
"mulps %%xmm5, %%xmm6 # Apply() * this->scale\n\t" |
167 |
|
"addps %%xmm6, %%xmm7 # xmm7 = result\n\t" |
168 |
|
:: "m" (scale) /* %0 */ |
169 |
|
); |
170 |
|
} |
171 |
|
#endif // ARCH_X86 |
172 |
|
|
173 |
}; |
}; |
174 |
|
|
175 |
}} //namespace LinuxSampler::gig |
}} //namespace LinuxSampler::gig |