1
0
Fork 0
forked from len0rd/rockbox

Fix faulty clipping when dithering is enabled (thanks to Jens Arnold). This bug would only affect people using WMA. Also, add a small comment in an unrelated place.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15369 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thom Johansen 2007-10-29 23:58:00 +00:00
parent 781c82c0d6
commit daf937422c

View file

@ -236,14 +236,13 @@ static inline struct dsp_config * switch_dsp(struct dsp_config *_dsp)
/* Clip sample to arbitrary limits where range > 0 and min + range = max */ /* Clip sample to arbitrary limits where range > 0 and min + range = max */
static inline long clip_sample(int32_t sample, int32_t min, int32_t range) static inline long clip_sample(int32_t sample, int32_t min, int32_t range)
{ {
int32_t c = sample - min; if ((uint32_t)(sample - min) > (uint32_t)range)
if ((uint32_t)c > (uint32_t)range)
{ {
sample -= c; int32_t c = min;
if (c > 0) if (sample > min)
sample += range; c += range;
sample = c
} }
return sample; return sample;
} }
#endif #endif
@ -488,20 +487,12 @@ static void sample_output_dithered(int count, struct dsp_data *data,
dither->random = random; dither->random = random;
/* Clip */ /* Clip */
int32_t c = output - min; if ((uint32_t)(output - min) > (uint32_t)range)
if ((uint32_t)c > (uint32_t)range)
{ {
output -= c; int32_t c = min;
if (c > 0) if (output > min)
{ c += range;
output += range; output = c;
if (sample > max)
sample = max;
}
else if (sample < min)
{
sample = min;
}
} }
output &= ~mask; output &= ~mask;
@ -986,6 +977,9 @@ static void set_tone_controls(void)
} }
#endif #endif
/* Hook back from firmware/ part of audio, which can't/shouldn't call apps/
* code directly.
*/
int dsp_callback(int msg, intptr_t param) int dsp_callback(int msg, intptr_t param)
{ {
switch (msg) { switch (msg) {