summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/dsp.c32
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 */
237static inline long clip_sample(int32_t sample, int32_t min, int32_t range) 237static 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 */
989int dsp_callback(int msg, intptr_t param) 983int dsp_callback(int msg, intptr_t param)
990{ 984{
991 switch (msg) { 985 switch (msg) {