NetBSD Problem Report #14819

Received: (qmail 10811 invoked from network); 3 Dec 2001 07:14:39 -0000
Message-Id: <E16AnLl-0004ZR-00@c1731831-a.crvlls1.or.home.com>
Date: Sun, 02 Dec 2001 23:17:13 -0800
From: collver@linuxfreemail.com
Sender: ",,," <ben@c1731831-a.crvlls1.or.home.com>
Reply-To: collver@linuxfreemail.com
To: gnats-bugs@gnats.netbsd.org
Subject: changing ym /dev/audio encoding is unreliable
X-Send-Pr-Version: 3.95

>Number:         14819
>Category:       kern
>Synopsis:       changing ym /dev/audio encoding is unreliable
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 03 07:15:00 +0000 2001
>Closed-Date:    Wed Mar 27 14:01:14 +0000 2002
>Last-Modified:  Wed Mar 27 14:01:14 +0000 2002
>Originator:     
>Release:        NetBSD 1.5.2
>Organization:
>Environment:
System: NetBSD glen 1.5.2 NetBSD 1.5.2 (GLEN) #0: Fri Nov 23 10:42:08 PST 2001 root@glen:/usr/src/sys/arch/i386/compile/GLEN i386


>Description:
	I am using an OPL3-SA3 card with the ym driver.  When I open /dev/audio
	and set the encoding/precision/rate, sometimes the settings don't
	actually take effect.  The ioctl does not return an error, and
	audioctl reports the settings that ought to be in place.  But the
	audio sounds terrible.

	If I use "audioctl -w play=$(audioctl play|cut -d = -f 2)" in the
	middle of incorrect playback, the audio starts playing correctly.

	I discovered this problem when all my SDL applications stopped
	working when I switched from my SoundBlaster to my OPL3-SA3 card.

>How-To-Repeat:
	Code to demonstrate the problem:
		http://amaterasu.math.orst.edu:8080/~sharpej/ym-test.c
		http://amaterasu.math.orst.edu:8080/~sharpej/sine.raw

	on my machine, using ym-test.c:
	example 1 sometimes plays a sine wave, sometimes plays hideous static
	example 2 always plays hideous static
	examples 3 and 4 always play a sine wave

>Fix:
	A workaround is to configure software to use /dev/sound
	instead of /dev/audio
>Release-Note:
>Audit-Trail:

From: itohy@netbsd.org (ITOH Yasufumi)
To: collver@linuxfreemail.com
Cc: netbsd-bugs@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/14819: changing ym /dev/audio encoding is unreliable
Date: Wed, 27 Feb 2002 19:07:01 +0900 (JST)

 In article <E16AnLl-0004ZR-00@c1731831-a.crvlls1.or.home.com>
 collver@linuxfreemail.com writes:

 > >How-To-Repeat:
 > 	Code to demonstrate the problem:
 > 		http://amaterasu.math.orst.edu:8080/~sharpej/ym-test.c
 > 		http://amaterasu.math.orst.edu:8080/~sharpej/sine.raw

 Hmm, I tried this but I can't reproduce the problem on my Libretto
 (MMX 166MHz, audio chip revision 5 ("audioctl version" output)).

 Can anyone reproduce this problem?

 One possibility is that the calibration of CODEC is timed out.
 Does it change if you modify magic constants (100, 10000 etc) in
 	sys/dev/ic/ad1848.c::wait_for_calibration()
 	sys/dev/ic/ad1848.c::ad1848_commit_settings()
 or somewhere?
 -- 
 ITOH Yasufumi

From: collver@linuxfreemail.com
To: ITOH Yasufumi <itohy@netbsd.org>
Cc: netbsd-bugs@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/14819: changing ym /dev/audio encoding is unreliable
Date: Wed, 27 Feb 2002 07:40:16 -0800

 On Wed, Feb 27, 2002 at 07:07:01PM +0900, ITOH Yasufumi wrote:
 > Hmm, I tried this but I can't reproduce the problem on my Libretto
 > (MMX 166MHz, audio chip revision 5 ("audioctl version" output)).
 > 
 > One possibility is that the calibration of CODEC is timed out.
 > Does it change if you modify magic constants (100, 10000 etc) in
 > 	sys/dev/ic/ad1848.c::wait_for_calibration()
 > 	sys/dev/ic/ad1848.c::ad1848_commit_settings()
 > or somewhere?

 Thanks for the reply!

 I have a revision 1 chip.

 I tried multiplying the original magic timeouts by 10, and still had the
 same problem.  I tried dividing the original magic timeouts by 10, and
 still had the same problem.

 I reverted to the original magic timeouts, and changed
 int     ad1848debug = 0;
 to
 int     ad1848debug = 1;

 Now the problem doesn't happen and /dev/audio works correctly.

 Ben

From: itohy@netbsd.org (ITOH Yasufumi)
To: collver@linuxfreemail.com
Cc: netbsd-bugs@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/14819: changing ym /dev/audio encoding is unreliable
Date: Thu, 28 Feb 2002 22:40:14 +0900 (JST)

 In article <20020227074015.A243@glen.takilma.net>
 collver@linuxfreemail.com writes:

 > I have a revision 1 chip.

 Interesting.  That's an OPL3-SA2 (YMF711) chip.
 SA2 and SA3 are not so much different and I think the driver works on SA2
 except for some functions are missing (SA2 doesn't have equalizer, etc.).

 > I reverted to the original magic timeouts, and changed
 > int     ad1848debug = 0;
 > to
 > int     ad1848debug = 1;
 > 
 > Now the problem doesn't happen and /dev/audio works correctly.

 Mmm, uncertainty principle... :(
 Can you try and find out which DPRINTF() are helpful?
 -- 
 ITOH Yasufumi

From: collver@linuxfreemail.com
To: netbsd-bugs@netbsd.org, gnats-bugs@gnats.netbsd.org
Cc:  
Subject: Re: kern/14819: changing ym /dev/audio encoding is unreliable
Date: Thu, 28 Feb 2002 12:20:47 -0800

 > > I have a revision 1 chip.
 > 
 > Interesting.  That's an OPL3-SA2 (YMF711) chip.
 > SA2 and SA3 are not so much different and I think the driver works on SA2
 > except for some functions are missing (SA2 doesn't have equalizer, etc.).

 You are right, this is an SA2 chip.  And I am trying to use the SA3 driver.
 Funky that it works at all, hehe.

 from my dmesg:

 ym0: OPL3-SA2 Sound Board : OPL3-SA3
 midi0 at opl0: OPL3-SA3 Yamaha OPL3
 midi1 at mpu0: OPL3-SA3 MPU-401 MIDI UART
 joy0: OPL3-SA2 Sound Board 
 isapnp0: <OPL3-SA2 Sound Board, YMH002F, , > port 0x100/8 not configured
 wdc2: OPL3-SA2 Sound Board 

 My card does have an equalizer, from mixerctl -a:
 inputs.dac=179,179
 inputs.dac.mute=off
 inputs.midi=184,184
 inputs.midi.mute=off
 inputs.cd=220,220
 inputs.cd.mute=off
 inputs.line=220,220
 inputs.line.mute=on
 inputs.speaker=0
 inputs.speaker.mute=on
 inputs.mic=0
 inputs.mic.mute=on
 monitor.monitor=0
 monitor.monitor.mute=on
 record.record=220,220
 record.record.source=mic
 outputs.master=220,220
 outputs.master.mute=off
 equalization.mode=desktop
 equalization.treble=0,0
 equalization.bass=0,0
 equalization.surround=0,0
 power.save=powersave
 power.save.timeout=5

 Ben

From: itohy@netbsd.org (ITOH Yasufumi)
To: collver@linuxfreemail.com
Cc: netbsd-bugs@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/14819: changing ym /dev/audio encoding is unreliable
Date: Fri, 22 Mar 2002 23:44:12 +0900 (JST)

   Hello,

 Will you try again with following change?
 This checks unexpected busy state of the device and print diagnosis.

 Regards,
 -- 
 ITOH Yasufumi

 Index: ad1848.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/ic/ad1848.c,v
 retrieving revision 1.13
 diff -u -r1.13 ad1848.c
 --- ad1848.c	2002/03/06 07:12:02	1.13
 +++ ad1848.c	2002/03/22 12:58:18
 @@ -236,12 +236,23 @@
  	int reg;
  {
  	int x;
 +	int t = 0;

 +	for ( ; t < 10000 && ADREAD(sc, AD1848_IADDR) & SP_IN_INIT; t++)
 +		delay(10);
 +	if (t) printf("ad_read: %d (unknown location)\n", t);
  	ADWRITE(sc, AD1848_IADDR, (reg & 0xff) | sc->MCE_bit);
  	x = ADREAD(sc, AD1848_IDATA);
  	/*  printf("(%02x<-%02x) ", reg|sc->MCE_bit, x); */
  	return x;
  }
 +#define ad_read(sc, reg) ({						\
 +	int t = 0;							\
 +	for ( ; t < 10000 && ADREAD(sc, AD1848_IADDR) & SP_IN_INIT; t++)\
 +		delay(10);						\
 +	if (t) printf("%s:%d: ad_read: %d\n", __FILE__, __LINE__, t);	\
 +	ADWRITE(sc, AD1848_IADDR, ((reg) & 0xff) | (sc)->MCE_bit);	\
 +	ADREAD(sc, AD1848_IDATA); })

  __inline void
  ad_write(sc, reg, data)
 @@ -249,10 +260,23 @@
  	int reg;
  	int data;
  {
 +	int t = 0;
 +
 +	for ( ; t < 10000 && ADREAD(sc, AD1848_IADDR) & SP_IN_INIT; t++)
 +		delay(10);
 +	if (t) printf("ad_write: %d (unknown location)\n", t);
  	ADWRITE(sc, AD1848_IADDR, (reg & 0xff) | sc->MCE_bit);
  	ADWRITE(sc, AD1848_IDATA, data & 0xff);
  	/* printf("(%02x->%02x) ", reg|sc->MCE_bit, data); */
  }
 +#define ad_write(sc, reg, data) do {					\
 +	int t = 0;							\
 +	for ( ; t < 10000 && ADREAD(sc, AD1848_IADDR) & SP_IN_INIT; t++)\
 +		delay(10);						\
 +	if (t) printf("%s:%d: ad_write: %d\n", __FILE__, __LINE__, t);	\
 +	ADWRITE(sc, AD1848_IADDR, ((reg) & 0xff) | (sc)->MCE_bit);	\
 +	ADWRITE(sc, AD1848_IDATA, (data) & 0xff);			\
 +} while (0)

  /*
   * extended registers (mode 3) require an additional level of

From: collver@linuxfreemail.com
To: ITOH Yasufumi <itohy@netbsd.org>
Cc: netbsd-bugs@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/14819: changing ym /dev/audio encoding is unreliable
Date: Fri, 22 Mar 2002 08:22:45 -0800

 Thanks a lot!

 I applied your patch and ran ym-test.c
 Everything sounds fine now.
 Do you have documentation for this chipset?

 Below are the console messages from several runs of ym-test.c

 first time:
 ../../../../dev/ic/ad1848.c:1142: ad_write: 4
 ../../../../dev/ic/ad1848.c:1142: ad_write: 2

 second time:
 ../../../../dev/ic/ad1848.c:1142: ad_write: 1
 ../../../../dev/ic/ad1848.c:1142: ad_write: 4
 ../../../../dev/ic/ad1848.c:1142: ad_write: 4

 third time:
 ../../../../dev/ic/ad1848.c:1142: ad_write: 1
 ../../../../dev/ic/ad1848.c:1142: ad_write: 4
 ../../../../dev/ic/ad1848.c:1142: ad_write: 2

 forth time:
 ../../../../dev/ic/ad1848.c:1142: ad_write: 1
 ../../../../dev/ic/ad1848.c:1142: ad_write: 4

 fifth time:
 ../../../../dev/ic/ad1848.c:1142: ad_write: 1
 ../../../../dev/ic/ad1848.c:1142: ad_write: 3

 Ben

 On Fri, Mar 22, 2002 at 11:44:12PM +0900, ITOH Yasufumi wrote:
 >   Hello,
 > 
 > Will you try again with following change?
 > This checks unexpected busy state of the device and print diagnosis.
 > 
 > Regards,
 > -- 
 > ITOH Yasufumi

From: itohy@netbsd.org (ITOH Yasufumi)
To: collver@linuxfreemail.com, gnats-bugs@gnats.netbsd.org
Cc: itohy@netbsd.org
Subject: Re: kern/14819: changing ym /dev/audio encoding is unreliable
Date: Sat, 23 Mar 2002 19:49:01 +0900 (JST)

 In article <20020322082243.A253@glen.takilma.net>
 collver@linuxfreemail.com writes:

 > I applied your patch and ran ym-test.c
 > Everything sounds fine now.
 > Below are the console messages from several runs of ym-test.c
 > first time:
 > ../../../../dev/ic/ad1848.c:1142: ad_write: 4
 > ../../../../dev/ic/ad1848.c:1142: ad_write: 2
 	:

 Good.  It is the
 	ad_write(sc, SP_CLOCK_DATA_FORMAT, fs);
 line in ad1848_commit_settings().
 (For audience: I personally contacted to Ben to identify the place
 in the source.)

 Please back out all the changes before and apply following patch,
 and test if it works.  I think this should work.

 P.S.
 > Do you have documentation for this chipset?

 ftp://ftp.alsa-project.org/pub/manuals/yamaha/YMF711.PDF	YMF711
 http://www.yamaha.com/lsi/products/pdf/4MF715E20.pdf		YMF715E
 ftp://ftp.alsa-project.org/pub/manuals/yamaha/sax-rege.pdf	FM, WSS, etc.
 http://www.cirrus.com/pubs/4231a.pdf	CS4231A (original WSS CODEC)

 Index: ad1848.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/ic/ad1848.c,v
 retrieving revision 1.13
 diff -u -5 -r1.13 ad1848.c
 --- ad1848.c	2002/03/06 07:12:02	1.13
 +++ ad1848.c	2002/03/23 09:38:27
 @@ -1138,10 +1138,17 @@
  	fs = sc->speed_bits | (sc->format_bits << 5);

  	if (sc->channels == 2)
  		fs |= FMT_STEREO;

 +	/*
 +	 * OPL3-SA2 (YMF711) is sometimes busy here.  Wait til it becomes ready.
 +	 */
 +	for (timeout = 0;
 +	    timeout < 1000 && ADREAD(sc, AD1848_IADDR) & SP_IN_INIT; timeout++)
 +		delay(10);
 +
  	ad_write(sc, SP_CLOCK_DATA_FORMAT, fs);

  	/*
  	 * If mode >= 2 (CS4231), set I28 also.
  	 * It's the capture format register.

From: collver@linuxfreemail.com
To: ITOH Yasufumi <itohy@netbsd.org>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/14819: changing ym /dev/audio encoding is unreliable
Date: Sat, 23 Mar 2002 06:59:05 -0800

 I backed out the prior changes and tested your patch.
 It works fine.

 Thank you for fixing this,

 Ben

 > Good.  It is the
 > 	ad_write(sc, SP_CLOCK_DATA_FORMAT, fs);
 > line in ad1848_commit_settings().
 > (For audience: I personally contacted to Ben to identify the place
 > in the source.)
 > 
 > Please back out all the changes before and apply following patch,
 > and test if it works.  I think this should work.
State-Changed-From-To: open->closed 
State-Changed-By: itohy 
State-Changed-When: Wed Mar 27 05:58:16 PST 2002 
State-Changed-Why:  
Fix in the following delta: 

-current:	sys/dev/ic/ad1848.c:1.14 
netbsd-1-5:	sys/dev/ic/ad1848.c:1.9.6.1 

Thanks. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.