From alsa-devel-owner@alsa.jcu.cz  Sat Apr 18 19:23:11 1998
Received: from sandy.force9.co.uk (root@53.usr02.wor.dialup.force9.net [195.166.131.117] (may be forged))
	by marvin.jcu.cz (8.8.8/8.8.8) with ESMTP id TAA01421
	for <alsa-devel@alsa.jcu.cz>; Sat, 18 Apr 1998 19:23:03 +0200
Received: (from chrisb@localhost)
	by sandy.force9.co.uk (8.8.5/8.8.5) id QAA03506
	for alsa-devel@alsa.jcu.cz; Sat, 18 Apr 1998 16:18:20 GMT
From: Christopher Butler <chrisb@sandy.force9.co.uk>
Message-Id: <199804181618.QAA03506@sandy.force9.co.uk>
Subject: Close but no cigar :)
To: alsa-devel@alsa.jcu.cz
Date: Sat, 18 Apr 1998 16:18:20 +0000 (UTC)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list

Hi!

Sorry about that previous patch. It /did/ indeed fix some bugs, but
there was still one there. This one mainly effected all those programs
that check the playback status to find out what the playback rate has
been adjusted to by the driver. 

--
Chris Butler <chrisb@sandy.force9.co.uk>

***
diff -urN alsadriver-0.0.11.orig/CHANGELOG alsadriver/CHANGELOG
--- alsadriver-0.0.11.orig/CHANGELOG	Fri Apr 17 20:04:07 1998
+++ alsadriver/CHANGELOG	Fri Apr 17 20:12:54 1998
@@ -2,9 +2,11 @@
 
 * native PCM
   - fixed time computing for playback
+  - set number of voices before computing rate, instead of afterwards
 * PCM OSS emulation
   - quake works now ok again - fixed error from 0.0.11
   - fixed error with large buffers - (affected Doom etc...)
+* stereo rate calculation fixed for SB Pro
 
 0.0.10 -> 0.0.11
 
diff -urN alsadriver-0.0.11.orig/Makefile alsadriver/Makefile
--- alsadriver-0.0.11.orig/Makefile	Mon Apr 13 09:26:54 1998
+++ alsadriver/Makefile	Fri Apr 17 19:58:50 1998
@@ -45,9 +45,11 @@
 	rm -f modules/*.o
 	rm -f doc/*~
 
-pack: clean
+distclean:
 	rm -f config.cache config.log config.status Makefile.conf
 	rm -f utils/alsadriver.spec
+
+pack: distclean
 	chown -R root.root ../alsadriver
 	tar cvz -C .. -f ../alsadriver-$(SND_VERSION).tar.gz alsadriver
 
diff -urN alsadriver-0.0.11.orig/kernel/pcm.c alsadriver/kernel/pcm.c
--- alsadriver-0.0.11.orig/kernel/pcm.c	Fri Apr 17 20:04:07 1998
+++ alsadriver/kernel/pcm.c	Fri Apr 17 20:08:58 1998
@@ -984,8 +984,8 @@
       err = -EINVAL;
   }
   pchn -> rate = format.rate;
-  pchn -> hw.compute_rate( pcm );
   pchn -> voices = format.channels;
+  pchn -> hw.compute_rate( pcm );
   pchn -> flags |= SND_PCM_FLG_BUFFERS;
   pchn -> neutral_byte = pchn -> mode & SND_PCM_MODE_16 ? 0x00 : 0x80;
   return err;
diff -urN alsadriver-0.0.11.orig/lowlevel/sb/sb8.c alsadriver/lowlevel/sb/sb8.c
--- alsadriver-0.0.11.orig/lowlevel/sb/sb8.c	Fri Apr 10 13:38:07 1998
+++ alsadriver/lowlevel/sb/sb8.c	Sat Apr 18 15:43:16 1998
@@ -69,15 +69,19 @@
       if ( direction == SND_PCM_RECORD ) {
         if ( rate > 15000 ) rate = 15000;
       }
-      if ( pchn -> voices > 2 ) {
-        rate = rate > (22050 + 11025) / 2 ? 22050 : 11025;
-        codec -> speed8 = (65536 - (256000000 + rate / 2) / rate) >> 8;
+      if ( pchn -> voices > 1 ) {
+/* This doesn't look right to me - Chris Butler */
+/*      rate = rate > (22050 + 11025) / 2 ? 22050 : 11025; */
+ 	if (rate < 4000) rate = 4000;
+ 	if (rate > 22050) rate = 22050;
+        codec -> speed8 = (65536 - (256000000 + rate) / (rate * 2)) >> 8;
         if ( direction == SND_PCM_PLAYBACK ) {
           codec -> fmt8 = SB_DSP_HI_OUTPUT_AUTO;
         } else {
           codec -> fmt8 = SB_DSP_HI_INPUT_AUTO;
         }
-        break;
+/* 	Should this break be here? - Chris Butler */
+	/*      break; */
       } else {
         if ( rate < 4000 ) rate = 4000;
         if ( rate > 44100 ) rate = 44100;
@@ -88,7 +92,9 @@
           codec -> fmt8 = rate > 23000 ? SB_DSP_HI_INPUT_AUTO : SB_DSP_LO_INPUT_AUTO;
         }
       }
-      pchn -> real_rate = 256000000 / (65536 - (codec -> speed8 << 8));
+      pchn -> real_rate = 256000000 / (65536 - (codec->speed8 << 8)) / pchn->voices;
+      snd_printd( "snd_sb8_compute_rate: rate = %u, pchn->real_rate = %u\n",
+		  rate, pchn->real_rate);
       break;
     default:
       snd_printd( "unknown hardware for sb8 compute rate!!!\n" );


