Oddity in snd_uaudio(4) driver?
Ed Schouten
ed at fxq.nl
Thu Sep 7 04:38:26 PDT 2006
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 >= UA_SAMP_LO(asf1d) && speed <= UA_SAMP_HI(asf1d)) {
| ch->sample_rate = speed;
| return speed;
| } else if (speed < UA_SAMP_LO(asf1d)) {
| score = 0xfff * speed / UA_SAMP_LO(asf1d);
| if (score > hiscore) {
| bestspeed = UA_SAMP_LO(asf1d);
| hiscore = score;
| }
| } else if (speed < UA_SAMP_HI(asf1d)) {
| score = 0xfff * UA_SAMP_HI(asf1d) / speed;
| if (score > hiscore) {
| bestspeed = UA_SAMP_HI(asf1d);
| hiscore = 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 >= 10 && x <= 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,
--
Ed Schouten <ed at fxq.nl>
WWW: http://g-rave.nl/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20060907/7cffdbcf/attachment.pgp
More information about the freebsd-hackers
mailing list