64const float SHAPED_BS[] = { 2.033f, -2.165f, 1.959f, -1.590f, 0.6149f };
78 return rand() / (float)RAND_MAX - 0.5f;
101 return *((
float*)(ptr)) > 1.0
103 *((
float*)(ptr)) < -1.0
109template<
typename dst_type>
111 dst_type *ptr,
float sample, dst_type min_bound, dst_type max_bound)
116 else if (x<(min_bound))
119 *ptr =
static_cast<dst_type
>(x);
124 short *dst,
float sample)
126 IMPLEMENT_STORE<short>(dst,
128 short(-32768),
short(32767));
133 int *dst,
float sample)
135 IMPLEMENT_STORE<int>(dst,
142template<
typename srcType,
typename dstType>
145 float (*load)(
const srcType *),
152 for (d = (
char*)dst, s = (
char*)src, ii = 0;
156 store(dither, state,
reinterpret_cast<dstType *
>(d), load(
reinterpret_cast<const srcType *
>(s)));
167 DITHER_LOOP<int, short>(dither, state,
171 DITHER_LOOP<float, short>(dither, state,
175 DITHER_LOOP<float, int>(dither, state,
178 else { wxASSERT(
false); }
220 unsigned int sourceStride ,
221 unsigned int destStride )
226 wxASSERT(
sizeof(
int) == 4);
227 wxASSERT(
sizeof(
short) == 2);
233 wxASSERT(sourceStride > 0);
234 wxASSERT(destStride > 0);
239 if (destFormat == sourceFormat)
243 if (destStride == 1 && sourceStride == 1)
244 memcpy(dest, source, len *
SAMPLE_SIZE(destFormat));
249 auto d = (
float*)dest;
250 auto s = (
const float*)source;
252 for (i = 0; i < len; i++, d += destStride, s += sourceStride)
258 auto s = (
const int*)source;
260 for (i = 0; i < len; i++, d += destStride, s += sourceStride)
265 auto d = (
short*)dest;
266 auto s = (
const short*)source;
268 for (i = 0; i < len; i++, d += destStride, s += sourceStride)
279 auto d = (
float*)dest;
283 auto s = (
const short*)source;
284 for (i = 0; i < len; i++, d += destStride, s += sourceStride)
289 auto s = (
const int*)source;
290 for (i = 0; i < len; i++, d += destStride, s += sourceStride)
300 auto s = (
const short*)source;
301 for (i = 0; i < len; i++, d += destStride, s += sourceStride)
309 DITHER(
NoDither,
mState, dest, destFormat, destStride, source, sourceFormat, sourceStride, len);
368 float result = xe + r;
380 {
XC(
"Triangle",
"dither") },
391 wxT(
"Quality/DitherAlgorithmChoice"),
397 wxT(
"Quality/DitherAlgorithm")
401 wxT(
"Quality/HQDitherAlgorithmChoice"),
407 wxT(
"Quality/HQDitherAlgorithm")
static void DITHER_TO_INT24(Ditherer dither, State &state, int *dst, float sample)
float(*)(State &, float) Ditherer
static float DITHER_NOISE()
static float FROM_INT24(const int *ptr)
static void DITHER_TO_INT16(Ditherer dither, State &state, short *dst, float sample)
static const std::initializer_list< EnumValueSymbol > choicesDither
static void IMPLEMENT_STORE(dst_type *ptr, float sample, dst_type min_bound, dst_type max_bound)
static float FROM_INT16(const short *ptr)
static auto intChoicesDither
static void DITHER(Ditherer dither, State &state, samplePtr dst, sampleFormat dstFormat, size_t dstStride, constSamplePtr src, sampleFormat srcFormat, size_t srcStride, size_t len)
static float ShapedDither(State &state, float sample)
static void DITHER_LOOP(Ditherer dither, State &state, void(*store)(Ditherer, State &, dstType *, float), float(*load)(const srcType *), samplePtr dst, sampleFormat dstFormat, size_t dstStride, constSamplePtr src, sampleFormat srcFormat, size_t srcStride, size_t len)
static float NoDither(State &, float sample)
static float TriangleDither(State &state, float sample)
static float FROM_FLOAT(const float *ptr)
constexpr auto CONVERT_DIV16
constexpr auto CONVERT_DIV24
static float RectangleDither(State &, float sample)
DitherType
These ditherers are currently available:
static DitherType FastDitherChoice()
void Reset()
Reset state of the dither.
Dither()
Default constructor.
static EnumSetting< DitherType > BestSetting
static DitherType BestDitherChoice()
static EnumSetting< DitherType > FastSetting
void Apply(DitherType ditherType, constSamplePtr source, sampleFormat sourceFormat, samplePtr dest, sampleFormat destFormat, unsigned int len, unsigned int sourceStride=1, unsigned int destStride=1)