From: Ben Pfaff Date: Sun, 13 Dec 2009 22:15:43 +0000 (-0800) Subject: Rewrite to use video4linux2 API. X-Git-Url: https://repo.or.cz/w/fmtools.git/commitdiff_plain/0dfff45e7649b86ae9bc2d5547300138860a863a Rewrite to use video4linux2 API. - Add "-q" (quiet) and "-T" (tuner) options to fmscan. - Improve fmscan frequency calculations. It should now be better at accurately finding radio stations. - Add Autotest test suite and, in the process, convert the packaging to use Autoconf and Automake. - Some code and some documentation used a range of 0-65535 for volume, other code and other documentation used a range of 0-100. This has been consistently changed to 0-100. --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92482d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +/.deps +/Makefile +/Makefile.in +/aclocal.m4 +/atconfig +/atlocal +/autom4te.cache +/build-aux +/config.log +/config.status +/configure +/fm +/fmscan +/package.m4 +/testsuite +/testsuite.log +/fmtools-*.tar.gz diff --git a/CHANGES b/CHANGES index ee49482..7d20a6c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,21 @@ +2.0: + +Sat Dec 12 21:18:52 PST 2009 / Ben Pfaff + +- Rewrite to use video4linux2 API. + +- Add "-q" (quiet) and "-T" (tuner) options to fmscan. + +- Improve fmscan frequency calculations. It should now be better at + accurately finding radio stations. + +- Add Autotest test suite and, in the process, convert the packaging + to use Autoconf and Automake. + +- Some code and some documentation used a range of 0-65535 for volume, + other code and other documentation used a range of 0-100. This has + been consistently changed to 0-100. + 1.0.2: Thu Nov 23 1:41:00 PDT 2006 / Ben Pfaff diff --git a/Makefile b/Makefile deleted file mode 100644 index 2bdcb61..0000000 --- a/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -# fmtools Makefile - just the basics for now - -CC = gcc -CFLAGS = -Wall -O2 - -INSTALL = /usr/bin/install - -# Since fmtools doesn't use configure, these paths are provided here -# to make packaging easier. Just override them when doing 'make install'. - -BINPATH = $(DESTDIR)/usr/local/bin -BINMODE = 0755 -MANPATH = $(DESTDIR)/usr/local/man/man1 -MANMODE = 0644 - -TARGETS = fm fmscan - -all: $(TARGETS) - -fm: fm.c - $(CC) $(CFLAGS) -o fm fm.c -lm - -fmscan: fmscan.c - $(CC) $(CFLAGS) -o fmscan fmscan.c -lm - -clean: - rm -f *~ *.o $(TARGETS) - -install: all install-bin install-man - -install-bin: - if (test ! -d $(BINPATH)); \ - then \ - mkdir -p $(BINPATH); \ - fi - for f in $(TARGETS) ; do \ - $(INSTALL) -m $(BINMODE) $$f $(BINPATH); \ - done - -install-man: - if (test ! -d $(MANPATH)); \ - then \ - mkdir -p $(MANPATH); \ - fi - for f in $(TARGETS) ; do \ - $(INSTALL) -m $(MANMODE) $$f.1 $(MANPATH); \ - done - -devices: - mknod /dev/radio0 c 81 64 - ln -s /dev/radio0 /dev/radio diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..fb96355 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,57 @@ +AM_CFLAGS = -Wall -Wstrict-prototypes -Wmissing-prototypes + +bin_PROGRAMS = fm fmscan + +fm_SOURCES = fm.c fmlib.c fmlib.h +fm_LDADD = -lm + +fmscan_SOURCES = fmscan.c fmlib.c fmlib.h +fmscan_LDADD = -lm + +#### The rest of this file is just for the testsuite. It is just +#### boilerplate from the Autoconf manual describing how to use +#### Autotest. + +# The `:;' works around a Bash 3.2 bug when the output is not writeable. +$(srcdir)/package.m4: $(top_srcdir)/configure.ac + :;{ \ + echo '# Signature of the current package.' && \ + echo 'm4_define([AT_PACKAGE_NAME],' && \ + echo ' [@PACKAGE_NAME@])' && \ + echo 'm4_define([AT_PACKAGE_TARNAME],' && \ + echo ' [@PACKAGE_TARNAME@])' && \ + echo 'm4_define([AT_PACKAGE_VERSION],' && \ + echo ' [@PACKAGE_VERSION@])' && \ + echo 'm4_define([AT_PACKAGE_STRING],' && \ + echo ' [@PACKAGE_STRING@])' && \ + echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \ + echo ' [@PACKAGE_BUGREPORT@])'; \ + echo 'm4_define([AT_PACKAGE_URL],' && \ + echo ' [@PACKAGE_URL@])'; \ + } >'$(srcdir)/package.m4' + +EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) atlocal.in +DISTCLEANFILES = atconfig +TESTSUITE = $(srcdir)/testsuite +TESTSUITE_AT = \ + $(srcdir)/testsuite.at \ + $(srcdir)/test-fm.at \ + $(srcdir)/test-fmscan.at \ + $(srcdir)/package.m4 + +check-local: atconfig atlocal $(TESTSUITE) + $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS) + +installcheck-local: atconfig atlocal $(TESTSUITE) + $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \ + $(TESTSUITEFLAGS) + +clean-local: + test ! -f '$(TESTSUITE)' || \ + $(SHELL) '$(TESTSUITE)' --clean + +AUTOM4TE = $(SHELL) $(srcdir)/build-aux/missing --run autom4te +AUTOTEST = $(AUTOM4TE) --language=autotest +$(TESTSUITE): $(TESTSUITE_AT) + $(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at + mv $@.tmp $@ diff --git a/README b/README index ba16781..bcb03d1 100644 --- a/README +++ b/README @@ -1,18 +1,35 @@ -* fmtools: simple Video for Linux radio card programs -* -* Russell Kroll -* -* Program support page: http://www.exploits.org/v4l/fmtools.html -* -* Released under the GNU GPL - See COPYING for details. +fmtools: simple V4L2 radio card programs + +Maintained by Ben Pfaff +Originally by Russell Kroll + +Web: http://benpfaff.org/fmtools +Git: git://repo.or.cz/fmtools.git + +License +======= + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . Package information =================== -This is a pair of hopefully useful control programs for Video for Linux -(v4l) radio card drivers. The focus is on control, so you may find these -programs a bit unfriendly. Users are encouraged to investigate the source -and create wrappers or new programs based on this design. +This is a pair of hopefully useful control programs for Video for +Linux 2 (V4L2) radio card drivers. The focus is on control, so you +may find these programs a bit unfriendly. Users are encouraged to +investigate the source and create wrappers or new programs based on +this design. fm - a simple tuner fmscan - a simple band scanner @@ -20,109 +37,102 @@ and create wrappers or new programs based on this design. fm == -This is a small controller that will send commands to your v4l radio -cards. It was written mostly so I could have something to send commands -at the drivers being created or debugged here. - -I'll discuss the options a little, but it should be fairly simple to run. +This is a simple program that will send commands to your V4L2 radio +cards. It was written mostly so I could have something to send +commands at the drivers being created or debugged here. The usual mode of operation is to tell the radio to come on to a given freqency. In these examples, 94.3 will be used since that's a station that happens to get tuned here frequently. To turn the radio on to that frequency at the default volume, you'd do -"fm 94.3" and call it done. If you wanted to crank it up to full volume, -another argument would be needed and the command becomes "fm 94.3 65535". -Volumes range from 0 (off) to 65535 (full intensity). This is a direct -link to the value used in the v4l API by the actual drivers. +"fm 94.3" and call it done. If you wanted to crank it up to full +volume, another argument would be needed and the command becomes "fm +94.3 100". Volumes range from 0 (off) to 100 (full intensity). There is a -q option that will suppress messages about tuning, volume -changes, and so forth. Keeping your tuner quiet may not seem like such -a useful thing at first, but it can be very handy inside an IRC script. -Having a program scribble on your channel window when you do /KILO -or similar is not enjoyable. +changes, and so forth. Keeping your tuner quiet may not seem like +such a useful thing at first, but it can be very handy inside an IRC +script. Having a program scribble on your channel window when you do +/KILO or similar is not enjoyable. -Besides direct tuning, there are also "on" and "off" commands. They will -turn the card on and off (mute) as you may have guessed. +Besides direct tuning, there are also "on" and "off" commands. They +will turn the card on and off (mute) as you may have guessed. -Finally, there is volume control. To go up a notch, use +. To go down -a notch, use -. Simple. +Finally, there is volume control. To go up a notch, use +. To go +down a notch, use -. Simple. fm configuration ---------------- -You can create a file called .fmrc in your home directory that contains -values for the default volume and default volume stepping. This way, -you can have your radio card always come on at a certain volume when you -don't explicitly list it on the command line. The volume stepping -controls how much the volume changes during a - or + operation. +You can create a file called .fmrc in your home directory that +contains values for the default volume and default volume stepping. +This way, you can have your radio card always come on at a certain +volume when you don't explicitly list it on the command line. The +volume stepping controls how much the volume changes during a - or + +operation. -This file is not required for operation of the program, and it will not -even give so much as a peep if it doesn't find it. The defaults are -used when you don't specify values. The values are 12.5% for default -volume and 10% for default volume stepping. +This file is not required for operation of the program, and it will +not even give so much as a peep if it doesn't find it. The defaults +are used when you don't specify values. The values are 12.5% for +default volume and 10% for default volume stepping. Here's what a real .fmrc might look like ... -VOL 32000 -INCR 6554 +VOL 50 +INCR 10 -Here we say the default volume is 32000 - just shy of 50%. Then we -say the increment value for volume changes with + and - is 6554 - -approximately 10%. These values were obtained by playing around with -the numbers until things behaved the way I wanted. Be aware that some -cards only have a couple of volume steps, so you may not notice a change -right away. +Here we say the default volume is 50%. Then we say the increment +value for volume changes with + and - is 10%. These values were +obtained by playing around with the numbers until things behaved the +way I wanted. Be aware that some cards only have a couple of volume +steps, so you may not notice a change right away. -The Cadet hardware, for example, has two settings: off and *VERY LOUD*. -Any volume setting will turn it on. The Aztech card has 4 settings (off, -low, medium, high) and you'll notice it change when you cross the -boundaries. The Aimslab RadioReveal card is actually based on analog -volume control, with 10 steps emulated within that range. +The Cadet hardware, for example, has two settings: off and *VERY +LOUD*. Any volume setting will turn it on. The Aztech card has 4 +settings (off, low, medium, high) and you'll notice it change when you +cross the boundaries. The Aimslab RadioReveal card is actually based +on analog volume control, with 10 steps emulated within that range. There are some other options available: --d - select device. If you have more than one v4l radio card in your - system for some reason, use -d to select the right one. - This is probably only useful if you like writing drivers for these - things. +-d - select device. If you have more than one V4L2 radio card in your + system for some reason, use -d to select the right one. + This is probably only useful if you like writing drivers for + these things. -o - override card frequency range - Some radio card drivers don't actively enforce the frequencies that you can tune to. Use this - switch and fm will send any frequency you want to the driver. This - alone will not make an unmodified card receive frequencies from - outside the design range. You have to change the tuner hardware in - order to enjoy such broadcasts. + switch and fm will send any frequency you want to the driver. + This alone will not make an unmodified card receive frequencies + from outside the design range. You have to change the tuner + hardware in order to enjoy such broadcasts. --t - select tuner - Certain cards have multiple tuners - usually used for - different bands. The ADS Cadet driver is known to support this, - specifically using 0 for FM and 1 for AM. To tune AM frequencies, - remember that fm expects MHz style input, and do the following: +-t - select tuner - Certain cards have multiple tuners - usually used + for different bands. The ADS Cadet driver is known to support + this, specifically using 0 for FM and 1 for AM. To tune AM + frequencies, remember that fm expects MHz style input, and do the + following: For 1200 kHz, enter 'fm -t 1 1.2', since 1.2 MHz == 1200 kHz. Yes, tuning am frequencies with 'fm' seems backwards, but that's - life. Crafty hackers may want to add some code to make the program - check argv[0] and behave differently. + life. Crafty hackers may want to add some code to make the + program check argv[0] and behave differently. fmscan ====== -This simple little program will command your radio card through the radio -band and show which ones have a accumulated signal strength of 50% or -higher. This process can take awhile, and can vary greatly depending on -the radio card in use. +This simple little program will command your radio card through the +radio band and show which ones have a accumulated signal strength of +50% or higher. This process can take awhile, and can vary greatly +depending on the radio card in use. By default, the range scanned is 87.9-107.9 MHz in .2 MHz steps, since -that's the standard band here in the USA. Users in other regions should -set the appropriate information for best results. - -This program may not do much if your radio card's driver doesn't support -fine tuning in 1/16000 MHz offsets. By default, v4l assumes 1/16 MHz -tuning units, which introduces evil rounding errors on many frequencies. -If in doubt, grep for VIDEO_TUNER_LOW in your driver's source. +that's the standard band here in the USA. Users in other regions +should set the appropriate information for best results. -v4l /dev entries +V4L2 /dev entries ================ By default, these programs use /dev/radio0 to access the hardware. This @@ -148,16 +158,3 @@ making the device part of a "radio" group or maybe even "console" if you use such a thing. That will keep random individuals from doing odd things to your radio like changing it to a classical station while you're listening to some death metal (or vice versa). You have been warned. - -Old interim Linux 2.1 /dev/radio interface -========================================== - -Around 2.1.60, there was another /dev/radio specification that controlled -two boards - namely the AIMSLab RadioTrack and later the Aztech/Packard -Bell radio card. This didn't last very long, as the entire radio card -driver tree was eventually redone under the expanded Video for Linux API. - -These programs are not compatible with that interface. Very few things -are. If you are still using it, you should throw it away and upgrade to -the v4l drivers. There have been many improvements since then, and you -will be able to use the fmtools programs on your card. diff --git a/atlocal.in b/atlocal.in new file mode 100644 index 0000000..e69de29 diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..42fdcfd --- /dev/null +++ b/configure.ac @@ -0,0 +1,9 @@ +AC_INIT([fmtools], [2.0], [blp@cs.stanford.edu]) +AC_CONFIG_AUX_DIR([build-aux]) +AM_INIT_AUTOMAKE([foreign]) +AC_PREREQ([2.59]) +AC_CONFIG_SRCDIR([fm.c]) +AC_PROG_CC +AC_CONFIG_TESTDIR([.]) +AC_CONFIG_FILES([Makefile atlocal]) +AC_OUTPUT diff --git a/fm.1 b/fm.1 index 4b5387d..8d65be8 100644 --- a/fm.1 +++ b/fm.1 @@ -128,9 +128,6 @@ Additional documentation: .TP The fmtools homepage: .B http://benpfaff.org/fmtools -.TP -The video4linux webpage: -.B http://www.exploits.org/v4l/ .SH AUTHORS Russell Kroll , now maintained by Ben Pfaff . Sleep time feature contributed by Dave Ulrick diff --git a/fm.c b/fm.c dissimilarity index 76% index dc148a8..be76ce1 100644 --- a/fm.c +++ b/fm.c @@ -1,411 +1,307 @@ -/* fm.c - simple v4l compatible tuner for radio cards - - Copyright (C) 1998 Russell Kroll - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "videodev.h" - -#include "version.h" - -#define DEFAULT_DEVICE "/dev/radio0" - - - -static int convert_time (const char *string) -{ - if (strcmp (string, "forever") == 0 || - strcmp (string, "-") == 0 || - atoi (string) < 0) - return 0; - else if (strcmp (string, "none") == 0 || - strcmp (string, "0") == 0) - return -1; - else - { - char worktime[80+1]; - int inttime; - const char *suffix; - - suffix = string + strspn (string, "0123456789"); - - strncpy (worktime, string, suffix - string); - worktime[suffix - string] = '\0'; - inttime = atoi (worktime); - - switch (*suffix) - { - case 's': - case '\0': - break; - case 'm': - inttime *= 60; - break; - case 'h': - inttime *= 60 * 60; - break; - case 'd': - inttime *= 24 * 60 * 60; - break; - default: - break; - } - - return inttime; - } -} - - - -static char *format_time (char *buffer, - const char *string) -{ - if (strcmp (string, "forever") == 0 || - strcmp (string, "-") == 0 || - atoi (string) < 0) - strcpy (buffer, "forever"); - else if (strcmp (string, "none") == 0 || - strcmp (string, "0") == 0) - strcpy (buffer, "none"); - else - { - char worktime[80+1]; - const char *suffix; - char *format; - int int_time; - - suffix = string + strspn (string, "0123456789"); - strncpy (worktime, string, suffix - string); - worktime[suffix - string] = '\0'; - int_time = atoi (worktime); - - switch (*suffix) - { - case 'm': - format = "%d minute(s)"; - break; - case 'h': - format = "%d hour(s)"; - break; - case 'd': - format = "%d day(s)"; - break; - case 's': - case '\0': - default: - format = "%d second(s)"; - break; - } - - sprintf (buffer, format, int_time); - } - - return buffer; -} - - - -static void maybe_sleep (const char *wait_time) -{ - char message[80+1]; - int int_wait_time; - - int_wait_time = convert_time (wait_time); - - if (int_wait_time > 0) - { - printf ("Sleeping for %s\n", format_time (message, wait_time)); - sleep (int_wait_time); - } - else if (int_wait_time == 0) - { - printf ("Sleeping forever...CTRL-C exits\n"); - do { - sleep (INT_MAX); - } while (1); - } -} - - - -void help(char *prog) -{ - printf("fmtools fm version %s\n\n", FMT_VERSION); - printf("usage: %s [-h] [-o] [-q] [-d ] [-t ] " - "[-T none|forever|time] |on|off []\n\n", - prog); - printf("A small controller for Video for Linux radio devices.\n\n"); - printf(" -h display this help\n"); - printf(" -o override frequency range limits of card\n"); - printf(" -q quiet mode\n"); - printf(" -d select device (default: /dev/radio0)\n"); - printf(" -t select tuner (default: 0)\n"); - printf(" -T