From nobody@FreeBSD.org  Wed Jun 16 04:44:37 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 90CBD16A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 16 Jun 2004 04:44:37 +0000 (GMT)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 892AF43D31
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 16 Jun 2004 04:44:37 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i5G4iaci054733
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 16 Jun 2004 04:44:36 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.11/8.12.11/Submit) id i5G4iaGe054732;
	Wed, 16 Jun 2004 04:44:36 GMT
	(envelope-from nobody)
Message-Id: <200406160444.i5G4iaGe054732@www.freebsd.org>
Date: Wed, 16 Jun 2004 04:44:36 GMT
From: "Jukka A. Ukkonen" <jau@iki.fi>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Morse plays beeps 10 times faster than it should.
X-Send-Pr-Version: www-2.3

>Number:         67995
>Category:       bin
>Synopsis:       [patch] morse(6) plays beeps 10 times faster than it should.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    brian
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jun 16 04:50:19 GMT 2004
>Closed-Date:    Thu Jul 12 07:07:14 GMT 2007
>Last-Modified:  Thu Jul 12 07:10:10 GMT 2007
>Originator:     Jukka A. Ukkonen
>Release:        FreeBSD 4.10-STABLE
>Organization:
>Environment:
FreeBSD mjolnir 4.10-STABLE FreeBSD 4.10-STABLE #0: Tue Jun 15 16:28:00 EET DST 2004     jau@mjolnir:/usr/src/sys/compile/Mjolnir  i386
>Description:
      The morse program has a scaling problem while counting the proper
dot_clock (dot length) value. As a result the dot duration becomes only
1/10 of what it should be.

>How-To-Repeat:
      morse -p whatever

You will hear only insane sqeeking.
Multiply the dot duration by 10 (add -w2 to the command) and your morse
comes out just fine.

>Fix:
      Apply the patch below. (Tab characters have been preserved by
importing the patch via xcut and xclipboard.)


--- morse.c.orig	Wed Jun 16 07:26:18 2004
+++ morse.c	Wed Jun 16 07:28:32 2004
@@ -374,7 +374,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 * 1000;	/* scale for ioctl */
 	}
 
 	argc -= optind;

>Release-Note:
>Audit-Trail:

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: 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;

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");

From: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk>
To: bug-followup@FreeBSD.org, jau@iki.fi
Cc:  
Subject: Re: bin/67995: [patch] morse(6) plays beeps 10 times faster than
	it should.
Date: Mon, 21 May 2007 17:45:36 +0100

 Hi,
 
 The correct fix for this is probably to fix the driver in the kernel, is
 it possible to try the fix in i386/70610 and see if that solves your
 problem?
 
 Thanks,
 
 Gavin
State-Changed-From-To: open->feedback 
State-Changed-By: remko 
State-Changed-When: Mon May 21 17:08:01 UTC 2007 
State-Changed-Why:  
The submitter had been asked for feedback 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67995 

From: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk>
To: jau@iki.fi, bug-followup@freebsd.org
Cc:  
Subject: Re: bin/67995: [patch] morse(6) plays beeps 10 times faster than
Date: Wed, 23 May 2007 15:58:53 +0100

 I've just tested it (sorry for the word wrap)
 
 kldload speaker
 morse -p test
   (beeps play far too fast)
 kldunload speaker
 cd /usr/src/sys/dev/speaker
 fetch -o spkr.diff \
      "http://www.freebsd.org/cgi/query-pr.cgi?pr=70610&getpatch=1"
 patch < spkr.diff
 cd /usr/src/sys/modules/speaker
 make all
 kldload ./speaker.ko
 morse -p test
   (beeps play at a realistic speed)
 
 If you (submitter) could test that and make sure you get the same
 result, then that would be excellent, otherwise I think that's all the
 proof I need to say that the correct fix is in kern/70610
 
 Gavin

From: Gavin Atkinson <gavin.atkinson@ury.york.ac.uk>
To: bug-followup@FreeBSD.org, jau@iki.fi
Cc:  
Subject: Re: bin/67995: [patch] morse(6) plays beeps 10 times faster than
	it should.
Date: Thu, 24 May 2007 12:16:49 +0100

 The correct fix for this is to fix the kernel driver, the patch in
 kern/70610 does this.  The submitter is happy with closing this PR - he
 intends to submit another PR with the extra functionality in the third
 diff as a new PR.
State-Changed-From-To: feedback->closed 
State-Changed-By: linimon 
State-Changed-When: Thu May 24 13:35:55 UTC 2007 
State-Changed-Why:  
See the patch in kern/70610. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67995 
State-Changed-From-To: closed->patched 
State-Changed-By: brian 
State-Changed-When: Mon Jun 4 08:36:26 UTC 2007 
State-Changed-Why:  
This has been fixed by spkr.c 1.71 which corrects the 
speaker driver so that it expects durations in 1/100ths 
of a second (as documented in spkr(4)) rather than in 
HZ.  The fix will be MFC'd in 2 weeks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67995 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/67995: commit references a PR
Date: Mon,  4 Jun 2007 08:33:24 +0000 (UTC)

 brian       2007-06-04 08:33:18 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/dev/speaker      spkr.c 
   Log:
   Speaker durations are specified in 1/100ths of a second according to
   spkr(4).
   
   PR:             70610, 67995
   Submitted by:   dada at sbox dot tugraz dot at (modulo one fix)
   MFC after:      2 weeks
   
   Revision  Changes    Path
   1.71      +19 -15    src/sys/dev/speaker/spkr.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
Responsible-Changed-From-To: freebsd-bugs->brian 
Responsible-Changed-By: brian 
Responsible-Changed-When: Mon Jun 4 18:47:50 UTC 2007 
Responsible-Changed-Why:  
Become responsible so it's clear who's gonna MFC 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67995 
State-Changed-From-To: patched->closed 
State-Changed-By: brian 
State-Changed-When: Thu Jul 12 07:06:56 UTC 2007 
State-Changed-Why:  
The fix has been MFC'd (spkr.c 1.70.2.2) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=67995 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/67995: commit references a PR
Date: Thu, 12 Jul 2007 07:05:51 +0000 (UTC)

 brian       2007-07-12 07:05:43 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     sys/dev/speaker      spkr.c 
   Log:
   MFC: Speaker durations are specified in 1/100ths of a second according to
        spkr(4).
   
   PR:             70610, 67995
   
   Revision  Changes    Path
   1.70.2.2  +21 -17    src/sys/dev/speaker/spkr.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
