Skip to content

Commit

Permalink
ALSA: fix incorrect rounding direction in snd_interval_ratnum()
Browse files Browse the repository at this point in the history
The direction of rounding is incorrect in the snd_interval_ratnum()
It was detected with following parameters (sb8 driver playing
8kHz stereo file):
 - num is always 1000000
 - requested frequency rate is from 7999 to 7999 (single frequency)

The first loop calculates div_down(num, freq->min) which is 125.
Thus, a frequency range's minimum value is 1000000 / 125 = 8000 Hz.
The second loop calculates div_up(num, freq->max) which is 126
The frequency range's maximum value is 1000000 / 126 = 7936 Hz.
The range maximum is lower than the range minimum so the function
fails due to empty result range.

Signed-off-by: Krzysztof Helt <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
Krzysztof-H authored and tiwai committed Dec 21, 2009
1 parent ef86f58 commit 40962d7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sound/core/pcm_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ int snd_interval_ratnum(struct snd_interval *i,
int diff;
if (q == 0)
q = 1;
den = div_down(num, q);
den = div_up(num, q);
if (den < rats[k].den_min)
continue;
if (den > rats[k].den_max)
Expand Down Expand Up @@ -794,7 +794,7 @@ int snd_interval_ratnum(struct snd_interval *i,
i->empty = 1;
return -EINVAL;
}
den = div_up(num, q);
den = div_down(num, q);
if (den > rats[k].den_max)
continue;
if (den < rats[k].den_min)
Expand Down

0 comments on commit 40962d7

Please sign in to comment.