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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 53 by schoenebeck, Mon Apr 26 17:15:51 2004 UTC revision 685 by persson, Tue Jul 5 19:30:37 2005 UTC
# Line 2  Line 2 
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     *   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  *
# Line 25  Line 26 
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    
38  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
39    
40      /**      /**
41       * This is a filter similar to the ones from Gigasampler.       * These are filters similar to the ones from Gigasampler.
42       */       */
43      class Filter {      class Filter {
44          protected:          protected:
# Line 54  namespace LinuxSampler { namespace gig { Line 51  namespace LinuxSampler { namespace gig {
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;
58    #endif
59    
60          public:          public:
             bool Enabled;  
61    
62              inline 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; }
# Line 73  namespace LinuxSampler { namespace gig { Line 78  namespace LinuxSampler { namespace gig {
78                          pFilter = &HPFilter;                          pFilter = &HPFilter;
79                          break;                          break;
80                      case ::gig::vcf_type_bandreject: //TODO: not implemented yet                      case ::gig::vcf_type_bandreject: //TODO: not implemented yet
81                          Type = ::gig::vcf_type_bandpass;                          FilterType = ::gig::vcf_type_bandpass;
82                      case ::gig::vcf_type_bandpass:                      case ::gig::vcf_type_bandpass:
83                          pFilter = &BPFilter;                          pFilter = &BPFilter;
84                          break;                          break;
85                      case ::gig::vcf_type_lowpassturbo: //TODO: not implemented yet                      case ::gig::vcf_type_lowpassturbo: //TODO: not implemented yet
86                      default:                      default:
87                          Type = ::gig::vcf_type_lowpass;                          FilterType = ::gig::vcf_type_lowpass;
88                      case ::gig::vcf_type_lowpass:                      case ::gig::vcf_type_lowpass:
89                          pFilter = &LPFilter;                          pFilter = &LPFilter;
90    
# Line 105  namespace LinuxSampler { namespace gig { Line 110  namespace LinuxSampler { namespace gig {
110                  this->cutoff    = cutoff;                  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.0 - resonance * LSF_BW, fs);
118                            break;
119                        case ::gig::vcf_type_bandpass:
120                            BPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs);
121                            break;
122                        case ::gig::vcf_type_lowpass:
123                            LPFilter.SetParameters(main, cutoff, 1.0 - resonance * LSF_BW, fs);
124                            break;
125                    }
126                    this->scale     = 1.0f - resonance * 0.7f;
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) {              inline bq_t Apply(const bq_t in) {
139                  return (Enabled) ? 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;
                                 : in;  
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  }} //namespace LinuxSampler::gig

Legend:
Removed from v.53  
changed lines
  Added in v.685

  ViewVC Help
Powered by ViewVC