/************************************************************************** * echogen.c - C program that simulates echo path for generating echo and * mixing with near-end speech * *************************************************************************** * System simulation configuration: * * ______________ * farEndIn | | speakerOut * ------------->| |---------------- * | | ____|____ * | | | | * | Speakphone | | A(z) | * | System | |_______| * | | | acousticEcho * | | | * | | +| + nearEndIn * | |<------------(sum)<------------ * |____________| microphoneIn * * farEndIn is a far-end speech from a data file * nearEndIn is a near-end speech from a data file * acousticEcho is acoustic echo generated A(z) * microphoneIn is the near-end speech plus acoustic echo * A(z) is an acoustic echo path * *-------------------------------------------------------------------------- * Synopsis * * This program is executed by keying in the following command: * * echogen NEARFILE FARFILE MICFILE * * where * NEARFILE - file name of near-end speech * FARFILE - file name of far-end speech * MICFILE - file name of microphoneIn signal * *-------------------------------------------------------------------------- * Functions called by this program * * fir, shift, uran, echopath * *************************************************************************** * Specify auxiliary routines and parameter values **************************************************************************/ #include #include #include #define MAX 1024 // maximum order of arrays void main(int argc, char *argv[]) { void shift(); // function to update signal vector void echopath(); // function to generate echo path float fir(); // function to perform FIR filtering float uran(); // function to generate white noise /************************************************************************** * Define variable arrays, define and clear variables **************************************************************************/ int i; // integers for indexes int AzOrder = 512; // order of A(z) float farEndIn = 0.; // new data from the far-end float nearEndIn = 0.; // new data from the near-end talker float acousticEcho = 0.; // new data of acoustic echo float speakerOut = 0.; // signal send to loudspeaker float microphoneIn = 0.; // signal pick up by microphone float AzCoef[MAX]; // coefficient vector of A(z) float AzBuf[MAX]; // signal buffer for A(z) /************************************************************************** * Define variables for generating line and acoustic impulse responses **************************************************************************/ int acousticDelay = 10; // acoustic echo path delay float acousticVar = (float)0.054; // variance float acousticDecay = (float)0.012;// decay of acoustic echo /************************************************************************** * Declare file pointers **************************************************************************/ FILE *farin; // file pointer of far_end signal FILE *nearin; // file pointer of near_end signal FILE *micout; // file pointer of transmit signal /************************************************************************** * Define usage of executable file **************************************************************************/ if ( argc < 3 ) { fprintf(stderr,"%s\n*** Usage ***\n",argv[0]); fprintf(stderr,"echopath NEARFILE FARFILE MICFILE\n"); fprintf(stderr," NEARFILE is file name of near-end speech\n"); fprintf(stderr," FARFILE is file name of far-end speech\n"); fprintf(stderr," MICFILE is file name of microphoneIn signal\n"); exit(0); } /************************************************************************** * Input data and parameters at execution time **************************************************************************/ if (( nearin = fopen(argv[1],"r")) == NULL ) // open near-end speech file { fprintf(stderr,"Can't open the near-end data file %s!\n",argv[1]); exit(0); } if (( farin = fopen(argv[2],"r")) == NULL ) // open far-end speech file { fprintf(stderr,"Can't open the far-end data file %s!\n",argv[2]); exit(0); } micout = fopen(argv[3],"w"); // open MIC signal data file for storage /************************************************************************** * Clear arrays **************************************************************************/ for (i=0; i0; --i) { x[i] = x[i-1]; // shift old data x(n-i), i = 1, 2, ... N-1 } x[0] = (float)new; // insert new data x(n) } /************************************************************************** * FIR - This function performs FIR filtering * ntap-1 * y(n) = sum wi * x(n-i) * i=0 **************************************************************************/ float fir(x, w, ntap) float *x, *w; int ntap; { float yn; // output of FIR filter int i; // index yn = 0.0; // y(n) = 0. for (i=0; i