add the crude afc option to float_to_bits.c too

This commit is contained in:
sq5bpf 2016-02-03 12:19:32 +01:00 committed by Harald Welte
parent a6b961a755
commit c07f324085
1 changed files with 30 additions and 7 deletions

View File

@ -17,6 +17,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 20160203: added crude AFC option --sq5bpf
*/
@ -79,19 +80,29 @@ int main(int argc, char **argv)
int fd, fd_out, opt;
int opt_verbose = 0;
int do_afc=0;
float filter=0;
float filter_val=0.0001;
int ccounter=0;
while ((opt = getopt(argc, argv, "v")) != -1) {
while ((opt = getopt(argc, argv, "vaf:F:")) != -1) {
switch (opt) {
case 'v':
opt_verbose = 1;
break;
default:
exit(2);
case 'v':
opt_verbose++;
break;
case 'a':
do_afc=1;
break;
case 'f':
filter_val=atof(optarg);
break;
default:
exit(2);
}
}
if (argc <= optind+1) {
fprintf(stderr, "Usage: %s [-v] <infile> <outfile>\n", argv[0]);
fprintf(stderr, "Usage: %s [-v] [-a] [-f filter_averaging_coefficient] <infile> <outfile>\n", argv[0]);
exit(2);
}
@ -119,12 +130,24 @@ int main(int argc, char **argv)
rc /= sizeof(*fl);
int i;
for (i = 0; i < rc; ++i) {
#define MAXVAL 5.0 /* this is the maximum value we'll accept for the incoming floats */
if ((fl[i] > -MAXVAL) && (fl[i] < MAXVAL))
filter = filter * (1.0 - filter_val) + fl[i] * filter_val;
if (do_afc)
fl[i] = fl[i] - filter;
int sym = process_sym_fl(fl[i]);
sym_int2bits(sym, bits + i*2);
//printf("%2d %1u %1u %f\n", rc, bits[0], bits[1], fl);
if (opt_verbose) {
printf("%1u%1u", bits[2*i + 0], bits[2*i + 1]);
}
if (do_afc && (opt_verbose > 1)) {
ccounter++;
if (ccounter > 50) {
printf(" AFC: %f\n",filter); ccounter=0;
}
}
}
rc = write(fd_out, bits, rc * 2);