diff options
Diffstat (limited to '3rdparty/portaudio/src/common/pa_converters.c')
-rw-r--r-- | 3rdparty/portaudio/src/common/pa_converters.c | 217 |
1 files changed, 87 insertions, 130 deletions
diff --git a/3rdparty/portaudio/src/common/pa_converters.c b/3rdparty/portaudio/src/common/pa_converters.c index 2107f5e2891..dbf0523561d 100644 --- a/3rdparty/portaudio/src/common/pa_converters.c +++ b/3rdparty/portaudio/src/common/pa_converters.c @@ -26,13 +26,13 @@ */ /* - * The text above constitutes the entire PortAudio license; however, + * The text above constitutes the entire PortAudio license; however, * the PortAudio community also makes the following non-binding requests: * * Any person wishing to distribute modifications to the Software is * requested to send the modifications to the original developer so that - * they can be incorporated into the canonical version. It is also - * requested that these non-binding requests be included along with the + * they can be incorporated into the canonical version. It is also + * requested that these non-binding requests be included along with the * license above. */ @@ -40,17 +40,15 @@ @ingroup common_src @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. + we should do the same. see: "require clipping for dithering sample conversion functions?" http://www.portaudio.com/trac/ticket/112 @todo implement the converters marked IMPLEMENT ME: Int32_To_Int24_Dither, - Int32_To_UInt8_Dither, Int24_To_Int16_Dither, Int24_To_Int8_Dither, + Int32_To_UInt8_Dither, Int24_To_Int16_Dither, Int24_To_Int8_Dither, Int24_To_UInt8_Dither, Int16_To_Int8_Dither, Int16_To_UInt8_Dither see: "some conversion functions are not implemented in pa_converters.c" http://www.portaudio.com/trac/ticket/35 @@ -74,7 +72,7 @@ PaSampleFormat PaUtil_SelectClosestAvailableFormat( format &= ~paNonInterleaved; availableFormats &= ~paNonInterleaved; - + if( (format & availableFormats) == 0 ) { /* NOTE: this code depends on the sample format constants being in @@ -97,7 +95,7 @@ PaSampleFormat PaUtil_SelectClosestAvailableFormat( { result = 0; } - + if( result == 0 ){ /* scan for worse formats */ result = format; @@ -110,7 +108,7 @@ PaSampleFormat PaUtil_SelectClosestAvailableFormat( if( (result & availableFormats) == 0 ) result = paSampleFormatNotSupported; } - + }else{ result = format; } @@ -286,7 +284,7 @@ PaUtilConverterTable paConverters = { 0, /* PaUtilConverter *Int24_To_Int8_Dither; */ 0, /* PaUtilConverter *Int24_To_UInt8; */ 0, /* PaUtilConverter *Int24_To_UInt8_Dither; */ - + 0, /* PaUtilConverter *Int16_To_Float32; */ 0, /* PaUtilConverter *Int16_To_Int32; */ 0, /* PaUtilConverter *Int16_To_Int24; */ @@ -343,14 +341,9 @@ 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 - + *dest = (PaInt32) scaled; + src += sourceStride; dest += destinationStride; } @@ -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; } @@ -395,19 +382,13 @@ static void Float32_To_Int32_Clip( float *src = (float*)sourceBuffer; PaInt32 *dest = (PaInt32*)destinationBuffer; (void) ditherGenerator; /* unused parameter */ - + 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; @@ -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; @@ -458,13 +431,13 @@ static void Float32_To_Int24( PaInt32 temp; (void) ditherGenerator; /* unused parameter */ - + while( count-- ) { /* convert to 32 bit and drop the low 8 bits */ double scaled = (double)(*src) * 2147483647.0; temp = (PaInt32) scaled; - + #if defined(PA_LITTLE_ENDIAN) dest[0] = (unsigned char)(temp >> 8); dest[1] = (unsigned char)(temp >> 16); @@ -498,7 +471,7 @@ static void Float32_To_Int24_Dither( double dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator ); /* use smaller scaler to prevent overflow when we add the dither */ double dithered = ((double)*src * (2147483646.0)) + dither; - + temp = (PaInt32) dithered; #if defined(PA_LITTLE_ENDIAN) @@ -528,7 +501,7 @@ static void Float32_To_Int24_Clip( PaInt32 temp; (void) ditherGenerator; /* unused parameter */ - + while( count-- ) { /* convert to 32 bit and drop the low 8 bits */ @@ -561,16 +534,16 @@ static void Float32_To_Int24_DitherClip( float *src = (float*)sourceBuffer; unsigned char *dest = (unsigned char*)destinationBuffer; PaInt32 temp; - + while( count-- ) { /* convert to 32 bit and drop the low 8 bits */ - + 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. ); - + temp = (PaInt32) dithered; #if defined(PA_LITTLE_ENDIAN) @@ -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; @@ -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; @@ -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; @@ -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; @@ -728,7 +685,7 @@ static void Float32_To_Int8_Dither( { float *src = (float*)sourceBuffer; signed char *dest = (signed char*)destinationBuffer; - + while( count-- ) { float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator ); @@ -819,7 +776,7 @@ static void Float32_To_UInt8_Dither( { float *src = (float*)sourceBuffer; unsigned char *dest = (unsigned char*)destinationBuffer; - + while( count-- ) { float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator ); @@ -827,7 +784,7 @@ static void Float32_To_UInt8_Dither( float dithered = (*src * (126.0f)) + dither; PaInt32 samp = (PaInt32) dithered; *dest = (unsigned char) (128 + samp); - + src += sourceStride; dest += destinationStride; } @@ -910,10 +867,10 @@ static void Int32_To_Int24( PaInt32 *src = (PaInt32*)sourceBuffer; unsigned char *dest = (unsigned char*)destinationBuffer; (void) ditherGenerator; /* unused parameter */ - - while( count-- ) + + while( count-- ) { - /* REVIEW */ + /* REVIEW */ #if defined(PA_LITTLE_ENDIAN) dest[0] = (unsigned char)(*src >> 8); dest[1] = (unsigned char)(*src >> 16); @@ -1041,7 +998,7 @@ static void Int32_To_UInt8( while( count-- ) { - (*dest) = (unsigned char)(((*src) >> 24) + 128); + (*dest) = (unsigned char)(((*src) >> 24) + 128); src += sourceStride; dest += destinationStride; @@ -1055,16 +1012,16 @@ static void Int32_To_UInt8_Dither( void *sourceBuffer, signed int sourceStride, unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator ) { - PaInt32 *src = (PaInt32*)sourceBuffer; - unsigned char *dest = (unsigned char*)destinationBuffer; + /* PaInt32 *src = (PaInt32*)sourceBuffer; + unsigned char *dest = (unsigned char*)destinationBuffer; */ (void)ditherGenerator; /* unused parameter */ while( count-- ) { /* IMPLEMENT ME */ - src += sourceStride; - dest += destinationStride; + /* src += sourceStride; + dest += destinationStride; */ } } @@ -1080,12 +1037,12 @@ static void Int24_To_Float32( PaInt32 temp; (void) ditherGenerator; /* unused parameter */ - + while( count-- ) { #if defined(PA_LITTLE_ENDIAN) - temp = (((PaInt32)src[0]) << 8); + temp = (((PaInt32)src[0]) << 8); temp = temp | (((PaInt32)src[1]) << 16); temp = temp | (((PaInt32)src[2]) << 24); #elif defined(PA_BIG_ENDIAN) @@ -1113,12 +1070,12 @@ static void Int24_To_Int32( PaInt32 temp; (void) ditherGenerator; /* unused parameter */ - + while( count-- ) { #if defined(PA_LITTLE_ENDIAN) - temp = (((PaInt32)src[0]) << 8); + temp = (((PaInt32)src[0]) << 8); temp = temp | (((PaInt32)src[1]) << 16); temp = temp | (((PaInt32)src[2]) << 24); #elif defined(PA_BIG_ENDIAN) @@ -1143,20 +1100,20 @@ static void Int24_To_Int16( { unsigned char *src = (unsigned char*)sourceBuffer; PaInt16 *dest = (PaInt16*)destinationBuffer; - + PaInt16 temp; (void) ditherGenerator; /* unused parameter */ - + while( count-- ) { - + #if defined(PA_LITTLE_ENDIAN) - /* src[0] is discarded */ + /* src[0] is discarded */ temp = (((PaInt16)src[1])); temp = temp | (PaInt16)(((PaInt16)src[2]) << 8); #elif defined(PA_BIG_ENDIAN) - /* src[2] is discarded */ + /* src[2] is discarded */ temp = (PaInt16)(((PaInt16)src[0]) << 8); temp = temp | (((PaInt16)src[1])); #endif @@ -1184,7 +1141,7 @@ static void Int24_To_Int16_Dither( { #if defined(PA_LITTLE_ENDIAN) - temp = (((PaInt32)src[0]) << 8); + temp = (((PaInt32)src[0]) << 8); temp = temp | (((PaInt32)src[1]) << 16); temp = temp | (((PaInt32)src[2]) << 24); #elif defined(PA_BIG_ENDIAN) @@ -1211,20 +1168,20 @@ static void Int24_To_Int8( { unsigned char *src = (unsigned char*)sourceBuffer; signed char *dest = (signed char*)destinationBuffer; - + (void) ditherGenerator; /* unused parameter */ - + while( count-- ) - { - + { + #if defined(PA_LITTLE_ENDIAN) - /* src[0] is discarded */ - /* src[1] is discarded */ + /* src[0] is discarded */ + /* src[1] is discarded */ *dest = src[2]; #elif defined(PA_BIG_ENDIAN) - /* src[2] is discarded */ - /* src[1] is discarded */ - *dest = src[0]; + /* src[2] is discarded */ + /* src[1] is discarded */ + *dest = src[0]; #endif src += sourceStride * 3; @@ -1241,14 +1198,14 @@ static void Int24_To_Int8_Dither( { 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 = (((PaInt32)src[0]) << 8); temp = temp | (((PaInt32)src[1]) << 16); temp = temp | (((PaInt32)src[2]) << 24); #elif defined(PA_BIG_ENDIAN) @@ -1275,20 +1232,20 @@ static void Int24_To_UInt8( { unsigned char *src = (unsigned char*)sourceBuffer; unsigned char *dest = (unsigned char*)destinationBuffer; - + (void) ditherGenerator; /* unused parameter */ - + while( count-- ) { - + #if defined(PA_LITTLE_ENDIAN) - /* src[0] is discarded */ - /* src[1] is discarded */ + /* src[0] is discarded */ + /* src[1] is discarded */ *dest = (unsigned char)(src[2] + 128); #elif defined(PA_BIG_ENDIAN) *dest = (unsigned char)(src[0] + 128); - /* src[1] is discarded */ - /* src[2] is discarded */ + /* src[1] is discarded */ + /* src[2] is discarded */ #endif src += sourceStride * 3; @@ -1325,7 +1282,7 @@ static void Int16_To_Float32( while( count-- ) { - float samp = *src * const_1_div_32768_; /* FIXME: i'm concerned about this being asymetrical with float->int16 -rb */ + float samp = *src * const_1_div_32768_; /* FIXME: i'm concerned about this being asymmetrical with float->int16 -rb */ *dest = samp; src += sourceStride; @@ -1349,7 +1306,7 @@ static void Int16_To_Int32( /* REVIEW: we should consider something like (*src << 16) | (*src & 0xFFFF) */ - + *dest = *src << 16; src += sourceStride; @@ -1369,11 +1326,11 @@ static void Int16_To_Int24( PaInt16 temp; (void) ditherGenerator; /* unused parameter */ - + while( count-- ) { temp = *src; - + #if defined(PA_LITTLE_ENDIAN) dest[0] = 0; dest[1] = (unsigned char)(temp); @@ -1416,16 +1373,16 @@ static void Int16_To_Int8_Dither( void *sourceBuffer, signed int sourceStride, unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator ) { - PaInt16 *src = (PaInt16*)sourceBuffer; - signed char *dest = (signed char*)destinationBuffer; + /* PaInt16 *src = (PaInt16*)sourceBuffer; + signed char *dest = (signed char*)destinationBuffer; */ (void)ditherGenerator; /* unused parameter */ while( count-- ) { /* IMPLEMENT ME */ - src += sourceStride; - dest += destinationStride; + /* src += sourceStride; + dest += destinationStride; */ } } @@ -1442,7 +1399,7 @@ static void Int16_To_UInt8( while( count-- ) { - (*dest) = (unsigned char)(((*src) >> 8) + 128); + (*dest) = (unsigned char)(((*src) >> 8) + 128); src += sourceStride; dest += destinationStride; @@ -1456,16 +1413,16 @@ static void Int16_To_UInt8_Dither( void *sourceBuffer, signed int sourceStride, unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator ) { - PaInt16 *src = (PaInt16*)sourceBuffer; - unsigned char *dest = (unsigned char*)destinationBuffer; + /* PaInt16 *src = (PaInt16*)sourceBuffer; + unsigned char *dest = (unsigned char*)destinationBuffer; */ (void)ditherGenerator; /* unused parameter */ while( count-- ) { /* IMPLEMENT ME */ - src += sourceStride; - dest += destinationStride; + /* src += sourceStride; + dest += destinationStride; */ } } @@ -1503,7 +1460,7 @@ static void Int8_To_Int32( while( count-- ) { - (*dest) = (*src) << 24; + (*dest) = (*src) << 24; src += sourceStride; dest += destinationStride; @@ -1613,7 +1570,7 @@ static void UInt8_To_Int32( while( count-- ) { - (*dest) = (*src - 128) << 24; + (*dest) = (*src - 128) << 24; src += sourceStride; dest += destinationStride; @@ -1627,11 +1584,11 @@ static void UInt8_To_Int24( void *sourceBuffer, signed int sourceStride, unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator ) { - unsigned char *src = (unsigned char*)sourceBuffer; + unsigned char *src = (unsigned char*)sourceBuffer; unsigned char *dest = (unsigned char*)destinationBuffer; (void) ditherGenerator; /* unused parameters */ - - while( count-- ) + + while( count-- ) { #if defined(PA_LITTLE_ENDIAN) @@ -1643,10 +1600,10 @@ static void UInt8_To_Int24( dest[1] = 0; dest[2] = 0; #endif - + src += sourceStride; - dest += destinationStride * 3; - } + dest += destinationStride * 3; + } } /* -------------------------------------------------------------------------- */ @@ -1698,7 +1655,7 @@ static void Copy_8_To_8( { unsigned char *src = (unsigned char*)sourceBuffer; unsigned char *dest = (unsigned char*)destinationBuffer; - + (void) ditherGenerator; /* unused parameter */ while( count-- ) @@ -1719,9 +1676,9 @@ static void Copy_16_To_16( { PaUint16 *src = (PaUint16 *)sourceBuffer; PaUint16 *dest = (PaUint16 *)destinationBuffer; - + (void) ditherGenerator; /* unused parameter */ - + while( count-- ) { *dest = *src; @@ -1742,7 +1699,7 @@ static void Copy_24_To_24( unsigned char *dest = (unsigned char*)destinationBuffer; (void) ditherGenerator; /* unused parameter */ - + while( count-- ) { dest[0] = src[0]; @@ -1765,7 +1722,7 @@ static void Copy_32_To_32( PaUint32 *src = (PaUint32 *)sourceBuffer; (void) ditherGenerator; /* unused parameter */ - + while( count-- ) { *dest = *src; @@ -1787,7 +1744,7 @@ PaUtilConverterTable paConverters = { Float32_To_Int24_Dither, /* PaUtilConverter *Float32_To_Int24_Dither; */ Float32_To_Int24_Clip, /* PaUtilConverter *Float32_To_Int24_Clip; */ Float32_To_Int24_DitherClip, /* PaUtilConverter *Float32_To_Int24_DitherClip; */ - + Float32_To_Int16, /* PaUtilConverter *Float32_To_Int16; */ Float32_To_Int16_Dither, /* PaUtilConverter *Float32_To_Int16_Dither; */ Float32_To_Int16_Clip, /* PaUtilConverter *Float32_To_Int16_Clip; */ |