/[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 505 - (show annotations) (download) (as text)
Tue May 3 01:00:25 2005 UTC (18 years, 11 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7716 byte(s)
fixed libgig include rules

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 #if DEBUG_HEADERS
30 # warning Filter.h included
31 #endif // DEBUG_HEADERS
32
33 #include <gig.h>
34
35 #include "../common/BiquadFilter.h"
36
37 // TODO: Gigasampler's "Turbo Lowpass" and "Bandreject" filters not implemented yet
38
39 #define LSF_BW 0.9
40 #define LSF_FB 0.9f
41
42 namespace LinuxSampler { namespace gig {
43
44 /**
45 * These are filters similar to the ones from Gigasampler.
46 */
47 class Filter {
48 protected:
49 BandpassFilter BasicBPFilter;
50 HighpassFilter HPFilter;
51 BandpassFilter BPFilter;
52 LowpassFilter LPFilter;
53 BiquadFilter* pFilter;
54 bq_t scale;
55 bq_t resonance;
56 bq_t cutoff;
57 ::gig::vcf_type_t Type;
58 static const float fFB = LSF_FB;
59 public:
60
61 Filter() {
62 // set filter type to 'lowpass' by default
63 pFilter = &LPFilter;
64 Type = ::gig::vcf_type_lowpass;
65 }
66
67 inline bq_t Cutoff() { return cutoff; }
68
69 inline bq_t Resonance() { return resonance; }
70
71 inline void SetType(::gig::vcf_type_t FilterType) {
72 switch (FilterType) {
73 case ::gig::vcf_type_highpass:
74 pFilter = &HPFilter;
75 break;
76 case ::gig::vcf_type_bandreject: //TODO: not implemented yet
77 FilterType = ::gig::vcf_type_bandpass;
78 case ::gig::vcf_type_bandpass:
79 pFilter = &BPFilter;
80 break;
81 case ::gig::vcf_type_lowpassturbo: //TODO: not implemented yet
82 default:
83 FilterType = ::gig::vcf_type_lowpass;
84 case ::gig::vcf_type_lowpass:
85 pFilter = &LPFilter;
86
87 }
88 Type = FilterType;
89 }
90
91 inline void SetParameters(bq_t cutoff, bq_t resonance, bq_t fs) {
92 BasicBPFilter.SetParameters(cutoff, 0.7, fs);
93 switch (Type) {
94 case ::gig::vcf_type_highpass:
95 HPFilter.SetParameters(cutoff, 1.0 - resonance * LSF_BW, fs);
96 break;
97 case ::gig::vcf_type_bandpass:
98 BPFilter.SetParameters(cutoff, 1.0 - resonance * LSF_BW, fs);
99 break;
100 case ::gig::vcf_type_lowpass:
101 LPFilter.SetParameters(cutoff, 1.0 - resonance * LSF_BW, fs);
102 break;
103 }
104 this->scale = 1.0f - resonance * 0.7f;
105 this->resonance = resonance;
106 this->cutoff = cutoff;
107 }
108
109 inline void SetParameters(biquad_param_t* base, biquad_param_t* main, bq_t cutoff, bq_t resonance, bq_t fs) {
110 BasicBPFilter.SetParameters(base, cutoff, 0.7, fs);
111 switch (Type) {
112 case ::gig::vcf_type_highpass:
113 HPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs);
114 break;
115 case ::gig::vcf_type_bandpass:
116 BPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs);
117 break;
118 case ::gig::vcf_type_lowpass:
119 LPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs);
120 break;
121 }
122 this->scale = 1.0f - resonance * 0.7f;
123 this->resonance = resonance;
124 this->cutoff = cutoff;
125 }
126
127 void Reset() {
128 BasicBPFilter.Reset();
129 HPFilter.Reset();
130 BPFilter.Reset();
131 LPFilter.Reset();
132 }
133
134 inline bq_t Apply(const bq_t in) {
135 return pFilter->Apply(in) * this->scale +
136 BasicBPFilter.ApplyFB(in, this->resonance * LSF_FB) * this->resonance;
137 }
138
139 inline bq_t Apply(biquad_param_t* base, biquad_param_t* main, const bq_t in) {
140 return pFilter->Apply(main, in) * this->scale +
141 BasicBPFilter.ApplyFB(base, in, this->resonance * LSF_FB) * this->resonance;
142 }
143
144 #if ARCH_X86
145 // expects to find input in xmm0 and leaves output in xmm7
146 inline void Apply4StepsSSE(biquad_param_t* base, biquad_param_t* main) {
147 float fb;
148 __asm__ __volatile__ (
149 "movss %0, %%xmm4\n\t"
150 "mulss %1, %%xmm4 # this->resonance * LSF_FB\n\t"
151 "movss %%xmm4, %2\n\t"
152 :: "m" (fFB), /* %0 */
153 "m" (resonance), /* %1 */
154 "m" (fb) /* %2 */
155 );
156 BasicBPFilter.ApplyFB4StepsSSE(base, fb); // leaves output in xmm7
157 __asm__ __volatile__ (
158 "movss %0, %%xmm4\n\t"
159 "shufps $0, %%xmm4, %%xmm4 # copy to other 3 cells\n\t"
160 "mulps %%xmm4, %%xmm7 # ApplyFB() * this->resonance\n\t"
161 :: "m" (resonance) /* %0 */
162 );
163 pFilter->Apply4StepsSSE(main); // leaves output in xmm6
164 __asm__ __volatile__ (
165 "movss %0, %%xmm5\n\t"
166 "shufps $0, %%xmm5, %%xmm5 # copy to other 3 cells\n\t"
167 "mulps %%xmm5, %%xmm6 # Apply() * this->scale\n\t"
168 "addps %%xmm6, %%xmm7 # xmm7 = result\n\t"
169 :: "m" (scale) /* %0 */
170 );
171 }
172 #endif // ARCH_X86
173
174 };
175
176 }} //namespace LinuxSampler::gig
177
178 #endif // __LS_GIG_FILTER_H__

  ViewVC Help
Powered by ViewVC