[zaptel-commits] trunk r933 - in /trunk: mg2ec.h mg2ec_const.h

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Thu Feb 2 13:00:58 MST 2006


Author: mattf
Date: Thu Feb  2 14:00:58 2006
New Revision: 933

URL: http://svn.digium.com/view/zaptel?rev=933&view=rev
Log:
More echo canceller updates for MG2.  Thanks mgernoth, you rock! (#5520)

Modified:
    trunk/mg2ec.h
    trunk/mg2ec_const.h

Modified: trunk/mg2ec.h
URL: http://svn.digium.com/view/zaptel/trunk/mg2ec.h?rev=933&r1=932&r2=933&view=diff
==============================================================================
--- trunk/mg2ec.h (original)
+++ trunk/mg2ec.h Thu Feb  2 14:00:58 2006
@@ -462,8 +462,12 @@
 		!(ec->i_d % DEFAULT_M)) {		/* we only update on every DEFAULM_M'th sample from the stream */
   			if (ec->Lu_i > MIN_UPDATE_THRESH_I) {	/* there is sufficient energy above the noise floor to contain meaningful data */
   							/* so loop over all the filter coefficients */
-#ifdef FILTER_PERCENT
-				int max = 0, max2 = 0;
+#ifdef USED_COEFFS
+				int max_coeffs[USED_COEFFS];
+				int *pos;
+
+				if (ec->N_d > USED_COEFFS)
+					memset(max_coeffs, 0, USED_COEFFS*sizeof(int));
 #endif
 #ifdef MEC2_STATS_DETAILED
 				printk( KERN_INFO "updating coefficients with: ec->Lu_i %9d\n", ec->Lu_i);
@@ -482,21 +486,29 @@
 					ec->a_i[k] += grad2 / two_beta_i;
 					ec->a_s[k] = ec->a_i[k] >> 16;
 
-#ifdef FILTER_PERCENT
-					/* Find the peaks */
-					if (abs(ec->a_i[k]) > max)
-					{
-						max2 = max;
-						max = abs(ec->a_i[k]);
+#ifdef USED_COEFFS
+					if (ec->N_d > USED_COEFFS) {
+						if (abs(ec->a_i[k]) > max_coeffs[USED_COEFFS-1]) {
+							/* More or less insertion-sort... */
+							pos = max_coeffs;
+							while (*pos > abs(ec->a_i[k]))
+								pos++;
+
+							if (*pos > max_coeffs[USED_COEFFS-1])
+								memmove(pos+1, pos, (USED_COEFFS-(pos-max_coeffs)-1)*sizeof(int));
+
+							*pos = abs(ec->a_i[k]);
+						}
 					}
 #endif
 				}
 
-#ifdef FILTER_PERCENT
+#ifdef USED_COEFFS
 				/* Filter out irrelevant coefficients */
-				for (k=0; k < ec->N_d; k++)
-					if (abs(ec->a_i[k]) < (max2*FILTER_PERCENT)/100)
-						ec->a_i[k] = ec->a_s[k] = 0;
+				if (ec->N_d > USED_COEFFS)
+					for (k=0; k < ec->N_d; k++)
+						if (abs(ec->a_i[k]) < max_coeffs[USED_COEFFS-1])
+							ec->a_i[k] = ec->a_s[k] = 0;
 #endif
 		 	 } else { 
 #ifdef MEC2_STATS_DETAILED

Modified: trunk/mg2ec_const.h
URL: http://svn.digium.com/view/zaptel/trunk/mg2ec_const.h?rev=933&r1=932&r2=933&view=diff
==============================================================================
--- trunk/mg2ec_const.h (original)
+++ trunk/mg2ec_const.h Thu Feb  2 14:00:58 2006
@@ -62,11 +62,14 @@
  * the input-signal */
 #define MAX_SIGN_ERROR 3000
 
-/* Filter out coefficients which are smaller than this
- * percentage of the second biggest coefficient.
- * If you comment out this define, the filtering-code will
- * not be used */
-#define FILTER_PERCENT 1
+/* Number of coefficients really used for calculating the
+ * simulated echo. The value specifies how many of the
+ * biggest coefficients are used for calculating rs.
+ * This helps on long echo-tails by artificially limiting
+ * the number of coefficients for the calculation and
+ * preventing overflows.
+ * Comment this to deactivate the code */
+#define USED_COEFFS 64
 
 /* Backup coefficients every this number of samples */
 #define BACKUP 256



More information about the zaptel-commits mailing list