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
diff --git a/apps/dsp.c b/apps/dsp.c
index 699b0c5..305288f 100644
--- a/apps/dsp.c
+++ b/apps/dsp.c
@@ -236,14 +236,13 @@
 /* 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)
 {
-    int32_t c = sample - min;
-    if ((uint32_t)c > (uint32_t)range)
+    if ((uint32_t)(sample - min) > (uint32_t)range)
     {
-        sample -= c;
-        if (c > 0)
-            sample += range;
+        int32_t c = min;
+        if (sample > min)
+            c += range;
+        sample = c
     }
-
     return sample;
 }
 #endif
@@ -488,20 +487,12 @@
             dither->random = random;
 
             /* Clip */
-            int32_t c = output - min;
-            if ((uint32_t)c > (uint32_t)range)
+            if ((uint32_t)(output - min) > (uint32_t)range)
             {
-                output -= c;
-                if (c > 0)
-                {
-                    output += range;
-                    if (sample > max)
-                        sample = max;
-                }
-                else if (sample < min)
-                {
-                    sample = min;
-                }
+                int32_t c = min;
+                if (output > min)
+                    c += range;
+                output = c;
             }
 
             output &= ~mask;
@@ -986,6 +977,9 @@
 }
 #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)
 {
     switch (msg) {