summaryrefslogtreecommitdiff
path: root/fxotune.c
diff options
context:
space:
mode:
Diffstat (limited to 'fxotune.c')
-rwxr-xr-xfxotune.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/fxotune.c b/fxotune.c
index 8560e75..2726e13 100755
--- a/fxotune.c
+++ b/fxotune.c
@@ -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;