Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Apr 2001 15:20:12 +0800 (CST)
From:      huangant@cis.nctu.edu.tw
To:        FreeBSD-gnats-submit@freebsd.org
Cc:        huangant@cis.nctu.edu.tw
Subject:   kern/26563: [patch] fix of ioctl(SNDCTL_DSP_SPEED) return value
Message-ID:  <200104140720.f3E7KCb04683@Evilant.dorm7.nctu.edu.tw>

next in thread | raw e-mail | index | archive | help

>Number:         26563
>Category:       kern
>Synopsis:       ioctl(SNDCTL_DSP_SPEED) returns -1 when fall back to orignal sample rate
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 14 00:30:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Chun-Ying Huang
>Release:        FreeBSD 4.3-BETA2 i386
>Organization:
NCTU Dept. of Computer Information Science, Taiwan
>Environment:
System: FreeBSD Evilant.dorm7.nctu.edu.tw 4.3-BETA2 FreeBSD 4.3-BETA2 #6: Fri Apr 13 12:04:14 CST 2001 huangant@Evilant.dorm7.nctu.edu.tw:/usr/src/sys/compile/EVILANT i386


>Description:

	When I am trying to set output sample rate that my sound card
	not support (my sound card is fixed at 48khz), the
	ioctl(SNDCTL_DSP_SPEED) return -1 and the value passed into 
	ioctl() keep unchanged.
	
	According to OSS programming guide, the ioctl() should ONLY
	return -1 when critical/serious fault happens. When fails on
	setting sample rates, it should return 0 (no error) and
	change the value passed into ioctl() to the sample rate
	previous used.
	
	This problem will happen on some fixed sample rate sound chips,
	for example, VIA 82C686 AC'97 Codec, and cause some media player
	(such as 'xmms') caused an incorrect sound output.

	This problem exists in 4.3-BETA2, RC, and 20010412-CURRENT.
	
>How-To-Repeat:

	Run following piece of the code:
=== cut here ===
#include <stdio.h>
#include <fcntl.h>
#include <sys/soundcard.h>

int main() {
	int fd, freq;
	
	if((fd = open("/dev/dsp", O_WRONLY))==-1) {
		printf("open %s failed.\n", "/dev/dsp");
		return(-1);
	}

	freq = 44100;
	printf("trying setting 44100hz...");
	if(ioctl(fd, SNDCTL_DSP_SPEED, &freq)==-1)
		freq = -1;
	printf("[%d]\n", freq);

	close(fd);
	return(0);
}
=== cut here ===

	When setting 44.1khz as sample rate, ioctl() will return -1 and
	keep freq==44100 on my VIA82C686 AC'97 Codec.

	Before applying any patches, result of this code shows:
	
	trying setting 44100hz...[-1]

>Fix:

	Here is a very sample patch to solve this problem.
	The patch is just return correct value when sample rate
	falling back to previous rate caused by setting unsupported
	sample rate.

	PS. This patch is generate based on 4.3-BETA2, but it has
	been tested on 4.3-RC(OK) and
	20010412-CURRENT(with some offset).

=== cut here ===
--- sys/dev/sound/pcm/channel.c.old	Fri Apr 13 11:55:53 2001
+++ sys/dev/sound/pcm/channel.c	Fri Apr 13 11:56:14 2001
@@ -1178,7 +1178,7 @@
 	r = chn_tryspeed(c, speed);
 	if (r) {
 		DEB(printf("Failed to set speed %d falling back to %d\n", speed, oldspeed));
-		chn_tryspeed(c, oldspeed);
+		r = chn_tryspeed(c, oldspeed);
 	}
 	return r;
 }
=== cut here ===

	After applying this patch, result of above test code shows:
	
	trying setting 44100hz...[48000]
	
	on my VIA 82C686 AC'97 Codec.:)

>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200104140720.f3E7KCb04683>