www.pudn.com > aec.rar > ec_main.cpp
// file: ec_main.cc // // system include files // #include#include #include #include #include // local include files // #include "ec.h" #include "ec_constants.h" extern unsigned char l2u( short data ); extern short u2l( unsigned char data ); //----------------------------------------------------------------------------- // // program: ec_main.cc // synopsis: echoc.exe // example: ec.exe < foo_stereo_echo.raw > foo_stereo_clean.raw // // options: none // // arguments: none // // note: // this program is a fairly hardcoded implementation of a standard // echo canceller. //----------------------------------------------------------------------------- int main( int argc, char * argv[] ) { //--------------------------------------------------------------------------- // // process the command line arguments // //--------------------------------------------------------------------------- // check the number of arguments // if ( argc != 4 ) { fprintf(stderr, "usage: ec.exe tx_file rx_file out_file"); return(1); } FILE * f_tx = fopen( argv[ 1 ], "rb" ); FILE * f_rx = fopen( argv[ 2 ], "rb" ); FILE * f_out = fopen( argv[ 3 ], "wb+" ); assert( f_tx != NULL ); assert( f_rx != NULL ); assert( f_out != NULL ); // declare an echo canceller object for the reference far-end speech and // the near-end speech // Echo_canceller ec_near; // initialize the echo canceller // ec_near.init_cc(DEFAULT_GAMMA, DEFAULT_N, DEFAULT_M, DEFAULT_BETA1, DEFAULT_SIGMA_LY, DEFAULT_SIGMA_LU, DEFAULT_ALPHA_ST, DEFAULT_ALPHA_YT, DEFAULT_CUTOFF, DEFAULT_HANGT, DEFAULT_SUPPR, DEFAULT_TAU); //--------------------------------------------------------------------------- // // process data // //--------------------------------------------------------------------------- // main echo cancellation loop // unsigned char sig_tx, sig_rx; unsigned char sig_out; short sig_tx_s, sig_rx_s, sig_out_s; while ( 1 ) { if ( fread( &sig_tx, sizeof(sig_tx), (int)1, f_tx ) <= 0 ) break; if ( fread( &sig_rx, sizeof(sig_rx), (int)1, f_rx ) <= 0 ) break; sig_tx_s = u2l( sig_tx ); sig_rx_s = u2l( sig_rx ); // process the data // // sig_out_s = ec_near.clip_cc( ec_near.process_cc( AMPL_SCALE_1 * sig_tx_s, AMPL_SCALE_1 * sig_rx_s ) ); sig_out_s = (short)( ec_near.process_cc( sig_tx_s, sig_rx_s ) ); // sig_out_s = (short)ec_near.process_cc( sig_tx_s, sig_rx_s ); // write the output data // sig_out = l2u( sig_out_s ); fwrite( &sig_out, sizeof(sig_out), (int)1, f_out ); // if ( sig_out != sig_rx ) // printf( "%2x:%2x ", sig_rx, sig_out ); } // exit gracefully // fclose( f_tx ); fclose( f_rx ); fclose( f_out ); return(0); }