diff options
author | mattf <mattf@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2005-02-25 21:13:41 +0000 |
---|---|---|
committer | mattf <mattf@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2005-02-25 21:13:41 +0000 |
commit | 387025b1cb918f00acf049f0c7302df62d1fcf7f (patch) | |
tree | fa0a548335f313bd7471091d334b9fbeecbff488 /fxotune.c | |
parent | 9766cfb0f98398939d9259a35e449b6c5d1d1f0c (diff) |
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.
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@594 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'fxotune.c')
-rwxr-xr-x | fxotune.c | 51 |
1 files changed, 31 insertions, 20 deletions
@@ -50,18 +50,6 @@ static short outbuf[TEST_DURATION]; 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 @@ static float power_of(void *prebuf, int bufsize, int short_format) 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 @@ static float power_of(void *prebuf, int bufsize, int short_format) } } + 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); + + finalanswer = square_of_sums - sum_of_squares; + + if (debug) printf("finalanswer = %f\n", finalanswer); - if (finalanswer < 0) + 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 @@ static int acim_tune(int whichzap, char *dialstr) /* 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 main (int argc , char **argv) int fd; int res = 0; int configfd; + FILE *fp = NULL; if ((argc < 2) || (argc > 3)) { /* Show usage */ @@ -439,7 +448,7 @@ int main (int argc , char **argv) } if (!strcasecmp(argv[1], "-s")) { - FILE *fp = NULL; +set: fp = fopen(configfile, "r"); @@ -548,6 +557,8 @@ int main (int argc , char **argv) } close(configfd); + /* Some getto goto hackery to make this more convenient */ + goto set; } return 0; |