gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
fastDepukfb.H
Go to the documentation of this file.
1 /*
2  libaudiomask - hybrid simultaneous audio masking threshold evaluation library
3  Copyright (C) 2000-2018 Dr Matthew Raphael Flax
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef FASTDEPUKFB_H_
20 #define FASTDEPUKFB_H_
21 #include <string.h>
22 #include "AudioMask/depukfb.H"
23 
24 class FastDepUKFB : public DepUKFB {
25 
26  double n_l[2], d_l[3]; // Lower filter IIR coeff.
27  double n_u[2], d_u[3]; // Upper filter IIR coeff.
28 
29  void findIIRCoeff(double fc, double pl, double pu){
30  double c1, c2, c3, c4; // Numerator coefficients
31  double d1, d2, d3, d4; // Denominator coefficients
32 
33  // Find the lower filter's IIR coefficients first
34  c1=exp(pl/fc);
35  c2=exp(pl);
36  //c5=c1*c1;
37  c4=c1*c2;
38  c3=c1*c4;
39  d_l[0]=(c2*fc); // Do this first so we can divide by it
40  n_l[0]=(fc+fc*pl)/d_l[0]; // Numerator
41  n_l[1]=(-c1*fc-c1*pl-c1*fc*pl)/d_l[0];
42  d_l[1]=(-2*c4*fc)/d_l[0]; // Denominator
43  d_l[2]=(c3*fc)/d_l[0];
44  d_l[0]=1.0;
45 
46  // Find the upper filter's IIR coefficients
47  d4=exp(pu/fc);
48  d3=d4*d4;
49  d2=exp(pu+pu/fc);
50  d1=d2*d4;
51 
52  d_u[0]=(d3*fc);
53  n_u[0]=(d1*fc-d1*fc*pu)/d_u[0]; // Numerator
54  n_u[1]=d2*(-fc+pu+pu*fc)/d_u[0];
55  d_u[1]=(-2*d4*fc)/d_u[0]; // Denominator
56  d_u[2]=(fc)/d_u[0];
57  d_u[0]=1.0;
58  }
59 
60  void filter(double fc, double *out){
61  //Second order impulse response
62 
63  // Reset the state vars and the output
64  double z1=0.0, z2=0.0;
65  bzero(out, (int)rint(fs/2.0)*sizeof(double));
66 
67  // Upper filter ...
68  // First excite with a unit input ....
69  out[0] = n_u[0] - d_u[0]*out[0] + z1;
70  z1 = n_u[1] - d_u[1]*out[0] + z2;
71  z2 = - d_u[2]*out[0];
72 
73  for (int i=1;i<(int)rint(fs/2.0);i++){ // the input now equals zero
74  out[i] = - d_u[0]*out[i] + z1;
75  z1 = - d_u[1]*out[i] + z2;
76  z2 = - d_u[2]*out[i];
77  }
78 
79  // Reset the state vars and the lower output
80  z1=z2=0.0;
81  bzero(out, (int)rint(fc)*sizeof(double));
82 
83  // Lower filter ...
84  // First excite with a unit input ....
85  out[0] = n_l[0] - d_l[0]*out[0] + z1;
86  z1 = n_l[1] - d_l[1]*out[0] + z2;
87  z2 = - d_l[2]*out[0];
88 
89  for (int i=1;i<(int)rint(fc);i++){ // the input now equals zero
90  out[i] = - d_l[0]*out[i] + z1;
91  z1 = - d_l[1]*out[i] + z2;
92  z2 = - d_l[2]*out[i];
93  }
94  }
95 
96  void afZ(double fc, int whichFilter, double pl, double pu){
97  double *filt=w[whichFilter];
98  findIIRCoeff(fc, pl, pu); // Find the IIR coefficients to filter with
99  filter(fc, filt); // Find the lower filter shape
100  }
101 
103  virtual void af(double fc, int whichFilter){
104  cout<<"FastDepUKFB::af"<<endl;
105 
106  // Produce the filter
107  afZ(fc, whichFilter, p_l(fc), p_u(fc));
108  }
109 
110 public:
111  FastDepUKFB(int sampleFreq, int fCnt=50) {
112  init(sampleFreq, fCnt);
113  }
114 };
115 
116 #endif //FASTDEPUKFB_H_
double n_l[2]
Definition: fastDepukfb.H:26
double p_l(double fc)
Definition: depukfb.H:136
double ** w
The filters.
Definition: depukfb.H:127
virtual void af(double fc, int whichFilter)
Auditory Filter procedure.
Definition: fastDepukfb.H:103
double rint(double)
void findIIRCoeff(double fc, double pl, double pu)
Definition: fastDepukfb.H:29
double d_l[3]
Definition: fastDepukfb.H:26
double d_u[3]
Definition: fastDepukfb.H:27
FastDepUKFB(int sampleFreq, int fCnt=50)
Definition: fastDepukfb.H:111
int fs
The sample frequency.
Definition: depukfb.H:125
void init(int sampleFreq, int fCnt=50)
Definition: depukfb.H:171
double p_u(double fc)
Definition: depukfb.H:147
void afZ(double fc, int whichFilter, double pl, double pu)
Definition: fastDepukfb.H:96
void filter(double fc, double *out)
Definition: fastDepukfb.H:60
double n_u[2]
Definition: fastDepukfb.H:27
gtkIOStream: /tmp/gtkiostream/include/AudioMask/fastDepukfb.H Source File
GTK+ IOStream  Beta