Date: Thu, 17 Jun 2004 05:20:24 GMT From: "Jukka A. Ukkonen" <Jukka.Ukkonen@mawit.com> To: freebsd-bugs@FreeBSD.org Subject: Re: misc/67995: Morse plays beeps 10 times faster than it should. Message-ID: <200406170520.i5H5KO4n054244@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR misc/67995; it has been noted by GNATS. From: "Jukka A. Ukkonen" <Jukka.Ukkonen@mawit.com> To: freebsd-gnats-submit@FreeBSD.org, jau@iki.fi Cc: Subject: Re: misc/67995: Morse plays beeps 10 times faster than it should. Date: Thu, 17 Jun 2004 08:10:03 +0300 Aargh! - My second patch would make it OK for speaker output, but at the same time it obviously would break the ttyout() function on system with higher HZ than 100. So, I re-iterate once more. This time I also added morse the ability show the dot-dash patterns at the same time the speaker is playing the sound. This is beneficial if/when one wishes to use morse for learning morse code. // jau --- morse.c.orig Wed Jun 16 07:26:18 2004 +++ morse.c Thu Jun 17 07:53:30 2004 @@ -67,6 +67,33 @@ #include <machine/speaker.h> #endif +struct clockrate { + unsigned hz; + unsigned tick; + unsigned tickadj; + unsigned stathz; + unsigned profhz; +}; + +_HZ () +{ + struct clockrate rates; + size_t bufsize = sizeof (rates); + int ret; + + ret = sysctlbyname ("kern.clockrate", + (void *) &rates, &bufsize, NULL, 0); + + if (ret < 0) + return (100); /* Wild guess. */ + + return (rates.hz); +} + +static unsigned _hz; + +#define HZ (! _hz ? (_hz = _HZ ()) : _hz) + struct morsetab { char inchar; char *morse; @@ -326,14 +353,17 @@ fputs(USAGE, stderr); exit(1); } - if ((pflag || device) && sflag) { - fputs("morse: only one of -p, -d and -s allowed\n", stderr); + + if ((pflag || sflag) && device) { + fputs("morse: -d cannot be used with -p or -s\n", stderr); exit(1); } + if ((pflag || device) && ((wpm < 1) || (wpm > 60))) { fputs("morse: insane speed\n", stderr); exit(1); } + if ((pflag || device) && (freq == 0)) freq = FREQUENCY; @@ -369,12 +399,19 @@ (void)signal(SIGQUIT, sighandler); (void)signal(SIGTERM, sighandler); } - if (pflag || device) { + if (pflag) { dot_clock = wpm / 2.4; /* dots/sec */ dot_clock = 1 / dot_clock; /* duration of a dot */ dot_clock = dot_clock / 2; /* dot_clock runs at twice */ /* the dot rate */ - dot_clock = dot_clock * 100; /* scale for ioctl */ + dot_clock = dot_clock * HZ; /* scale for ioctl() */ + } + else if (device) { + dot_clock = wpm / 2.4; /* dots/sec */ + dot_clock = 1 / dot_clock; /* duration of a dot */ + dot_clock = dot_clock / 2; /* dot_clock runs at twice */ + /* the dot rate */ + dot_clock = dot_clock * 100; /* scale for usleep() */ } argc -= optind; @@ -466,7 +503,13 @@ #ifdef SPEAKER const char *c; + if (sflag) + printf(" %c", *s); + for (c = s; *c != '\0'; c++) { + if (sflag) + printf(" %c", *c); + switch (*c) { case '.': sound.frequency = freq; @@ -483,6 +526,7 @@ default: sound.duration = 0; } + if (sound.duration) { if (ioctl(spkr, SPKRTONE, &sound) == -1) { perror("ioctl play");
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200406170520.i5H5KO4n054244>