diff options
author | Thom Johansen <thomj@rockbox.org> | 2007-10-29 23:58:00 +0000 |
---|---|---|
committer | Thom Johansen <thomj@rockbox.org> | 2007-10-29 23:58:00 +0000 |
commit | daf937422c17ea571b67e3ef7dae570369daa8a1 (patch) | |
tree | 27176aa4e280a2055ee6ba35943aa8006084b1ed /apps/dsp.c | |
parent | 781c82c0d68e007582e98173ff9b767c6bc22df8 (diff) | |
download | rockbox-daf937422c17ea571b67e3ef7dae570369daa8a1.tar.gz rockbox-daf937422c17ea571b67e3ef7dae570369daa8a1.zip |
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
Diffstat (limited to 'apps/dsp.c')
-rw-r--r-- | apps/dsp.c | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/apps/dsp.c b/apps/dsp.c index 699b0c5c67..305288fa77 100644 --- a/apps/dsp.c +++ b/apps/dsp.c | |||
@@ -236,14 +236,13 @@ static inline struct dsp_config * switch_dsp(struct dsp_config *_dsp) | |||
236 | /* Clip sample to arbitrary limits where range > 0 and min + range = max */ | 236 | /* Clip sample to arbitrary limits where range > 0 and min + range = max */ |
237 | static inline long clip_sample(int32_t sample, int32_t min, int32_t range) | 237 | static inline long clip_sample(int32_t sample, int32_t min, int32_t range) |
238 | { | 238 | { |
239 | int32_t c = sample - min; | 239 | if ((uint32_t)(sample - min) > (uint32_t)range) |
240 | if ((uint32_t)c > (uint32_t)range) | ||
241 | { | 240 | { |
242 | sample -= c; | 241 | int32_t c = min; |
243 | if (c > 0) | 242 | if (sample > min) |
244 | sample += range; | 243 | c += range; |
244 | sample = c | ||
245 | } | 245 | } |
246 | |||
247 | return sample; | 246 | return sample; |
248 | } | 247 | } |
249 | #endif | 248 | #endif |
@@ -488,20 +487,12 @@ static void sample_output_dithered(int count, struct dsp_data *data, | |||
488 | dither->random = random; | 487 | dither->random = random; |
489 | 488 | ||
490 | /* Clip */ | 489 | /* Clip */ |
491 | int32_t c = output - min; | 490 | if ((uint32_t)(output - min) > (uint32_t)range) |
492 | if ((uint32_t)c > (uint32_t)range) | ||
493 | { | 491 | { |
494 | output -= c; | 492 | int32_t c = min; |
495 | if (c > 0) | 493 | if (output > min) |
496 | { | 494 | c += range; |
497 | output += range; | 495 | output = c; |
498 | if (sample > max) | ||
499 | sample = max; | ||
500 | } | ||
501 | else if (sample < min) | ||
502 | { | ||
503 | sample = min; | ||
504 | } | ||
505 | } | 496 | } |
506 | 497 | ||
507 | output &= ~mask; | 498 | output &= ~mask; |
@@ -986,6 +977,9 @@ static void set_tone_controls(void) | |||
986 | } | 977 | } |
987 | #endif | 978 | #endif |
988 | 979 | ||
980 | /* Hook back from firmware/ part of audio, which can't/shouldn't call apps/ | ||
981 | * code directly. | ||
982 | */ | ||
989 | int dsp_callback(int msg, intptr_t param) | 983 | int dsp_callback(int msg, intptr_t param) |
990 | { | 984 | { |
991 | switch (msg) { | 985 | switch (msg) { |