From owner-freebsd-bugs@FreeBSD.ORG Wed Jun 16 05:50:55 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 289A916A4CE for ; Wed, 16 Jun 2004 05:50:55 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 208A143D45 for ; Wed, 16 Jun 2004 05:50:55 +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 i5G5oWnY088087 for ; Wed, 16 Jun 2004 05:50:32 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i5G5oW43088085; Wed, 16 Jun 2004 05:50:32 GMT (envelope-from gnats) Date: Wed, 16 Jun 2004 05:50:32 GMT Message-Id: <200406160550.i5G5oW43088085@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: Wed, 16 Jun 2004 05:50:55 -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: Wed, 16 Jun 2004 08:46:09 +0300 In fact there could be a better fix, because it seems the speaker ioctl() interface is depending on the system HZ value. We just fetch the real HZ value from the kernel and use that as the multiplier for the speaker ioctl() duration field. This became sort of a lengthy patch for a small thing, because the system does not provide HZ as part of the standard API. // jau --- morse.c.orig Wed Jun 16 07:26:18 2004 +++ morse.c Wed Jun 16 08:32:37 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; @@ -374,7 +401,7 @@ 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 */ } argc -= optind;