00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
#ifndef _VrIIRFILTER_H_
00040
#define _VrIIRFILTER_H_
00041
00042
#include <VrSigProc.h>
00043
00044
template<
class iType,
class oType>
00045 class VrIIRfilter :
public VrSigProc {
00046
protected:
00047 int order,
offset;
00048 double *
Btaps, *
Ataps;
00049 iType *
input_hist;
00050 oType *
output_hist;
00051 float gain;
00052
00053
public:
00054
virtual int work(
VrSampleRange output,
void *ao[],
00055
VrSampleRange inputs[],
void *ai[]);
00056
virtual void initialize();
00057
VrIIRfilter(
int,
double *,
double *,
float);
00058
~VrIIRfilter();
00059 };
00060
00061
template<
class iType,
class oType>
int
00062 VrIIRfilter<iType,oType>::work(
VrSampleRange output,
void *ao[],
00063
VrSampleRange inputs[],
void *ai[])
00064 {
00065
oType result;
00066
for (
unsigned int sample=0;sample<output.
size;sample++)
00067 {
00068
input_hist[(sample +
offset)%
order] = ((
iType **)ai)[0][sample];
00069 result =
Btaps[0] * ((
iType **)ai)[0][sample];
00070
00071
for (
int tap=1; tap <
order; tap++)
00072 result += (Btaps[tap] *
input_hist[(sample +
offset + order - tap)%order])
00073 + (
Ataps[tap] *
output_hist[(sample +
offset + order - tap)%order]);
00074 ((
oType **)ao)[0][sample] =
gain * result;
00075 output_hist[(sample +
offset) % order] = result;
00076 }
00077
offset = (
offset + output.
size) %
order;
00078
return output.
size;
00079 }
00080
00081
00082
template<
class iType,
class oType>
00083 VrIIRfilter<iType,oType>::VrIIRfilter(
int ord,
double *intaps,
double *outtaps,
float gain)
00084 :
VrSigProc(1, sizeof(
iType), sizeof(
oType)), order(ord),offset(0),gain(gain)
00085 {
00086
Ataps =
new double[
order];
00087
Btaps =
new double[
order];
00088
input_hist =
new iType[
order];
00089
output_hist =
new oType[
order];
00090
00091
for(
int i = 0; i<
order; i++)
00092 {
00093
input_hist[i] = 0;
output_hist[i] = 0;
00094
Btaps[i] = intaps[i];
00095
Ataps[i] = outtaps[i];
00096 }
00097 }
00098
00099
template<
class iType,
class oType>
00100 void VrIIRfilter<iType,oType>::initialize()
00101 {
00102
00103
00104 }
00105
00106
template<
class iType,
class oType>
00107 VrIIRfilter<iType,oType>::~VrIIRfilter()
00108 {
00109
delete Ataps;
00110
delete Btaps;
00111
delete input_hist;
00112
delete output_hist;
00113 }
00114
00115
#endif
00116
00117
00118
00119
00120
00121
00122
00123