00001 #include "flt.h"
00002
00003
00004
00005
00006
00007 namespace flt{
00008
00009
00010 CFIRFilter::CFIRFilter
00011 ( const shortfract h[],
00012 int tap,
00013 shortfract d[] )
00014 {
00015 if ( d ) {
00016 givenDelayLine = 1;
00017 state.d = (fract16 *) d;
00018 }
00019 else{
00020 givenDelayLine = 0;
00021 state.d = (short*)new shortfract[tap];
00022 }
00023
00024 state.h = (fract16 *)h;
00025 state.k = tap;
00026 state.p = state.d;
00027 state.l = 0;
00028
00029
00030 for ( int i=0; i< tap; i++ )
00031 state.d[i] = 0;
00032 }
00033
00034
00035 CFIRFilter::~CFIRFilter()
00036 {
00037 if ( ! givenDelayLine )
00038 delete[] state.d;
00039 }
00040
00041 void CFIRFilter::run( const shortfract input[],
00042 shortfract output[],
00043 int count )
00044 {
00045 fir_fr16(
00046 (fract16 *)input,
00047 (fract16 *)output,
00048 count,
00049 &state
00050 );
00051 }
00052
00053
00054 CIIRFilter::CIIRFilter
00055 ( const shortfract coeff[],
00056 int stage,
00057 shortfract d[])
00058 {
00059
00060
00061 if ( d ) {
00062 givenDelayLine = 1;
00063 state.d = (fract16 *) d;
00064 }
00065 else{
00066 givenDelayLine = 0;
00067 state.d = (short *)new shortfract[stage*2];
00068 }
00069
00070 state.c = (fract16 *)coeff;
00071 state.k = stage;
00072
00073
00074 for ( int i=0; i< stage*2; i++ )
00075 state.d[i] = 0;
00076 }
00077
00078
00079 CIIRFilter::~CIIRFilter()
00080 {
00081 if ( ! givenDelayLine )
00082 delete[] state.d;
00083 }
00084
00085 void CIIRFilter::run( const shortfract input[],
00086 shortfract output[],
00087 int count )
00088 {
00089 iir_fr16(
00090 (fract16 *)input,
00091 (fract16 *)output,
00092 count,
00093 &state
00094 );
00095 }
00096
00097 CDecimator::CDecimator
00098 ( const shortfract h[],
00099 int tap,
00100 int ratio,
00101 shortfract d[] )
00102 : CFIRFilter( h, tap, d )
00103 {
00104 state.l = ratio;
00105 }
00106
00107
00108 void CDecimator::run( const shortfract input[],
00109 shortfract output[],
00110 int count )
00111 {
00112 fir_decima_fr16(
00113 (fract16 *)input,
00114 (fract16 *)output,
00115 count,
00116 &state
00117 );
00118 }
00119
00120 CInterpolator::CInterpolator
00121 ( const shortfract h[],
00122 int tap,
00123 int ratio,
00124 shortfract d[] )
00125 : CFIRFilter( h, tap/ratio, d )
00126 {
00127 state.l = ratio;
00128 }
00129
00130
00131 void CInterpolator::run( const shortfract input[],
00132 shortfract output[],
00133 int count )
00134 {
00135 fir_interp_fr16(
00136 (fract16 *)input,
00137 (fract16 *)output,
00138 count,
00139 &state
00140 );
00141 }
00142
00143 extern "C" void _iir_fr16_ex( fract16 input[], fract16 output[], int count, iir_state_fr16 * d, const short sc[] );
00144 void CIIRFilterEx::run( const shortfract input[],
00145 shortfract output[],
00146 int count )
00147 {
00148 _iir_fr16_ex(
00149 (fract16 *)input,
00150 (fract16 *)output,
00151 count,
00152 &state,
00153 scaleFactor
00154 );
00155 }
00156
00157
00158 };