while( count-- )
{
/* convert to 32 bit and drop the low 8 bits */
- double scaled = *src * 0x7FFFFFFF;
+ double scaled = (double)(*src) * 2147483647.0;
temp = (PaInt32) scaled;
#if defined(PA_LITTLE_ENDIAN)
void *sourceBuffer, signed int sourceStride,
unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
{
- #define _PA_CNV_RESCALE(__max_from,__max_to,g) ((1.0f/(float)(__max_from/2+1))*((float)((__max_to/2+1)+g)))
-#ifndef PA_BIG_ENDIAN
- #define _PA_INT24_TO_INT32(v) ((int)(((int)v[2] << 24)|((int)v[1] << 16)|((int)v[0] << 8)) >> 8)
-#else
- #define _PA_INT24_TO_INT32(v) ((int)(((int)v[0] << 24)|((int)v[1] << 16)|((int)v[2] << 8)) >> 8)
-#endif
- #define _PA_INT24_TO_FLOAT(v,g) ((float)(_PA_INT24_TO_INT32(v)) * _PA_CNV_RESCALE(0xffffff,0xffff,g))
+ unsigned char *src = (unsigned char*)sourceBuffer;
+ PaInt16 *dest = (PaInt16*)destinationBuffer;
- unsigned char *src = (unsigned char *)sourceBuffer;
- PaInt16 *dest = (PaInt16 *)destinationBuffer;
- float dither, dithered;
+ PaInt32 temp, dither;
while( count-- )
{
- dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
-
- /* downscale 24-bit int to 16-bit int placed into 32-bit float container,
- 16-bit scaler is decreased by 2 to leave space for dither in order not to overflow
- */
- dithered = _PA_INT24_TO_FLOAT(src, -2.0f) + dither;
-#ifdef PA_USE_C99_LRINTF
- *dest = lrintf(dithered-0.5f);
-#else
- *dest = (PaInt16) dithered;
+#if defined(PA_LITTLE_ENDIAN)
+ temp = (((PaInt32)src[0]) << 8);
+ temp = temp | (((PaInt32)src[1]) << 16);
+ temp = temp | (((PaInt32)src[2]) << 24);
+#elif defined(PA_BIG_ENDIAN)
+ temp = (((PaInt32)src[0]) << 24);
+ temp = temp | (((PaInt32)src[1]) << 16);
+ temp = temp | (((PaInt32)src[2]) << 8);
#endif
- src += sourceStride * 3;
+ /* REVIEW */
+ dither = PaUtil_Generate16BitTriangularDither( ditherGenerator );
+ *dest = (PaInt16) (((temp >> 1) + dither) >> 15);
+
+ src += sourceStride * 3;
dest += destinationStride;
}
}
-
/* -------------------------------------------------------------------------- */
static void Int24_To_Int8(
void *sourceBuffer, signed int sourceStride,
unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
{
- (void) destinationBuffer; /* unused parameters */
- (void) destinationStride; /* unused parameters */
- (void) sourceBuffer; /* unused parameters */
- (void) sourceStride; /* unused parameters */
- (void) count; /* unused parameters */
- (void) ditherGenerator; /* unused parameters */
- /* IMPLEMENT ME */
+ unsigned char *src = (unsigned char*)sourceBuffer;
+ signed char *dest = (signed char*)destinationBuffer;
+
+ PaInt32 temp, dither;
+
+ while( count-- )
+ {
+
+#if defined(PA_LITTLE_ENDIAN)
+ temp = (((PaInt32)src[0]) << 8);
+ temp = temp | (((PaInt32)src[1]) << 16);
+ temp = temp | (((PaInt32)src[2]) << 24);
+#elif defined(PA_BIG_ENDIAN)
+ temp = (((PaInt32)src[0]) << 24);
+ temp = temp | (((PaInt32)src[1]) << 16);
+ temp = temp | (((PaInt32)src[2]) << 8);
+#endif
+
+ /* REVIEW */
+ dither = PaUtil_Generate16BitTriangularDither( ditherGenerator );
+ *dest = (signed char) (((temp >> 1) + dither) >> 23);
+
+ src += sourceStride * 3;
+ dest += destinationStride;
+ }
}
/* -------------------------------------------------------------------------- */