From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 7 11:38:25 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 DF4A216A4DA for ; Thu, 7 Sep 2006 11:38:25 +0000 (UTC) (envelope-from ed@hoeg.nl) Received: from palm.hoeg.nl (palm.hoeg.nl [83.98.131.212]) by mx1.FreeBSD.org (Postfix) with ESMTP id A688E43D6D for ; Thu, 7 Sep 2006 11:38:21 +0000 (GMT) (envelope-from ed@hoeg.nl) Received: by palm.hoeg.nl (Postfix, from userid 1000) id 56FB51CCBD; Thu, 7 Sep 2006 13:38:20 +0200 (CEST) Date: Thu, 7 Sep 2006 13:38:20 +0200 From: Ed Schouten To: FreeBSD Hackers Message-ID: <20060907113820.GO22564@hoeg.nl> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7gLe/sNPhR777EPF" Content-Disposition: inline User-Agent: Mutt/1.5.12-2006-07-14 X-Mailman-Approved-At: Thu, 07 Sep 2006 12:07:42 +0000 Subject: Oddity in snd_uaudio(4) driver? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: FreeBSD Hackers 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 11:38:26 -0000 --7gLe/sNPhR777EPF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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: | if (speed >=3D UA_SAMP_LO(asf1d) && speed <=3D UA_SAMP_HI(asf1d)) { | ch->sample_rate =3D speed; | return speed; | } else if (speed < UA_SAMP_LO(asf1d)) { | score =3D 0xfff * speed / UA_SAMP_LO(asf1d); | if (score > hiscore) { | bestspeed =3D UA_SAMP_LO(asf1d); | hiscore =3D score; | } | } else if (speed < UA_SAMP_HI(asf1d)) { | score =3D 0xfff * UA_SAMP_HI(asf1d) / speed; | if (score > hiscore) { | bestspeed =3D UA_SAMP_HI(asf1d); | hiscore =3D score; | } | } 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: | if (x >=3D 10 && x <=3D 20) { | ... | } else if (x < 10) { | ... | } else if (x < 20) { | ... | } 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 {'? Yours, --=20 Ed Schouten WWW: http://g-rave.nl/ --7gLe/sNPhR777EPF Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQFFAASs52SDGA2eCwURAuqWAJ0c4LQ1uNXvwUexH+jjFiuw3dzRQQCfQKrj 66ga7m+cWqe6sWW0rl9jyes= =Cgl7 -----END PGP SIGNATURE----- --7gLe/sNPhR777EPF--