From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 7 12:30:37 2006 Return-Path: X-Original-To: freebsd-hackers@FreeBSD.org Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6527016A4E0; Thu, 7 Sep 2006 12:30:37 +0000 (UTC) (envelope-from Alexander@Leidinger.net) Received: from www.ebusiness-leidinger.de (jojo.ms-net.de [84.16.236.246]) by mx1.FreeBSD.org (Postfix) with ESMTP id 56BDB43E29; Thu, 7 Sep 2006 12:27:59 +0000 (GMT) (envelope-from Alexander@Leidinger.net) Received: from Andro-Beta.Leidinger.net (p54A5D914.dip.t-dialin.net [84.165.217.20]) (authenticated bits=0) by www.ebusiness-leidinger.de (8.13.6/8.13.6) with ESMTP id k87C6voj025162; Thu, 7 Sep 2006 14:06:57 +0200 (CEST) (envelope-from Alexander@Leidinger.net) Received: from localhost (webmail.Leidinger.net [192.168.1.102]) by Andro-Beta.Leidinger.net (8.13.4/8.13.3) with ESMTP id k87CRiNq032533; Thu, 7 Sep 2006 14:27:44 +0200 (CEST) (envelope-from Alexander@Leidinger.net) Received: from psbru.cec.eu.int (psbru.cec.eu.int [158.169.131.14]) by webmail.leidinger.net (Horde MIME library) with HTTP; Thu, 07 Sep 2006 14:27:44 +0200 Message-ID: <20060907142744.aazrsemxkwcok40w@webmail.leidinger.net> X-Priority: 3 (Normal) Date: Thu, 07 Sep 2006 14:27:44 +0200 From: Alexander Leidinger To: FreeBSD Hackers , Ed Schouten References: <20060907113820.GO22564@hoeg.nl> In-Reply-To: <20060907113820.GO22564@hoeg.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable User-Agent: Internet Messaging Program (IMP) H3 (4.1.3) / FreeBSD-7.0 X-Virus-Scanned: by amavisd-new X-Mailman-Approved-At: Thu, 07 Sep 2006 13:22:23 +0000 Cc: multimedia@FreeBSD.org Subject: Re: Oddity in snd_uaudio(4) driver? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Sep 2006 12:30:37 -0000 Quoting Ed Schouten (from Thu, 7 Sep 2006 13:38:20 +0200): CCing multimedia@, where all "the cool sound guys hang out"... > Hello, > > I was just looking through FreeBSD's snd_uaudio(4) driver, because I'm > thinking of patching it to support Xbox 360 headsets as well. I was > looking at the code to set the sample rate in > /sys/dev/sound/usb/uaudio.c. In that file there is the following code > near line 4100: > > | =09if (speed >=3D UA_SAMP_LO(asf1d) && speed <=3D UA_SAMP_HI(asf1d)) { > | =09=09ch->sample_rate =3D speed; > | =09=09return speed; > | =09} else if (speed < UA_SAMP_LO(asf1d)) { > | =09=09score =3D 0xfff * speed / UA_SAMP_LO(asf1d); > | =09=09if (score > hiscore) { > | =09=09=09bestspeed =3D UA_SAMP_LO(asf1d); > | =09=09=09hiscore =3D score; > | =09=09} > | =09} else if (speed < UA_SAMP_HI(asf1d)) { > | =09=09score =3D 0xfff * UA_SAMP_HI(asf1d) / speed; > | =09=09if (score > hiscore) { > | =09=09=09bestspeed =3D UA_SAMP_HI(asf1d); > | =09=09=09hiscore =3D score; > | =09=09} > | =09} > > If we would rewrite this code to something more basic, let's say we > rename 'speed' to 'x' and the UA_SAMP_ macros to some predefined > variables: > > | =09if (x >=3D 10 && x <=3D 20) { > | =09=09... > | =09} else if (x < 10) { > | =09=09... > | =09} else if (x < 20) { > | =09=09... > | =09} > > Wouldn't that mean that the last portion of the code is never reached? > Looking at the code, it looks like some range check, making sure the > sample rate remains inside a certain range. Wouldn't it be enough to > remove the entire third if-statement, using a normal '} else {'? Just by looking at the code you pasted, I assume the last part is a =20 typo in the uaudio code and should be a '>' instead of a '<': "if it =20 is outside the range, use the end of the range as a good candidate." Bye, Alexander. --=20 The most delightful day after the one on which you buy a cottage in the country is the one on which you resell it. =09=09-- J. Brecheux http://www.Leidinger.net Alexander @ Leidinger.net: PGP ID =3D B0063FE7 http://www.FreeBSD.org netchild @ FreeBSD.org : PGP ID =3D 72077137