Implement the Float32 to UInt8 converters.

The loopback test now passes cleanly for the first time on my PreSonus FireStudio.
Added tests for clip and dither flag combinations to loopback.
This commit is contained in:
philburk 2011-09-01 22:08:32 +00:00
commit 9cdd56f5b4
4 changed files with 88 additions and 50 deletions

View file

@ -49,8 +49,7 @@
see: "require clipping for dithering sample conversion functions?"
http://www.portaudio.com/trac/ticket/112
@todo implement the converters marked IMPLEMENT ME: Float32_To_UInt8_Dither,
Float32_To_UInt8_Clip, Float32_To_UInt8_DitherClip, Int32_To_Int24_Dither,
@todo implement the converters marked IMPLEMENT ME: Int32_To_Int24_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"
@ -729,8 +728,7 @@ static void Float32_To_Int8_Dither(
{
float *src = (float*)sourceBuffer;
signed char *dest = (signed char*)destinationBuffer;
(void)ditherGenerator; /* unused parameter */
while( count-- )
{
float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
@ -821,12 +819,15 @@ static void Float32_To_UInt8_Dither(
{
float *src = (float*)sourceBuffer;
unsigned char *dest = (unsigned char*)destinationBuffer;
(void)ditherGenerator; /* unused parameter */
while( count-- )
{
/* IMPLEMENT ME */
float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
/* use smaller scaler to prevent overflow when we add the dither */
float dithered = (*src * (126.0f)) + dither;
PaInt32 samp = (PaInt32) dithered;
*dest = (unsigned char) (128 + samp);
src += sourceStride;
dest += destinationStride;
}
@ -845,7 +846,9 @@ static void Float32_To_UInt8_Clip(
while( count-- )
{
/* IMPLEMENT ME */
PaInt32 samp = 128 + (PaInt32)(*src * (127.0f));
PA_CLIP_( samp, 0x0000, 0x00FF );
*dest = (unsigned char) samp;
src += sourceStride;
dest += destinationStride;
@ -865,7 +868,12 @@ static void Float32_To_UInt8_DitherClip(
while( count-- )
{
/* IMPLEMENT ME */
float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
/* use smaller scaler to prevent overflow when we add the dither */
float dithered = (*src * (126.0f)) + dither;
PaInt32 samp = 128 + (PaInt32) dithered;
PA_CLIP_( samp, 0x0000, 0x00FF );
*dest = (unsigned char) samp;
src += sourceStride;
dest += destinationStride;

View file

@ -1009,6 +1009,10 @@ static OSStatus UpdateSampleRateFromDeviceProperty( PaMacCoreStream *stream, Aud
static OSStatus AudioDevicePropertyActualSampleRateListenerProc( AudioDeviceID inDevice, UInt32 inChannel, Boolean isInput, AudioDevicePropertyID inPropertyID, void *inClientData )
{
PaMacCoreStream *stream = (PaMacCoreStream*)inClientData;
// Make sure the callback is operating on a stream that is still valid!
assert( stream->streamRepresentation.magic == PA_STREAM_MAGIC );
OSStatus osErr = UpdateSampleRateFromDeviceProperty( stream, inDevice, isInput );
if( osErr == noErr )
{
@ -1034,6 +1038,10 @@ static OSStatus AudioDevicePropertyGenericListenerProc( AudioDeviceID inDevice,
{
OSStatus osErr = noErr;
PaMacCoreStream *stream = (PaMacCoreStream*)inClientData;
// Make sure the callback is operating on a stream that is still valid!
assert( stream->streamRepresentation.magic == PA_STREAM_MAGIC );
PaMacCoreDeviceProperties *deviceProperties = isInput ? &stream->inputProperties : &stream->outputProperties;
UInt32 *valuePtr = NULL;
switch( inPropertyID )
@ -2107,7 +2115,7 @@ static OSStatus AudioIOProc( void *inRefCon,
PaMacCoreStream *stream = (PaMacCoreStream*)inRefCon;
const bool isRender = inBusNumber == OUTPUT_ELEMENT;
int callbackResult = paContinue ;
double hostTimeStampInPaTime = HOST_TIME_TO_PA_TIME(inTimeStamp->mHostTime);
double hostTimeStampInPaTime = HOST_TIME_TO_PA_TIME(inTimeStamp->mHostTime);
VVDBUG(("AudioIOProc()\n"));