From de73791a79e242ebaa609bc3d383916e070527e1 Mon Sep 17 00:00:00 2001 From: mchinen Date: Thu, 9 Feb 2012 05:23:16 +0000 Subject: [PATCH] revert 11465, going back to the original solution for clipping to prevent bad exports --- src/Dither.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Dither.cpp b/src/Dither.cpp index bf3bd00ec..98c799faf 100644 --- a/src/Dither.cpp +++ b/src/Dither.cpp @@ -76,7 +76,13 @@ const float Dither::SHAPED_BS[] = { 2.033f, -2.165f, 1.959f, -1.590f, 0.6149f }; // Dereference sample pointer and convert to float sample #define FROM_INT16(ptr) (*((short*)(ptr)) / CONVERT_DIV16) #define FROM_INT24(ptr) (*(( int*)(ptr)) / CONVERT_DIV24) -#define FROM_FLOAT(ptr) (*((float*)(ptr))) + +// For float, we internally allow values greater than 1.0, which +// would blow up the dithering to int values. FROM_FLOAT is +// only used to dither to int, so clip here. +#define FROM_FLOAT(ptr) (*((float*)(ptr)) > 1.0 ? 1.0 : \ + *((float*)(ptr)) < -1.0 ? -1.0 : \ + *((float*)(ptr))) // Promote sample to range of specified type, keep it float, though #define PROMOTE_TO_INT16(sample) ((sample) * CONVERT_DIV16) @@ -292,7 +298,7 @@ inline float Dither::ShapedDither(float sample) // Roll buffer and store last error mPhase = (mPhase + 1) & BUF_MASK; - mBuffer[mPhase] = xe - llrintf(result); + mBuffer[mPhase] = xe - lrintf(result); return result; }