[Asterisk-cvs] zaptel fxotune.c,1.17,1.18
mattf at lists.digium.com
mattf at lists.digium.com
Fri Feb 25 15:15:34 CST 2005
Update of /usr/cvsroot/zaptel
In directory mongoose.digium.com:/tmp/cvs-serv27673
Modified Files:
fxotune.c
Log Message:
Fixed fxotune utility. It now can automatically find the best impedance and
other values for the line. If you are having problems with echo on your
FXO modules, take a look at this utility. It should fix most of your echo
issues.
Index: fxotune.c
===================================================================
RCS file: /usr/cvsroot/zaptel/fxotune.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- fxotune.c 11 Feb 2005 15:50:05 -0000 1.17
+++ fxotune.c 25 Feb 2005 21:13:41 -0000 1.18
@@ -50,18 +50,6 @@
static int debug = 0;
-#if 0
-int process_readbuf(short *ibuf)
-{
- int sum=0;
- int x;
- for (x=0;x<BUFFER_LENGTH;x++) {
- sum += abs(ibuf[x]);
- }
- return sum;
-}
-#endif
-
/* Generates a tone of hz frequency. Index is the current sample
* to begenerated. For a normal waveform you need to increment
* this every time you execute the function.
@@ -96,8 +84,16 @@
numsamples = bufsize / 2;
for (i = 0; i < numsamples; i++) {
+#if 0
sum_of_squares += ((float)sbuf[i] * (float)sbuf[i])/(float)32768;
- square_of_sums += (float)sbuf[i]/(float)32768;
+#endif
+ sum_of_squares += ((float)sbuf[i] * (float)sbuf[i]);
+ if (sbuf[i] > 0) {
+ square_of_sums += (float)sbuf[i];
+ } else {
+ sbuf[i] *= -1;
+ square_of_sums += (float)sbuf[i];
+ }
}
} else {
/* Version for float inputs */
@@ -107,12 +103,23 @@
}
}
+ if (debug) printf("sum_of_squares = %f\n", sum_of_squares);
+
square_of_sums *= square_of_sums; /* sums ^ 2 */
- finalanswer = sum_of_squares - square_of_sums;
+ if (debug) printf("square_of_sums = %f\n", square_of_sums);
- if (finalanswer < 0)
+ finalanswer = square_of_sums - sum_of_squares;
+
+ if (debug) printf("finalanswer = %f\n", finalanswer);
+
+ if (finalanswer < 0) {
+ printf("Error: Final answer negative number %f\n", finalanswer);
return -3;
+ }
+#if 0
+ finalanswer = finalanswer * (float)-1;
+#endif
return sqrtf(finalanswer);
}
@@ -407,14 +414,15 @@
/* calculate power of response */
freq_results[(freq/200)-1] = power_of(inbuf+SKIP_BYTES, BUFFER_LENGTH-SKIP_BYTES, 1);
- fprintf(outfile, "%d,%d,%f\n", i, freq, freq_results[(freq/200)-1]);
+ if (debug) fprintf(outfile, "%d,%d,%f\n", acim, freq, freq_results[(freq/200)-1]);
}
-
- acim_results[i] = power_of(freq_results, 15, 0);
+ acim_results[acim] = power_of(freq_results, 15, 0);
}
+ for (i = 0; i < 16; i++)
+ fprintf(outfile, "acim_results[%d] = %f\n", i, acim_results[i]);
/* Find out what the "best" impedance is for the line */
- lowest = 1;
+ lowest = 0;
for (i = 0; i < 16; i++) {
if (acim_results[i] < acim_results[lowest]) {
lowest = i;
@@ -431,6 +439,7 @@
int fd;
int res = 0;
int configfd;
+ FILE *fp = NULL;
if ((argc < 2) || (argc > 3)) {
/* Show usage */
@@ -439,7 +448,7 @@
}
if (!strcasecmp(argv[1], "-s")) {
- FILE *fp = NULL;
+set:
fp = fopen(configfile, "r");
@@ -548,6 +557,8 @@
}
close(configfd);
+ /* Some getto goto hackery to make this more convenient */
+ goto set;
}
return 0;
More information about the svn-commits
mailing list