mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 08:09:32 +02:00
Stop an overflow with large (>100dB) sample values.
This commit is contained in:
parent
7bdac9233b
commit
5b3f3f71ea
@ -76,13 +76,7 @@ const float Dither::SHAPED_BS[] = { 2.033f, -2.165f, 1.959f, -1.590f, 0.6149f };
|
|||||||
// Dereference sample pointer and convert to float sample
|
// Dereference sample pointer and convert to float sample
|
||||||
#define FROM_INT16(ptr) (*((short*)(ptr)) / CONVERT_DIV16)
|
#define FROM_INT16(ptr) (*((short*)(ptr)) / CONVERT_DIV16)
|
||||||
#define FROM_INT24(ptr) (*(( int*)(ptr)) / CONVERT_DIV24)
|
#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
|
// Promote sample to range of specified type, keep it float, though
|
||||||
#define PROMOTE_TO_INT16(sample) ((sample) * CONVERT_DIV16)
|
#define PROMOTE_TO_INT16(sample) ((sample) * CONVERT_DIV16)
|
||||||
@ -283,7 +277,7 @@ inline float Dither::TriangleDither(float sample)
|
|||||||
// Shaped dither
|
// Shaped dither
|
||||||
inline float Dither::ShapedDither(float sample)
|
inline float Dither::ShapedDither(float sample)
|
||||||
{
|
{
|
||||||
// Generate triangular dither, +-1 LSB, flat psd
|
// Generate triangular dither, +-1 LSB, flat psd
|
||||||
float r = DITHER_NOISE + DITHER_NOISE;
|
float r = DITHER_NOISE + DITHER_NOISE;
|
||||||
|
|
||||||
// Run FIR
|
// Run FIR
|
||||||
@ -298,7 +292,7 @@ inline float Dither::ShapedDither(float sample)
|
|||||||
|
|
||||||
// Roll buffer and store last error
|
// Roll buffer and store last error
|
||||||
mPhase = (mPhase + 1) & BUF_MASK;
|
mPhase = (mPhase + 1) & BUF_MASK;
|
||||||
mBuffer[mPhase] = xe - lrintf(result);
|
mBuffer[mPhase] = xe - llrintf(result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user