From be3124fe410f37462b6af7131697ee91f33a9ba3 Mon Sep 17 00:00:00 2001 From: markster Date: Wed, 16 Apr 2003 03:31:07 +0000 Subject: Make MEC3 work! git-svn-id: http://svn.digium.com/svn/zaptel/trunk@171 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- mec3.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'mec3.h') diff --git a/mec3.h b/mec3.h index 28cfa6e..6f42824 100755 --- a/mec3.h +++ b/mec3.h @@ -33,6 +33,9 @@ #define FREE(a) free(a) #endif +/* + * Define COEFF_BACKUP for experimental coefficient backup code + */ #define STEP_SIZE 0.4 /* Convergence rate */ @@ -50,7 +53,7 @@ #define HANG_TIME 600 /* Hangover time */ -#define NTAPS 128 /* Number of echo can taps */ +#define NTAPS 256 /* Number of echo can taps */ #define BACKUP 256 /* Backup every this number of samples */ @@ -62,8 +65,11 @@ typedef struct { typedef struct { float a[NTAPS]; /* Coefficients */ +#ifdef COEFF_BACKUP float b[NTAPS]; /* Coefficients */ float c[NTAPS]; /* Coefficients */ + int backup; /* Backup timer */ +#endif cbuf_f ref; /* Reference excitation */ cbuf_f sig; /* Signal (echo + near end + noise) */ cbuf_f e; /* Error */ @@ -71,7 +77,6 @@ typedef struct { int taps; /* Number of taps */ int hcntr; /* Hangtime counter */ int pos; /* Position in curcular buffers */ - int backup; /* Backup timer */ } echo_can_state_t; static inline void echo_can_free(echo_can_state_t *ec) @@ -118,6 +123,7 @@ static inline short echo_can_update(echo_can_state_t *ec, short iref, short isig printf("start: %d, finish: %d\n", ec->start, ec->finish); #endif +#ifdef COEFF_BACKUP if (!ec->backup) { /* Backup coefficients periodically */ ec->backup = BACKUP; @@ -125,6 +131,7 @@ static inline short echo_can_update(echo_can_state_t *ec, short iref, short isig memcpy(ec->b,ec->a,sizeof(ec->b)); } else ec->backup--; +#endif /* Remove old samples from reference power calculation */ ec->refpwr -= (ec->ref.buf[ec->pos] * ec->ref.buf[ec->pos]); @@ -141,6 +148,11 @@ static inline short echo_can_update(echo_can_state_t *ec, short iref, short isig for (x=0;xtaps;x++) se += ec->a[x] * ec->ref.buf[ec->pos + x]; +#if 0 + if (!(ec->pos2++ % 1024)) { + printk("sig: %d, se: %d\n", (int)(32768.0 * sig), (int)(32768.0 * se)); + } +#endif u = sig - se; if (ec->hcntr) ec->hcntr--; @@ -169,14 +181,16 @@ static inline short echo_can_update(echo_can_state_t *ec, short iref, short isig } } } else { +#ifdef COEFF_BACKUP if (!ec->hcntr) { /* Our double talk detector is turning on for the first time. Revert our coefficients, since we're probably well into the double talk by now */ memcpy(ec->a, ec->c, sizeof(ec->a)); } + ec->backup = BACKUP; +#endif /* Reset hang-time counter, and prevent backups */ ec->hcntr = HANG_TIME; - ec->backup = BACKUP; } } #ifndef NO_ECHO_SUPPRESSOR @@ -202,9 +216,11 @@ static inline echo_can_state_t *echo_can_create(int taps, int adaption_mode) taps = NTAPS; ec = MALLOC(sizeof(echo_can_state_t)); if (ec) { - printk("Allocating MEC3 canceller\n"); - memset(ec, 0, sizeof(ec)); + printk("Allocating MEC3 canceller (%d)\n", taps); + memset(ec, 0, sizeof(echo_can_state_t)); ec->taps = taps; + if (ec->taps > NTAPS) + ec->taps = NTAPS; ec->pos = ec->taps-1; } return ec; -- cgit v1.2.3