misc/67995: Morse plays beeps 10 times faster than it should.

Jukka A. Ukkonen Jukka.Ukkonen at mawit.com
Wed Jun 16 05:50:55 GMT 2004


The following reply was made to PR misc/67995; it has been noted by GNATS.

From: "Jukka A. Ukkonen" <Jukka.Ukkonen at mawit.com>
To: freebsd-gnats-submit at FreeBSD.org, jau at 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 <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;
 @@ -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;


More information about the freebsd-bugs mailing list