From owner-freebsd-bugs@FreeBSD.ORG Thu Jun 17 05:21:23 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B0BC416A4CE for ; Thu, 17 Jun 2004 05:21:23 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 92B2C43D41 for ; Thu, 17 Jun 2004 05:21:23 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i5H5KOs0054245 for ; Thu, 17 Jun 2004 05:20:24 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i5H5KO4n054244; Thu, 17 Jun 2004 05:20:24 GMT (envelope-from gnats) Date: Thu, 17 Jun 2004 05:20:24 GMT Message-Id: <200406170520.i5H5KO4n054244@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: "Jukka A. Ukkonen" Subject: Re: misc/67995: Morse plays beeps 10 times faster than it should. X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: "Jukka A. Ukkonen" List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jun 2004 05:21:24 -0000 The following reply was made to PR misc/67995; it has been noted by GNATS. From: "Jukka A. Ukkonen" 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 #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");