From brandt@fokus.gmd.de  Tue May  7 07:23:22 2002
Return-Path: <brandt@fokus.gmd.de>
Received: from mailhub.fokus.gmd.de (mailhub.fokus.gmd.de [193.174.154.14])
	by hub.freebsd.org (Postfix) with ESMTP id 024E537B405
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  7 May 2002 07:23:01 -0700 (PDT)
Received: from beagle.fokus.gmd.de (beagle [193.175.132.100])
	by mailhub.fokus.gmd.de (8.11.6/8.11.6) with ESMTP id g47EMo413900
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 7 May 2002 16:22:56 +0200 (MEST)
Received: from beagle.fokus.gmd.de (localhost [127.0.0.1])
	by beagle.fokus.gmd.de (8.12.3/8.12.3) with ESMTP id g47EMn7H036183
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 7 May 2002 16:22:50 +0200 (CEST)
	(envelope-from hbb@beagle.fokus.gmd.de)
Received: (from root@localhost)
	by beagle.fokus.gmd.de (8.12.3/8.12.3/Submit) id g47Dkq8X031220;
	Tue, 7 May 2002 15:46:52 +0200 (CEST)
Message-Id: <200205071346.g47Dkq8X031220@beagle.fokus.gmd.de>
Date: Tue, 7 May 2002 15:46:52 +0200 (CEST)
From: brandt@fokus.gmd.de
Reply-To: brandt@fokus.gmd.de
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Half of buffer gets filled with silence when recording
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         37831
>Category:       kern
>Synopsis:       Half of buffer gets filled with silence when recording
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    sound
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 07 07:30:01 PDT 2002
>Closed-Date:    Mon Feb 03 07:04:25 PST 2003
>Last-Modified:  Mon Feb 03 07:04:25 PST 2003
>Originator:     Hartmut Brandt
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
FhI Fokus
>Environment:
System: FreeBSD beagle.fokus.gmd.de 5.0-CURRENT FreeBSD 5.0-CURRENT #38: Tue May 7 11:25:29 CEST 2002 hbb@beagle.fokus.gmd.de:/opt/obj/usr/src/sys/BEAGLE i386


	
>Description:

When recording from a soundcard that supports only 16 bit formats (Emu10k in
this case) with an 8-bit format, half of the buffer gets filled with silence.

This is caused by the feeder mechanism interpreting the count parameter
as the number of bytes to fill in the destination buffer. In the record
case this parameter is the number of bytes that came from the soundcard.
If we are converting from a 16 bit to an 8 bit format, the 16to8 feeder
is called with the number of bytes in the input buffer. It requests from
the root feeder twice that number and the root feeder finding only half
that number of bytes, fills the other half with silence.

	
>How-To-Repeat:

Try to record from a emu10k with AFMT_U8. Observe the output to contain
1kbyte of audio data, 1kbyte of 0200 bytes, 1kbyte of audio data, ...

	
>Fix:

Apply the following patch to /sys/dev/sound/feeder.c. This causes to check
the root feeder, whether the current channel is a recording channel. If it
is not, don't append silence if the buffer contains lesser bytes than requested.

Index: feeder.c
===================================================================
RCS file: /usr/ncvs/src/sys/dev/sound/pcm/feeder.c,v
retrieving revision 1.21
diff -u -r1.21 feeder.c
--- feeder.c	26 Jan 2002 22:13:24 -0000	1.21
+++ feeder.c	7 May 2002 13:35:50 -0000
@@ -393,11 +393,13 @@
 		printf("appending %d bytes\n", count - l);
 */
 
-	x = (sndbuf_getfmt(src) & AFMT_SIGNED)? 0 : 0x80;
-	while (l < count)
-		buffer[l++] = x;
-
-	return count;
+	if (ch->direction != PCMDIR_REC) {
+		x = (sndbuf_getfmt(src) & AFMT_SIGNED)? 0 : 0x80;
+		while (l < count)
+			buffer[l++] = x;
+		return count;
+	} else
+		return (l);
 }
 
 static kobj_method_t feeder_root_methods[] = {
	

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->sound 
Responsible-Changed-By: dwmalone 
Responsible-Changed-When: Thu Jun 27 09:54:33 PDT 2002 
Responsible-Changed-Why:  
Assign this to the sound guys. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=37831 
State-Changed-From-To: open->closed 
State-Changed-By: orion 
State-Changed-When: Mon Feb 3 07:03:04 PST 2003 
State-Changed-Why:  
Equivalent patch applied to -CURRENT. 
Thanks! 


http://www.freebsd.org/cgi/query-pr.cgi?pr=37831 
>Unformatted:
