Skip to content

Commit

Permalink
remove all alternative sample conversion code using lrintf in pa_conv…
Browse files Browse the repository at this point in the history
…erters.c. this is code guarded by PA_USE_C99_LRINTF. Fixes #390.
  • Loading branch information
RossBencina committed Aug 25, 2023
1 parent 6ee9836 commit 6edbfc7
Showing 1 changed file with 2 additions and 45 deletions.
47 changes: 2 additions & 45 deletions src/common/pa_converters.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
@brief Conversion function implementations.
If the C9x function lrintf() is available, define PA_USE_C99_LRINTF to use it
@todo Consider whether functions which dither but don't clip should exist,
V18 automatically enabled clipping whenever dithering was selected. Perhaps
we should do the same.
Expand Down Expand Up @@ -343,13 +341,8 @@ static void Float32_To_Int32(
while( count-- )
{
/* REVIEW */
#ifdef PA_USE_C99_LRINTF
float scaled = *src * 0x7FFFFFFF;
*dest = lrintf(scaled-0.5f);
#else
double scaled = *src * 0x7FFFFFFF;
*dest = (PaInt32) scaled;
#endif

src += sourceStride;
dest += destinationStride;
Expand All @@ -369,17 +362,11 @@ static void Float32_To_Int32_Dither(
while( count-- )
{
/* REVIEW */
#ifdef PA_USE_C99_LRINTF
float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
/* use smaller scaler to prevent overflow when we add the dither */
float dithered = ((float)*src * (2147483646.0f)) + dither;
*dest = lrintf(dithered - 0.5f);
#else
double dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
/* use smaller scaler to prevent overflow when we add the dither */
double dithered = ((double)*src * (2147483646.0)) + dither;
*dest = (PaInt32) dithered;
#endif

src += sourceStride;
dest += destinationStride;
}
Expand All @@ -399,15 +386,9 @@ static void Float32_To_Int32_Clip(
while( count-- )
{
/* REVIEW */
#ifdef PA_USE_C99_LRINTF
float scaled = *src * 0x7FFFFFFF;
PA_CLIP_( scaled, -2147483648.f, 2147483647.f );
*dest = lrintf(scaled-0.5f);
#else
double scaled = *src * 0x7FFFFFFF;
PA_CLIP_( scaled, -2147483648., 2147483647. );
*dest = (PaInt32) scaled;
#endif

src += sourceStride;
dest += destinationStride;
Expand All @@ -427,19 +408,11 @@ static void Float32_To_Int32_DitherClip(
while( count-- )
{
/* REVIEW */
#ifdef PA_USE_C99_LRINTF
float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
/* use smaller scaler to prevent overflow when we add the dither */
float dithered = ((float)*src * (2147483646.0f)) + dither;
PA_CLIP_( dithered, -2147483648.f, 2147483647.f );
*dest = lrintf(dithered-0.5f);
#else
double dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
/* use smaller scaler to prevent overflow when we add the dither */
double dithered = ((double)*src * (2147483646.0)) + dither;
PA_CLIP_( dithered, -2147483648., 2147483647. );
*dest = (PaInt32) dithered;
#endif

src += sourceStride;
dest += destinationStride;
Expand Down Expand Up @@ -601,13 +574,8 @@ static void Float32_To_Int16(

while( count-- )
{
#ifdef PA_USE_C99_LRINTF
float tempf = (*src * (32767.0f)) ;
*dest = lrintf(tempf-0.5f);
#else
short samp = (short) (*src * (32767.0f));
*dest = samp;
#endif

src += sourceStride;
dest += destinationStride;
Expand All @@ -631,11 +599,7 @@ static void Float32_To_Int16_Dither(
/* use smaller scaler to prevent overflow when we add the dither */
float dithered = (*src * (32766.0f)) + dither;

#ifdef PA_USE_C99_LRINTF
*dest = lrintf(dithered-0.5f);
#else
*dest = (PaInt16) dithered;
#endif

src += sourceStride;
dest += destinationStride;
Expand All @@ -655,11 +619,8 @@ static void Float32_To_Int16_Clip(

while( count-- )
{
#ifdef PA_USE_C99_LRINTF
long samp = lrintf((*src * (32767.0f)) -0.5f);
#else
long samp = (PaInt32) (*src * (32767.0f));
#endif

PA_CLIP_( samp, -0x8000, 0x7FFF );
*dest = (PaInt16) samp;

Expand Down Expand Up @@ -687,11 +648,7 @@ static void Float32_To_Int16_DitherClip(
float dithered = (*src * (32766.0f)) + dither;
PaInt32 samp = (PaInt32) dithered;
PA_CLIP_( samp, -0x8000, 0x7FFF );
#ifdef PA_USE_C99_LRINTF
*dest = lrintf(samp-0.5f);
#else
*dest = (PaInt16) samp;
#endif

src += sourceStride;
dest += destinationStride;
Expand Down

0 comments on commit 6edbfc7

Please sign in to comment.