/[svn]/linuxsampler/trunk/src/engines/gig/Filter.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/gig/Filter.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 791 - (show annotations) (download) (as text)
Sun Oct 16 14:50:20 2005 UTC (18 years, 6 months ago) by persson
File MIME type: text/x-c++hdr
File size: 7835 byte(s)
* Filter tuning: calculation of cutoff frequency and bandwidth
  improved. Removed use of "BasicBPFilter". Changed bandpass filter
  from constant peak to constant skirt. Use gig parameter Resonance if
  no resonance controller is set. Removed keyboard tracking influence
  on resonance.

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * 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 *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 #ifndef __LS_GIG_FILTER_H__
25 #define __LS_GIG_FILTER_H__
26
27 #include "../../common/global.h"
28
29 #include <gig.h>
30
31 #include "../common/BiquadFilter.h"
32
33 // TODO: Gigasampler's "Turbo Lowpass" and "Bandreject" filters not implemented yet
34
35 #define LSF_BW 0.9
36 #define LSF_FB 0.9f
37
38 namespace LinuxSampler { namespace gig {
39
40 /**
41 * These are filters similar to the ones from Gigasampler.
42 */
43 class Filter {
44 protected:
45 BandpassFilter BasicBPFilter;
46 HighpassFilter HPFilter;
47 BandpassFilter BPFilter;
48 LowpassFilter LPFilter;
49 BiquadFilter* pFilter;
50 bq_t scale;
51 bq_t resonance;
52 bq_t cutoff;
53 ::gig::vcf_type_t Type;
54 #if __GNUC__ >= 4
55 float fFB;
56 #else
57 static const float fFB = LSF_FB;
58 #endif
59
60 public:
61
62 Filter() {
63 // set filter type to 'lowpass' by default
64 pFilter = &LPFilter;
65 Type = ::gig::vcf_type_lowpass;
66 #if __GNUC__ >= 4
67 fFB = LSF_FB;
68 #endif
69 }
70
71 inline bq_t Cutoff() { return cutoff; }
72
73 inline bq_t Resonance() { return resonance; }
74
75 inline void SetType(::gig::vcf_type_t FilterType) {
76 switch (FilterType) {
77 case ::gig::vcf_type_highpass:
78 pFilter = &HPFilter;
79 break;
80 case ::gig::vcf_type_bandreject: //TODO: not implemented yet
81 FilterType = ::gig::vcf_type_bandpass;
82 case ::gig::vcf_type_bandpass:
83 pFilter = &BPFilter;
84 break;
85 case ::gig::vcf_type_lowpassturbo: //TODO: not implemented yet
86 default:
87 FilterType = ::gig::vcf_type_lowpass;
88 case ::gig::vcf_type_lowpass:
89 pFilter = &LPFilter;
90
91 }
92 Type = FilterType;
93 }
94
95 inline void SetParameters(bq_t cutoff, bq_t resonance, bq_t fs) {
96 BasicBPFilter.SetParameters(cutoff, 0.7, fs);
97 switch (Type) {
98 case ::gig::vcf_type_highpass:
99 HPFilter.SetParameters(cutoff, 1.87 - resonance * 1.7526, fs);
100 break;
101 case ::gig::vcf_type_bandpass:
102 BPFilter.SetParameters(cutoff, 1.87 - resonance * 1.7526, fs);
103 break;
104 case ::gig::vcf_type_lowpass:
105 LPFilter.SetParameters(cutoff, 1.87 - resonance * 1.7526, fs);
106 break;
107 }
108 this->scale = resonance < 0.4 ? 1.0f : 1.4f - resonance * 1.016f;
109 this->resonance = resonance;
110 this->cutoff = cutoff;
111 }
112
113 inline void SetParameters(biquad_param_t* base, biquad_param_t* main, bq_t cutoff, bq_t resonance, bq_t fs) {
114 BasicBPFilter.SetParameters(base, cutoff, 0.7, fs);
115 switch (Type) {
116 case ::gig::vcf_type_highpass:
117 HPFilter.SetParameters(main, cutoff, 1.87 - resonance * 1.7526, fs);
118 break;
119 case ::gig::vcf_type_bandpass:
120 BPFilter.SetParameters(main, cutoff, 1.87 - resonance * 1.7526, fs);
121 break;
122 case ::gig::vcf_type_lowpass:
123 LPFilter.SetParameters(main, cutoff, 1.87 - resonance * 1.7526, fs);
124 break;
125 }
126 this->scale = resonance < 0.4 ? 1.0f : 1.4f - resonance * 1.016f;
127 this->resonance = resonance;
128 this->cutoff = cutoff;
129 }
130
131 void Reset() {
132 BasicBPFilter.Reset();
133 HPFilter.Reset();
134 BPFilter.Reset();
135 LPFilter.Reset();
136 }
137
138 inline bq_t Apply(const bq_t in) {
139 return pFilter->Apply(in) * this->scale;
140 // + 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) {
144 return pFilter->Apply(main, in) * this->scale;
145 // + BasicBPFilter.ApplyFB(base, in, this->resonance * LSF_FB) * this->resonance;
146 }
147
148 #if CONFIG_ASM && ARCH_X86
149 // expects to find input in xmm0 and leaves output in xmm7
150 inline void Apply4StepsSSE(biquad_param_t* base, biquad_param_t* main) {
151 float fb;
152 __asm__ __volatile__ (
153 "movss %0, %%xmm4\n\t"
154 "mulss %1, %%xmm4 # this->resonance * LSF_FB\n\t"
155 "movss %%xmm4, %2\n\t"
156 :: "m" (fFB), /* %0 */
157 "m" (resonance), /* %1 */
158 "m" (fb) /* %2 */
159 );
160 BasicBPFilter.ApplyFB4StepsSSE(base, fb); // leaves output in xmm7
161 __asm__ __volatile__ (
162 "movss %0, %%xmm4\n\t"
163 "shufps $0, %%xmm4, %%xmm4 # copy to other 3 cells\n\t"
164 "mulps %%xmm4, %%xmm7 # ApplyFB() * this->resonance\n\t"
165 :: "m" (resonance) /* %0 */
166 );
167 pFilter->Apply4StepsSSE(main); // leaves output in xmm6
168 __asm__ __volatile__ (
169 "movss %0, %%xmm5\n\t"
170 "shufps $0, %%xmm5, %%xmm5 # copy to other 3 cells\n\t"
171 "mulps %%xmm5, %%xmm6 # Apply() * this->scale\n\t"
172 "addps %%xmm6, %%xmm7 # xmm7 = result\n\t"
173 :: "m" (scale) /* %0 */
174 );
175 }
176 #endif // CONFIG_ASM && ARCH_X86
177
178 };
179
180 }} //namespace LinuxSampler::gig
181
182 #endif // __LS_GIG_FILTER_H__

  ViewVC Help
Powered by ViewVC