From nobody@FreeBSD.ORG  Wed Nov 15 11:15:33 2000
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 9C07D37B4CF; Wed, 15 Nov 2000 11:15:33 -0800 (PST)
Message-Id: <20001115191533.9C07D37B4CF@hub.freebsd.org>
Date: Wed, 15 Nov 2000 11:15:33 -0800 (PST)
From: larse@isi.edu
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@FreeBSD.org
Subject: newpcm CS461x sound problems
X-Send-Pr-Version: www-1.0

>Number:         22874
>Category:       kern
>Synopsis:       newpcm CS461x sound problems
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    greid
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 15 11:20:01 PST 2000
>Closed-Date:    Thu Jul 19 14:59:33 PDT 2001
>Last-Modified:  Thu Jul 19 15:00:06 PDT 2001
>Originator:     Lars Eggert
>Release:        4.2-BETA
>Organization:
USC Information Sciences Institute
>Environment:
FreeBSD hbo.isi.edu 4.2-BETA FreeBSD 4.2-BETA #0: Mon Nov 13 09:07:45 PST 2000     root@:/usr/obj/usr/src/sys/IDPRIO  i386

>Description:
Every once in a few hours of audio playback, newpcm will choke and sound
output will be scratchy/hissing from then on until I reboot the machine. Sounds
kinda like when you had dust collected on the needle of your record player
back when we were still using them.

I've not been able to reproduce this consistently (i.e. it chokes at a
certain time in one sound file, after a reboot that same file will play
fine.)

Here's my info:

[larse@hbo: ~] cat /dev/sndstat 
FreeBSD Audio Driver (newpcm) Nov 10 2000 12:59:49
Installed devices:
pcm0: <CS461x PCM Audio> at irq 5 (1p/1r channels duplex)

[larse@hbo: ~] uname -a
FreeBSD hbo.isi.edu 4.2-BETA FreeBSD 4.2-BETA #68: Fri Nov 10
13:00:17 PST 2000     larse@hbo.isi.edu:/usr/src-idprio/sys/compile/IDPRIO 
i386

Sorry I can't be more specific; if I had to guess I'd say some internal
newpcm struct gets bashed by a rare pointer error...


>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: oh <oh@btinternet.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: kern/22874: newpcm CS461x sound problems
Date: Sun, 19 Nov 2000 11:45:56 +0000

 This is a multi-part message in MIME format.
 --------------A6AB57816D389CF3F9D7AC4B
 Content-Type: text/plain; charset=us-ascii
 Content-Transfer-Encoding: 7bit
 
 This driver also fails to work in full duplex mode, blocking or
 non-blocking, on Lars' machine.  Lars reported that rat did not work
 with this driver and so we've conducted a few experiments (rat problems
 mostly caused card by not supporting 8kHz sampling and newpcm accepting
 and reporting this as an acceptable rate, rat driver interface fixed and
 patch submitted to check rate bounds in dsp.c).  
 
 The attached test program results in read buffer overruns, causing dump
 messages on syslog, at the lowest supported sampling rate (11025kHz). 
 Lars observes:
 
 > [larse@hbo: ~] ./a.out -r 11025
 > Device Caps:
 >        Sample rates: 11025 -- 48000 Hz
 >        Formats: 0x90000010
 >        DMA buffer size: 65536 bytes
 >        Mixers: 0x00000001 Inputs: 0x017049f1
 >         Levels: 100 (left), 100 (right)
 > Set play rate 11025 fmt 16
 > Set record rate 11025 fmt 16
 > Got play rate 11025 fmt 16
 > Got record rate 11025 fmt 16
 > Block size requested 1024, play 1024, rec 1024
 > Output buffer status: frags 2 frags total 2 fragsize 1024 bytes 2048
 > Input buffer status: frags 0 frags total 2 fragsize 1024 bytes 0
 > |^C
 >
 > Saw this in syslog during that run:
 > Nov 17 10:14:10 hbo /kernel: pcm0: record overrun, dumping 22528 bytes
 > Nov 17 10:14:26 hbo last message repeated 16 times
 
 Kind Regards
 - Orion
 --------------A6AB57816D389CF3F9D7AC4B
 Content-Type: text/plain; charset=us-ascii;
  name="full-duplex-blocking-audio-test3.c"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline;
  filename="full-duplex-blocking-audio-test3.c"
 
 #include <sys/soundcard.h>
 #include <sys/ioctl.h>
 
 #include <fcntl.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include <sysexits.h>
 #include <unistd.h>
 
 #define SAMPLE_BLKSZ 1024
 
 #define AUDIO_IOCTL(fd, cmd, val) \
 	if (ioctl((fd), (cmd), (val)) < 0) { \
 		fprintf(stderr, "Failed %s - line %d\n",#cmd, __LINE__); \
 		exit(EX_UNAVAILABLE); \
 	}
 
 
 static void progress() {
     const char sym[]="-\\|/";
     static int n;
 
     int m = n % (sizeof(sym) - 1);
 
     if (n == 0) {
 	printf(" ");
     }
     printf("%c%c", '\b', sym[m]);
     fflush(stdout);
 
     n++;
 }
 
 int main(int argc, char *argv[])
 {
     char    *thedev = "/dev/audio";
     uint16_t buf[SAMPLE_BLKSZ];
     int      c, fd, rlen, wlen, rate = 8000;
     
     while((c = getopt(argc, argv, "f:r:")) != -1) {
 	switch(c) {
 	case 'f':
 	    thedev = optarg;
 	    break;
 	case 'r':
 	    rate = atoi(optarg);
 	    break;
 	default:
 	    fprintf(stderr, 
 		    "%s -f flag specifies audio device to test.\n", 
 		    argv[0]);
 	    exit(EX_USAGE);
 	}
     }
 	  
     fd = open(thedev, O_RDWR);
     if (fd > 0) {
 	snd_chan_param   pa;
 	struct snd_size  sz;     
 	audio_buf_info   abi;
 	snd_capabilities sc;
 	int fragsz;
 
 	AUDIO_IOCTL(fd, AIOGCAP, &sc);
 	printf("Device Caps:\n\tSample rates: %d -- %d Hz\n", 
 	       sc.rate_min, sc.rate_max);
 	printf("\tFormats: 0x%08x\n\tDMA buffer size: %d bytes\n", 
 	       sc.formats, sc.bufsize);
 	printf("\tMixers: 0x%08x Inputs: 0x%08x\n", sc.mixers, sc.inputs);
 	printf("\tLevels: %d (left), %d (right)\n", sc.left, sc.right);
 
 	pa.play_rate   = rate;
 	pa.play_format = AFMT_S16_LE;
 	pa.rec_rate    = rate;
 	pa.rec_format  = AFMT_S16_LE;
 	AUDIO_IOCTL(fd, AIOSFMT, &pa);
 	fprintf(stdout, "Set play rate %d fmt %d\n", pa.play_rate, pa.play_format);
 	fprintf(stdout, "Set record rate %d fmt %d\n", pa.rec_rate, pa.rec_format);
 	AUDIO_IOCTL(fd, AIOGFMT, &pa);
 	fprintf(stdout, "Got play rate %d fmt %d\n", pa.play_rate, pa.play_format);
 	fprintf(stdout, "Got record rate %d fmt %d\n", pa.rec_rate, pa.rec_format);
 
 
 	/* Put device in block mode and set block size */
 	sz.play_size = SAMPLE_BLKSZ;
 	sz.rec_size  = SAMPLE_BLKSZ;
 	/*	AUDIO_IOCTL(fd, AIOSSIZE, &sz); */
 	AUDIO_IOCTL(fd, AIOGSIZE, &sz);
 
 	fprintf(stdout, "Block size requested %d, play %d, rec %d\n", 
 		SAMPLE_BLKSZ, sz.play_size, sz.rec_size);
 
 	/* Set large number of fragment */
 	fragsz = SAMPLE_BLKSZ;
 	AUDIO_IOCTL(fd, SNDCTL_DSP_SETFRAGMENT, &fragsz);
 
 	AUDIO_IOCTL(fd, SNDCTL_DSP_GETOSPACE, &abi);
 	fprintf(stdout, 
 		"Output buffer status: frags %d frags total %d fragsize %d bytes %d\n",
 		abi.fragments, abi.fragstotal, abi.fragsize, abi.bytes);
 
 
 	AUDIO_IOCTL(fd, SNDCTL_DSP_GETISPACE, &abi);
 	fprintf(stdout, 
 		"Input buffer status: frags %d frags total %d fragsize %d bytes %d\n",
 		abi.fragments, abi.fragstotal, abi.fragsize, abi.bytes);
 		
 
 	memset(buf, 0, sizeof(buf) / sizeof(buf[0]));
 	while((rlen = read(fd, buf, sizeof(buf))) > 0) {
 	  fprintf(stderr, "Read %d\n", rlen);
 	    progress();
 	    wlen = write(fd, buf, rlen);
 	    if (wlen != rlen) {
 		fprintf(stderr, "write failed %d != %d\n", wlen, rlen);
 		exit(EX_IOERR);
 	    }
 	}
      } else {
 	fprintf(stderr, "Could not open %s O_RDWR\n", thedev);
 	exit(EX_OSFILE);
     }
     return 0;
 }
 
 --------------A6AB57816D389CF3F9D7AC4B--
 
 
Responsible-Changed-From-To: freebsd-bugs->cg 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Sun Nov 19 09:49:04 PST 2000 
Responsible-Changed-Why:  

Cameron is responsible for pcm. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=22874 
State-Changed-From-To: open->feedback 
State-Changed-By: greid 
State-Changed-When: Thu Jul 12 18:23:33 PDT 2001 
State-Changed-Why:  
Is this still a problem with more recent sources? 


Responsible-Changed-From-To: cg->greid 
Responsible-Changed-By: greid 
Responsible-Changed-When: Thu Jul 12 18:23:33 PDT 2001 
Responsible-Changed-Why:  
I'll handle feedback. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=22874 
State-Changed-From-To: feedback->closed 
State-Changed-By: greid 
State-Changed-When: Thu Jul 19 14:59:33 PDT 2001 
State-Changed-Why:  
Originator reports problem is no longer present in >= 4.2 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=22874 
>Unformatted:
