diff options
Diffstat (limited to '3rdparty/portaudio/src/common/pa_process.c')
-rw-r--r-- | 3rdparty/portaudio/src/common/pa_process.c | 360 |
1 files changed, 183 insertions, 177 deletions
diff --git a/3rdparty/portaudio/src/common/pa_process.c b/3rdparty/portaudio/src/common/pa_process.c index 0faf8414cfa..29fca64fa3a 100644 --- a/3rdparty/portaudio/src/common/pa_process.c +++ b/3rdparty/portaudio/src/common/pa_process.c @@ -27,13 +27,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. */ @@ -142,7 +142,7 @@ PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bp, } else /* unknown host buffer size */ { - bp->framesPerTempBuffer = PA_FRAMES_PER_TEMP_BUFFER_WHEN_HOST_BUFFER_SIZE_IS_UNKNOWN_; + bp->framesPerTempBuffer = PA_FRAMES_PER_TEMP_BUFFER_WHEN_HOST_BUFFER_SIZE_IS_UNKNOWN_; } } else @@ -198,7 +198,7 @@ PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bp, bp->framesInTempInputBuffer = bp->initialFramesInTempInputBuffer; bp->framesInTempOutputBuffer = bp->initialFramesInTempOutputBuffer; - + if( inputChannelCount > 0 ) { bytesPerSample = Pa_GetSampleSize( hostInputSampleFormat ); @@ -224,7 +224,7 @@ PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bp, } /* Under the assumption that no ADC in existence delivers better than 24bits resolution, - we disable dithering when host input format is paInt32 and user format is paInt24, + we disable dithering when host input format is paInt32 and user format is paInt24, since the host samples will just be padded with zeros anyway. */ tempInputStreamFlags = streamFlags; @@ -239,30 +239,33 @@ PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bp, PaUtil_SelectConverter( hostInputSampleFormat, userInputSampleFormat, tempInputStreamFlags ); bp->inputZeroer = PaUtil_SelectZeroer( userInputSampleFormat ); - + bp->userInputIsInterleaved = (userInputSampleFormat & paNonInterleaved)?0:1; - + bp->hostInputIsInterleaved = (hostInputSampleFormat & paNonInterleaved)?0:1; bp->userInputSampleFormatIsEqualToHost = ((userInputSampleFormat & ~paNonInterleaved) == (hostInputSampleFormat & ~paNonInterleaved)); tempInputBufferSize = bp->framesPerTempBuffer * bp->bytesPerUserInputSample * inputChannelCount; - - bp->tempInputBuffer = PaUtil_AllocateMemory( tempInputBufferSize ); + + bp->tempInputBuffer = PaUtil_AllocateZeroInitializedMemory( tempInputBufferSize ); if( bp->tempInputBuffer == 0 ) { result = paInsufficientMemory; goto error; } - + if( bp->framesInTempInputBuffer > 0 ) - memset( bp->tempInputBuffer, 0, tempInputBufferSize ); + { + /* NOTE: we depend on bp->tempInputBuffer being zero-initialized by the allocator. */ + /* memset( bp->tempInputBuffer, 0, tempInputBufferSize ); */ + } if( userInputSampleFormat & paNonInterleaved ) { bp->tempInputBufferPtrs = - (void **)PaUtil_AllocateMemory( sizeof(void*)*inputChannelCount ); + (void **)PaUtil_AllocateZeroInitializedMemory( sizeof(void*)*inputChannelCount ); if( bp->tempInputBufferPtrs == 0 ) { result = paInsufficientMemory; @@ -271,7 +274,7 @@ PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bp, } bp->hostInputChannels[0] = (PaUtilChannelDescriptor*) - PaUtil_AllocateMemory( sizeof(PaUtilChannelDescriptor) * inputChannelCount * 2); + PaUtil_AllocateZeroInitializedMemory( sizeof(PaUtilChannelDescriptor) * inputChannelCount * 2); if( bp->hostInputChannels[0] == 0 ) { result = paInsufficientMemory; @@ -319,7 +322,7 @@ PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bp, tempOutputBufferSize = bp->framesPerTempBuffer * bp->bytesPerUserOutputSample * outputChannelCount; - bp->tempOutputBuffer = PaUtil_AllocateMemory( tempOutputBufferSize ); + bp->tempOutputBuffer = PaUtil_AllocateZeroInitializedMemory( tempOutputBufferSize ); if( bp->tempOutputBuffer == 0 ) { result = paInsufficientMemory; @@ -327,12 +330,15 @@ PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bp, } if( bp->framesInTempOutputBuffer > 0 ) - memset( bp->tempOutputBuffer, 0, tempOutputBufferSize ); - + { + /* NOTE: we depend on bp->tempOutputBuffer being zero-initialized by the allocator. */ + /* memset( bp->tempOutputBuffer, 0, tempOutputBufferSize ); */ + } + if( userOutputSampleFormat & paNonInterleaved ) { bp->tempOutputBufferPtrs = - (void **)PaUtil_AllocateMemory( sizeof(void*)*outputChannelCount ); + (void **)PaUtil_AllocateZeroInitializedMemory( sizeof(void*)*outputChannelCount ); if( bp->tempOutputBufferPtrs == 0 ) { result = paInsufficientMemory; @@ -341,9 +347,9 @@ PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bp, } bp->hostOutputChannels[0] = (PaUtilChannelDescriptor*) - PaUtil_AllocateMemory( sizeof(PaUtilChannelDescriptor)*outputChannelCount * 2 ); + PaUtil_AllocateZeroInitializedMemory( sizeof(PaUtilChannelDescriptor)*outputChannelCount * 2 ); if( bp->hostOutputChannels[0] == 0 ) - { + { result = paInsufficientMemory; goto error; } @@ -393,7 +399,7 @@ void PaUtil_TerminateBufferProcessor( PaUtilBufferProcessor* bp ) if( bp->hostInputChannels[0] ) PaUtil_FreeMemory( bp->hostInputChannels[0] ); - + if( bp->tempOutputBuffer ) PaUtil_FreeMemory( bp->tempOutputBuffer ); @@ -420,7 +426,7 @@ void PaUtil_ResetBufferProcessor( PaUtilBufferProcessor* bp ) } if( bp->framesInTempOutputBuffer > 0 ) - { + { tempOutputBufferSize = bp->framesPerTempBuffer * bp->bytesPerUserOutputSample * bp->outputChannelCount; memset( bp->tempOutputBuffer, 0, tempOutputBufferSize ); @@ -448,7 +454,7 @@ void PaUtil_SetInputFrameCount( PaUtilBufferProcessor* bp, else bp->hostInputFrameCount[0] = frameCount; } - + void PaUtil_SetNoInput( PaUtilBufferProcessor* bp ) { @@ -462,7 +468,7 @@ void PaUtil_SetInputChannel( PaUtilBufferProcessor* bp, unsigned int channel, void *data, unsigned int stride ) { assert( channel < bp->inputChannelCount ); - + bp->hostInputChannels[0][channel].data = data; bp->hostInputChannels[0][channel].stride = stride; } @@ -496,7 +502,7 @@ void PaUtil_SetNonInterleavedInputChannel( PaUtilBufferProcessor* bp, { assert( channel < bp->inputChannelCount ); assert( !bp->hostInputIsInterleaved ); - + bp->hostInputChannels[0][channel].data = data; bp->hostInputChannels[0][channel].stride = 1; } @@ -532,7 +538,7 @@ void PaUtil_Set2ndInterleavedInputChannels( PaUtilBufferProcessor* bp, assert( firstChannel < bp->inputChannelCount ); assert( firstChannel + channelCount <= bp->inputChannelCount ); assert( bp->hostInputIsInterleaved ); - + for( i=0; i< channelCount; ++i ) { bp->hostInputChannels[1][channel+i].data = p; @@ -541,13 +547,13 @@ void PaUtil_Set2ndInterleavedInputChannels( PaUtilBufferProcessor* bp, } } - + void PaUtil_Set2ndNonInterleavedInputChannel( PaUtilBufferProcessor* bp, unsigned int channel, void *data ) { assert( channel < bp->inputChannelCount ); assert( !bp->hostInputIsInterleaved ); - + bp->hostInputChannels[1][channel].data = data; bp->hostInputChannels[1][channel].stride = 1; } @@ -597,7 +603,7 @@ void PaUtil_SetInterleavedOutputChannels( PaUtilBufferProcessor* bp, assert( firstChannel < bp->outputChannelCount ); assert( firstChannel + channelCount <= bp->outputChannelCount ); assert( bp->hostOutputIsInterleaved ); - + for( i=0; i< channelCount; ++i ) { PaUtil_SetOutputChannel( bp, channel + i, p, channelCount ); @@ -647,7 +653,7 @@ void PaUtil_Set2ndInterleavedOutputChannels( PaUtilBufferProcessor* bp, assert( firstChannel < bp->outputChannelCount ); assert( firstChannel + channelCount <= bp->outputChannelCount ); assert( bp->hostOutputIsInterleaved ); - + for( i=0; i< channelCount; ++i ) { PaUtil_Set2ndOutputChannel( bp, channel + i, p, channelCount ); @@ -655,13 +661,13 @@ void PaUtil_Set2ndInterleavedOutputChannels( PaUtilBufferProcessor* bp, } } - + void PaUtil_Set2ndNonInterleavedOutputChannel( PaUtilBufferProcessor* bp, unsigned int channel, void *data ) { assert( channel < bp->outputChannelCount ); assert( !bp->hostOutputIsInterleaved ); - + PaUtil_Set2ndOutputChannel( bp, channel, data, 1 ); } @@ -673,11 +679,11 @@ void PaUtil_BeginBufferProcessing( PaUtilBufferProcessor* bp, /* the first streamCallback will be called to process samples which are currently in the input buffer before the ones starting at the timeInfo time */ - + bp->timeInfo->inputBufferAdcTime -= bp->framesInTempInputBuffer * bp->samplePeriod; - + /* We just pass through timeInfo->currentTime provided by the caller. This is - not strictly conformant to the word of the spec, since the buffer processor + not strictly conformant to the word of the spec, since the buffer processor might call the callback multiple times, and we never refresh currentTime. */ /* the first streamCallback will be called to generate samples which will be @@ -735,7 +741,7 @@ static unsigned long NonAdaptingProcess( PaUtilBufferProcessor *bp, } else /* there are input channels */ { - + destBytePtr = (unsigned char *)bp->tempInputBuffer; if( bp->userInputIsInterleaved ) @@ -779,7 +785,7 @@ static unsigned long NonAdaptingProcess( PaUtilBufferProcessor *bp, i * bp->bytesPerUserInputSample * frameCount; } } - + userInput = bp->tempInputBufferPtrs; } @@ -795,7 +801,7 @@ static unsigned long NonAdaptingProcess( PaUtilBufferProcessor *bp, } } else - { + { if( skipInputConvert ) { for( i=0; i<bp->inputChannelCount; ++i ) @@ -837,7 +843,7 @@ static unsigned long NonAdaptingProcess( PaUtilBufferProcessor *bp, /* process host buffer directly, or use temp buffer if formats differ or host buffer non-interleaved, * or if num channels differs between the host (set in stride) and the user (eg with some Alsa hw:) */ if( bp->userOutputSampleFormatIsEqualToHost && bp->hostOutputIsInterleaved - && bp->outputChannelCount == hostOutputChannels[0].stride ) + && bp->outputChannelCount == hostOutputChannels[0].stride ) { userOutput = hostOutputChannels[0].data; skipOutputConvert = 1; @@ -869,7 +875,7 @@ static unsigned long NonAdaptingProcess( PaUtilBufferProcessor *bp, userOutput = bp->tempOutputBufferPtrs; } } - + *streamCallbackResult = bp->streamCallback( userInput, userOutput, frameCount, bp->timeInfo, bp->callbackStatusFlags, bp->userData ); @@ -884,50 +890,50 @@ static unsigned long NonAdaptingProcess( PaUtilBufferProcessor *bp, bp->timeInfo->outputBufferDacTime += frameCount * bp->samplePeriod; /* convert output data (user -> host) */ - + if( bp->outputChannelCount != 0 && bp->hostOutputChannels[0][0].data ) { if( skipOutputConvert ) - { - for( i=0; i<bp->outputChannelCount; ++i ) - { - /* advance dest ptr for next iteration */ - hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + - frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; - } - } - else - { - - srcBytePtr = (unsigned char *)bp->tempOutputBuffer; - - if( bp->userOutputIsInterleaved ) - { - srcSampleStrideSamples = bp->outputChannelCount; - srcChannelStrideBytes = bp->bytesPerUserOutputSample; - } - else /* user output is not interleaved */ - { - srcSampleStrideSamples = 1; - srcChannelStrideBytes = frameCount * bp->bytesPerUserOutputSample; - } - - for( i=0; i<bp->outputChannelCount; ++i ) - { - bp->outputConverter( hostOutputChannels[i].data, - hostOutputChannels[i].stride, - srcBytePtr, srcSampleStrideSamples, - frameCount, &bp->ditherGenerator ); - - srcBytePtr += srcChannelStrideBytes; /* skip to next source channel */ - - /* advance dest ptr for next iteration */ - hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + - frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; - } - } + { + for( i=0; i<bp->outputChannelCount; ++i ) + { + /* advance dest ptr for next iteration */ + hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + + frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; + } + } + else + { + + srcBytePtr = (unsigned char *)bp->tempOutputBuffer; + + if( bp->userOutputIsInterleaved ) + { + srcSampleStrideSamples = bp->outputChannelCount; + srcChannelStrideBytes = bp->bytesPerUserOutputSample; + } + else /* user output is not interleaved */ + { + srcSampleStrideSamples = 1; + srcChannelStrideBytes = frameCount * bp->bytesPerUserOutputSample; + } + + for( i=0; i<bp->outputChannelCount; ++i ) + { + bp->outputConverter( hostOutputChannels[i].data, + hostOutputChannels[i].stride, + srcBytePtr, srcSampleStrideSamples, + frameCount, &bp->ditherGenerator ); + + srcBytePtr += srcChannelStrideBytes; /* skip to next source channel */ + + /* advance dest ptr for next iteration */ + hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + + frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; + } + } } - + framesProcessed += frameCount; framesToGo -= frameCount; @@ -982,7 +988,7 @@ static unsigned long AdaptingInputOnlyProcess( PaUtilBufferProcessor *bp, unsigned long frameCount; unsigned long framesToGo = framesToProcess; unsigned long framesProcessed = 0; - + userOutput = 0; do @@ -998,7 +1004,7 @@ static unsigned long AdaptingInputOnlyProcess( PaUtilBufferProcessor *bp, destBytePtr = ((unsigned char*)bp->tempInputBuffer) + bp->bytesPerUserInputSample * bp->inputChannelCount * bp->framesInTempInputBuffer; - + destSampleStrideSamples = bp->inputChannelCount; destChannelStrideBytes = bp->bytesPerUserInputSample; @@ -1018,7 +1024,7 @@ static unsigned long AdaptingInputOnlyProcess( PaUtilBufferProcessor *bp, bp->tempInputBufferPtrs[i] = ((unsigned char*)bp->tempInputBuffer) + i * bp->bytesPerUserInputSample * bp->framesPerUserBuffer; } - + userInput = bp->tempInputBufferPtrs; } @@ -1058,7 +1064,7 @@ static unsigned long AdaptingInputOnlyProcess( PaUtilBufferProcessor *bp, bp->timeInfo->inputBufferAdcTime += bp->framesPerUserBuffer * bp->samplePeriod; } - + bp->framesInTempInputBuffer = 0; } @@ -1113,7 +1119,7 @@ static unsigned long AdaptingOutputOnlyProcess( PaUtilBufferProcessor *bp, } bp->timeInfo->inputBufferAdcTime = 0; - + *streamCallbackResult = bp->streamCallback( userInput, userOutput, bp->framesPerUserBuffer, bp->timeInfo, bp->callbackStatusFlags, bp->userData ); @@ -1150,7 +1156,7 @@ static unsigned long AdaptingOutputOnlyProcess( PaUtilBufferProcessor *bp, srcBytePtr = ((unsigned char*)bp->tempOutputBuffer) + bp->bytesPerUserOutputSample * (bp->framesPerUserBuffer - bp->framesInTempOutputBuffer); - + srcSampleStrideSamples = 1; srcChannelStrideBytes = bp->framesPerUserBuffer * bp->bytesPerUserOutputSample; } @@ -1191,9 +1197,9 @@ static unsigned long AdaptingOutputOnlyProcess( PaUtilBufferProcessor *bp, frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; } } - + framesProcessed += frameCount; - + framesToGo -= frameCount; }while( framesToGo > 0 ); @@ -1202,8 +1208,8 @@ static unsigned long AdaptingOutputOnlyProcess( PaUtilBufferProcessor *bp, } /* CopyTempOutputBuffersToHostOutputBuffers is called from AdaptingProcess to copy frames from - tempOutputBuffer to hostOutputChannels. This includes data conversion - and interleaving. + tempOutputBuffer to hostOutputChannels. This includes data conversion + and interleaving. */ static void CopyTempOutputBuffersToHostOutputBuffers( PaUtilBufferProcessor *bp) { @@ -1215,65 +1221,65 @@ static void CopyTempOutputBuffersToHostOutputBuffers( PaUtilBufferProcessor *bp) unsigned int srcChannelStrideBytes; /* stride from one channel to the next, in bytes */ unsigned int i; - /* copy frames from user to host output buffers */ - while( bp->framesInTempOutputBuffer > 0 && - ((bp->hostOutputFrameCount[0] + bp->hostOutputFrameCount[1]) > 0) ) - { - maxFramesToCopy = bp->framesInTempOutputBuffer; - - /* select the output buffer set (1st or 2nd) */ - if( bp->hostOutputFrameCount[0] > 0 ) - { - hostOutputChannels = bp->hostOutputChannels[0]; - frameCount = PA_MIN_( bp->hostOutputFrameCount[0], maxFramesToCopy ); - } - else - { - hostOutputChannels = bp->hostOutputChannels[1]; - frameCount = PA_MIN_( bp->hostOutputFrameCount[1], maxFramesToCopy ); - } - - if( bp->userOutputIsInterleaved ) - { - srcBytePtr = ((unsigned char*)bp->tempOutputBuffer) + - bp->bytesPerUserOutputSample * bp->outputChannelCount * - (bp->framesPerUserBuffer - bp->framesInTempOutputBuffer); - - srcSampleStrideSamples = bp->outputChannelCount; - srcChannelStrideBytes = bp->bytesPerUserOutputSample; - } - else /* user output is not interleaved */ - { - srcBytePtr = ((unsigned char*)bp->tempOutputBuffer) + - bp->bytesPerUserOutputSample * - (bp->framesPerUserBuffer - bp->framesInTempOutputBuffer); - - srcSampleStrideSamples = 1; - srcChannelStrideBytes = bp->framesPerUserBuffer * bp->bytesPerUserOutputSample; - } - - for( i=0; i<bp->outputChannelCount; ++i ) - { - assert( hostOutputChannels[i].data != NULL ); - bp->outputConverter( hostOutputChannels[i].data, - hostOutputChannels[i].stride, - srcBytePtr, srcSampleStrideSamples, - frameCount, &bp->ditherGenerator ); - - srcBytePtr += srcChannelStrideBytes; /* skip to next source channel */ - - /* advance dest ptr for next iteration */ - hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + - frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; - } - - if( bp->hostOutputFrameCount[0] > 0 ) - bp->hostOutputFrameCount[0] -= frameCount; - else - bp->hostOutputFrameCount[1] -= frameCount; - - bp->framesInTempOutputBuffer -= frameCount; - } + /* copy frames from user to host output buffers */ + while( bp->framesInTempOutputBuffer > 0 && + ((bp->hostOutputFrameCount[0] + bp->hostOutputFrameCount[1]) > 0) ) + { + maxFramesToCopy = bp->framesInTempOutputBuffer; + + /* select the output buffer set (1st or 2nd) */ + if( bp->hostOutputFrameCount[0] > 0 ) + { + hostOutputChannels = bp->hostOutputChannels[0]; + frameCount = PA_MIN_( bp->hostOutputFrameCount[0], maxFramesToCopy ); + } + else + { + hostOutputChannels = bp->hostOutputChannels[1]; + frameCount = PA_MIN_( bp->hostOutputFrameCount[1], maxFramesToCopy ); + } + + if( bp->userOutputIsInterleaved ) + { + srcBytePtr = ((unsigned char*)bp->tempOutputBuffer) + + bp->bytesPerUserOutputSample * bp->outputChannelCount * + (bp->framesPerUserBuffer - bp->framesInTempOutputBuffer); + + srcSampleStrideSamples = bp->outputChannelCount; + srcChannelStrideBytes = bp->bytesPerUserOutputSample; + } + else /* user output is not interleaved */ + { + srcBytePtr = ((unsigned char*)bp->tempOutputBuffer) + + bp->bytesPerUserOutputSample * + (bp->framesPerUserBuffer - bp->framesInTempOutputBuffer); + + srcSampleStrideSamples = 1; + srcChannelStrideBytes = bp->framesPerUserBuffer * bp->bytesPerUserOutputSample; + } + + for( i=0; i<bp->outputChannelCount; ++i ) + { + assert( hostOutputChannels[i].data != NULL ); + bp->outputConverter( hostOutputChannels[i].data, + hostOutputChannels[i].stride, + srcBytePtr, srcSampleStrideSamples, + frameCount, &bp->ditherGenerator ); + + srcBytePtr += srcChannelStrideBytes; /* skip to next source channel */ + + /* advance dest ptr for next iteration */ + hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + + frameCount * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; + } + + if( bp->hostOutputFrameCount[0] > 0 ) + bp->hostOutputFrameCount[0] -= frameCount; + else + bp->hostOutputFrameCount[1] -= frameCount; + + bp->framesInTempOutputBuffer -= frameCount; + } } /* @@ -1300,7 +1306,7 @@ static unsigned long AdaptingProcess( PaUtilBufferProcessor *bp, unsigned int destSampleStrideSamples; /* stride from one sample to the next within a channel, in samples */ unsigned int destChannelStrideBytes; /* stride from one channel to the next, in bytes */ unsigned int i, j; - + framesAvailable = bp->hostInputFrameCount[0] + bp->hostInputFrameCount[1];/* this is assumed to be the same as the output buffer's frame count */ @@ -1310,9 +1316,9 @@ static unsigned long AdaptingProcess( PaUtilBufferProcessor *bp, endProcessingMinFrameCount = (bp->framesPerUserBuffer - 1); /* Fill host output with remaining frames in user output (tempOutputBuffer) */ - CopyTempOutputBuffersToHostOutputBuffers( bp ); + CopyTempOutputBuffersToHostOutputBuffers( bp ); - while( framesAvailable > endProcessingMinFrameCount ) + while( framesAvailable > endProcessingMinFrameCount ) { if( bp->framesInTempOutputBuffer == 0 && *streamCallbackResult != paContinue ) @@ -1326,7 +1332,7 @@ static unsigned long AdaptingProcess( PaUtilBufferProcessor *bp, if( frameCount > 0 ) { hostOutputChannels = bp->hostOutputChannels[i]; - + for( j=0; j<bp->outputChannelCount; ++j ) { bp->outputZeroer( hostOutputChannels[j].data, @@ -1340,7 +1346,7 @@ static unsigned long AdaptingProcess( PaUtilBufferProcessor *bp, bp->hostOutputFrameCount[i] = 0; } } - } + } /* copy frames from host to user input buffers */ @@ -1398,7 +1404,7 @@ static unsigned long AdaptingProcess( PaUtilBufferProcessor *bp, bp->hostInputFrameCount[0] -= frameCount; else bp->hostInputFrameCount[1] -= frameCount; - + bp->framesInTempInputBuffer += frameCount; /* update framesAvailable and framesProcessed based on input consumed @@ -1470,13 +1476,13 @@ static unsigned long AdaptingProcess( PaUtilBufferProcessor *bp, } } - /* copy frames from user (tempOutputBuffer) to host output buffers (hostOutputChannels) + /* copy frames from user (tempOutputBuffer) to host output buffers (hostOutputChannels) Means to process the user output provided by the callback. Has to be called after each callback. */ - CopyTempOutputBuffersToHostOutputBuffers( bp ); + CopyTempOutputBuffersToHostOutputBuffers( bp ); } - + return framesProcessed; } @@ -1485,7 +1491,7 @@ unsigned long PaUtil_EndBufferProcessing( PaUtilBufferProcessor* bp, int *stream { unsigned long framesToProcess, framesToGo; unsigned long framesProcessed = 0; - + if( bp->inputChannelCount != 0 && bp->outputChannelCount != 0 && bp->hostInputChannels[0][0].data /* input was supplied (see PaUtil_SetNoInput) */ && bp->hostOutputChannels[0][0].data /* output was supplied (see PaUtil_SetNoOutput) */ ) @@ -1560,17 +1566,17 @@ unsigned long PaUtil_EndBufferProcessing( PaUtilBufferProcessor* bp, int *stream *hostOutputFrameCount ); assert( framesToProcess != 0 ); - + framesProcessedThisIteration = NonAdaptingProcess( bp, streamCallbackResult, hostInputChannels, hostOutputChannels, - framesToProcess ); + framesToProcess ); *hostInputFrameCount -= framesProcessedThisIteration; *hostOutputFrameCount -= framesProcessedThisIteration; framesProcessed += framesProcessedThisIteration; framesToGo -= framesProcessedThisIteration; - + }while( framesToGo > 0 ); } else @@ -1587,7 +1593,7 @@ unsigned long PaUtil_EndBufferProcessing( PaUtilBufferProcessor* bp, int *stream framesToProcess ); /* process second buffer if provided */ - + framesToProcess = (bp->inputChannelCount != 0) ? bp->hostInputFrameCount[1] : bp->hostOutputFrameCount[1]; @@ -1605,7 +1611,7 @@ unsigned long PaUtil_EndBufferProcessing( PaUtilBufferProcessor* bp, int *stream if( bp->inputChannelCount != 0 && bp->outputChannelCount != 0 ) { /* full duplex */ - + if( bp->hostBufferSizeMode == paUtilVariableHostBufferSizePartialUsageAllowed ) { framesProcessed = AdaptingProcess( bp, streamCallbackResult, @@ -1656,7 +1662,7 @@ unsigned long PaUtil_EndBufferProcessing( PaUtilBufferProcessor* bp, int *stream int PaUtil_IsBufferProcessorOutputEmpty( PaUtilBufferProcessor* bp ) { return (bp->framesInTempOutputBuffer) ? 0 : 1; -} +} unsigned long PaUtil_CopyInput( PaUtilBufferProcessor* bp, @@ -1676,7 +1682,7 @@ unsigned long PaUtil_CopyInput( PaUtilBufferProcessor* bp, if( bp->userInputIsInterleaved ) { destBytePtr = (unsigned char*)*buffer; - + destSampleStrideSamples = bp->inputChannelCount; destChannelStrideBytes = bp->bytesPerUserInputSample; @@ -1701,11 +1707,11 @@ unsigned long PaUtil_CopyInput( PaUtilBufferProcessor* bp, else { /* user input is not interleaved */ - + nonInterleavedDestPtrs = (void**)*buffer; destSampleStrideSamples = 1; - + for( i=0; i<bp->inputChannelCount; ++i ) { destBytePtr = (unsigned char*)nonInterleavedDestPtrs[i]; @@ -1718,7 +1724,7 @@ unsigned long PaUtil_CopyInput( PaUtilBufferProcessor* bp, /* advance callers dest pointer (nonInterleavedDestPtrs[i]) */ destBytePtr += bp->bytesPerUserInputSample * framesToCopy; nonInterleavedDestPtrs[i] = destBytePtr; - + /* advance source ptr for next iteration */ hostInputChannels[i].data = ((unsigned char*)hostInputChannels[i].data) + framesToCopy * hostInputChannels[i].stride * bp->bytesPerHostInputSample; @@ -1726,7 +1732,7 @@ unsigned long PaUtil_CopyInput( PaUtilBufferProcessor* bp, } bp->hostInputFrameCount[0] -= framesToCopy; - + return framesToCopy; } @@ -1747,7 +1753,7 @@ unsigned long PaUtil_CopyOutput( PaUtilBufferProcessor* bp, if( bp->userOutputIsInterleaved ) { srcBytePtr = (unsigned char*)*buffer; - + srcSampleStrideSamples = bp->outputChannelCount; srcChannelStrideBytes = bp->bytesPerUserOutputSample; @@ -1773,15 +1779,15 @@ unsigned long PaUtil_CopyOutput( PaUtilBufferProcessor* bp, else { /* user output is not interleaved */ - + nonInterleavedSrcPtrs = (void**)*buffer; srcSampleStrideSamples = 1; - + for( i=0; i<bp->outputChannelCount; ++i ) { srcBytePtr = (unsigned char*)nonInterleavedSrcPtrs[i]; - + bp->outputConverter( hostOutputChannels[i].data, hostOutputChannels[i].stride, srcBytePtr, srcSampleStrideSamples, @@ -1791,7 +1797,7 @@ unsigned long PaUtil_CopyOutput( PaUtilBufferProcessor* bp, /* advance callers source pointer (nonInterleavedSrcPtrs[i]) */ srcBytePtr += bp->bytesPerUserOutputSample * framesToCopy; nonInterleavedSrcPtrs[i] = srcBytePtr; - + /* advance dest ptr for next iteration */ hostOutputChannels[i].data = ((unsigned char*)hostOutputChannels[i].data) + framesToCopy * hostOutputChannels[i].stride * bp->bytesPerHostOutputSample; @@ -1799,7 +1805,7 @@ unsigned long PaUtil_CopyOutput( PaUtilBufferProcessor* bp, } bp->hostOutputFrameCount[0] += framesToCopy; - + return framesToCopy; } @@ -1826,6 +1832,6 @@ unsigned long PaUtil_ZeroOutput( PaUtilBufferProcessor* bp, unsigned long frameC } bp->hostOutputFrameCount[0] += framesToZero; - + return framesToZero; } |