flt.cpp

説明を見る。
00001 #include "flt.h"
00002 /** フィルター・クラス定義ファイル
00003 * \file flt.cpp
00004 * fltクラス・ライブラリを定義する。このクラス・ライブラリはVisualDSP++の基本フィルタ群のラッパー
00005 * である。ヘッダー・ファイルは flt.h。
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(           // VisualDSP++のフィルタ関数
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(           // VisualDSP++のフィルタ関数
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;        // decimation比を内部変数に格納     
00105     }
00106     
00107 
00108     void CDecimator::run( const shortfract input[], 
00109                           shortfract output[], 
00110                           int count )
00111     {
00112         fir_decima_fr16(           // VisualDSP++のフィルタ関数
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(           // VisualDSP++のフィルタ関数
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(           // VisualDSP++のフィルタ関数
00149                     (fract16 *)input, 
00150                     (fract16 *)output, 
00151                     count, 
00152                     &state,
00153                     scaleFactor
00154                 );
00155     }
00156 
00157         
00158 };

IIR filter sample by wrapper classに対してMon Dec 18 17:29:47 2006に生成されました。  doxygen 1.5.1-p1