From xemacs-m  Wed Apr 16 06:30:27 1997
Received: from master.control.att.com ([135.205.52.13])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id GAA09289
	for <xemacs-beta@xemacs.org>; Wed, 16 Apr 1997 06:30:26 -0500 (CDT)
Received: from wander.control.att.com by master.control.att.com with esmtp
	(Smail3.1.29.1 #3) id m0wHSuU-002ix5C; Wed, 16 Apr 97 07:29 EDT
Received: by wander.control.att.com
	via sendmail with stdio
	id <m0wHSuT-000h9tC@wander.control.att.com>
	for xemacs-beta@xemacs.org; Wed, 16 Apr 1997 07:29:57 -0400 (EDT)
	(Smail-3.2 1996-Jul-4 #1 built 1996-Nov-1)
Message-Id: <m0wHSuT-000h9tC@wander.control.att.com>
Date: Wed, 16 Apr 1997 07:29:57 -0400 (EDT)
From: Larry Auton <lda@control.att.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: xemacs-beta@xemacs.org
Subject: Re: Native sound support for Linux 2.0.29
In-Reply-To: <m2wwq8tffg.fsf@altair.xemacs.org>
References: <m3hghfevuf.fsf_-_@cortex.corpus.uni-muenster.de>
	<19970412212534G.kasahara@nc.kyushu-u.ac.jp>
	<m0wG2Ea-000h9tC@wander.control.att.com>
	<m2wwq8tffg.fsf@altair.xemacs.org>
X-Mailer: VM 6.26 under 20.1 XEmacs Lucid

Larry Auton <lda@control.att.com> writes:
> 
> Taking the lead from Yoshiaki Kasahara <kasahara@nc.kyushu-u.ac.jp>,
> I tried this too:
> 
> 	M-x load-default-sounds
> 	hit ctrl-g
> 
> My host { Linux-2.0.29, OSS/Linux 3.7.1p, XEmacs-20.1b-14 } doesn't crash
> but I see this message flashed across the minibuffer:
> 
> 	audio: SNDCTL_DSP_SETFMT, Unknown error

I found the problem.  The ioctl() with AFMT_QUERY doesn't work.
I wrote a "demo" program and sent it to the author to verify my
conjecture.  Here's his reply:

Hannu Savolainen writes:
> There appears to be a buf [sic] in handling of AFMT_QUERY. Thanks
> for pointing it out.
> 
> Best regards,
> 
> Hannu
> ------
> Hannu Savolainen (hannu@voxware.pp.fi, hannu@4front-tech.com)
> http://www.4Front-Tech.com/oss.html (Open Sound System (OSS))
> http://personal.eunet.fi/pp/voxware (OSS Free/TASD/VoxWare)

Fortunately, the call to AFMT_QUERY is not required for correct
behavior.  I also noted that the initialization was being performed in
an order different than that specified in the OSS documentation.  The
documentation warns that order is important on some cards.  Here's a
patch to linuxplay.c:

--- ORGlinuxplay.c	Sat Apr 12 23:14:34 1997
+++ linuxplay.c	Wed Apr 16 06:28:57 1997
@@ -814,18 +814,15 @@
 
   /* Initialize sound hardware with prefered parameters */
   
-  /* The PCSP driver does not support reading of the sampling rate via the
-     SOUND_PCM_READ_RATE ioctl; determine "the_speed" here */     
-  the_speed = speed; ioctl(audio_fd,SNDCTL_DSP_SPEED,&the_speed);
-  /* The PCSP driver does not support reading of the mono/stereo flag, thus
-     we assume, that failure to change this mode means we are in mono mode  */
-  if (((i = (the_stereo = tracks)-1),ioctl(audio_fd,SNDCTL_DSP_STEREO,&i)) < 0)
-    the_stereo = 1;
-  the_fmt = fmt;     ioctl(audio_fd,SNDCTL_DSP_SETFMT,&the_fmt);
-
   /* If the sound hardware cannot support 16 bit format or requires a
      different byte sex then try to drop to 8 bit format */
-  the_fmt = AFMT_QUERY; ioctl(audio_fd,SNDCTL_DSP_SETFMT,&the_fmt);
+
+  the_fmt = fmt;
+  if(ioctl(audio_fd,SNDCTL_DSP_SETFMT,&the_fmt) < 0) {
+  	perror("SNDCTL_DSP_SETFMT");
+  	return(0);
+  }
+
   if (fmt != the_fmt) {
     if (fmt == AFMT_S16_LE || fmt == AFMT_S16_BE) {
       *sndcnv = fmt == AFMT_S16_BE ? sndcnv2byteBE : sndcnv2byteLE;
@@ -844,6 +841,14 @@
         fmt != the_fmt) {
       perror("SNDCTRL_DSP_SETFMT");
       return(0); } }
+
+  /* The PCSP driver does not support reading of the sampling rate via the
+     SOUND_PCM_READ_RATE ioctl; determine "the_speed" here */     
+  the_speed = speed; ioctl(audio_fd,SNDCTL_DSP_SPEED,&the_speed);
+  /* The PCSP driver does not support reading of the mono/stereo flag, thus
+     we assume, that failure to change this mode means we are in mono mode  */
+  if (((i = (the_stereo = tracks)-1),ioctl(audio_fd,SNDCTL_DSP_STEREO,&i)) < 0)
+    the_stereo = 1;
 
   /* Try to request stereo playback (if needed); if this cannot be supported
      by the hardware, then install conversion routines for mono playback */


