Commit 8143fe31 authored by rossb's avatar rossb

CoreAudio: if user specifies framesPerBuffer make sure host buffer is an...

CoreAudio: if user specifies framesPerBuffer make sure host buffer is an integer multiple of user buffer

git-svn-id: https://subversion.assembla.com/svn/portaudio/portaudio/trunk@1762 0f58301d-fd10-0410-b4af-bbb618454e57
parent be205055
......@@ -1579,7 +1579,7 @@ static UInt32 CalculateOptimalBufferSize( PaMacAUHAL *auhalHostApi,
double sampleRate,
UInt32 requestedFramesPerBuffer )
{
UInt32 suggested = 0;
UInt32 resultBufferSizeFrames = 0;
// Use maximum of suggested input and output latencies.
if( inputParameters )
{
......@@ -1588,28 +1588,25 @@ static UInt32 CalculateOptimalBufferSize( PaMacAUHAL *auhalHostApi,
SInt32 variableLatencyFrames = suggestedLatencyFrames - fixedInputLatency;
// Prevent negative latency.
variableLatencyFrames = MAX( variableLatencyFrames, 0 );
suggested = MAX( suggested, (UInt32) variableLatencyFrames );
resultBufferSizeFrames = MAX( resultBufferSizeFrames, (UInt32) variableLatencyFrames );
}
if( outputParameters )
{
UInt32 suggestedLatencyFrames = outputParameters->suggestedLatency * sampleRate;
SInt32 variableLatencyFrames = suggestedLatencyFrames - fixedOutputLatency;
variableLatencyFrames = MAX( variableLatencyFrames, 0 );
suggested = MAX( suggested, (UInt32) variableLatencyFrames );
resultBufferSizeFrames = MAX( resultBufferSizeFrames, (UInt32) variableLatencyFrames );
}
VDBUG( ("Block Size unspecified. Based on Latency, the user wants a Block Size near: %ld.\n",
suggested ) );
if( requestedFramesPerBuffer != paFramesPerBufferUnspecified )
{
if( suggested > (requestedFramesPerBuffer + 1) )
{
// If the user asks for higher latency than the requested buffer size would provide
// then put multiple user buffers in one host buffer.
UInt32 userBuffersPerHostBuffer = (suggested + (requestedFramesPerBuffer - 1)) / requestedFramesPerBuffer;
suggested = userBuffersPerHostBuffer * requestedFramesPerBuffer;
}
// make host buffer the next highest integer multiple of user frames per buffer
UInt32 n = (resultBufferSizeFrames + requestedFramesPerBuffer - 1) / requestedFramesPerBuffer;
resultBufferSizeFrames = n * requestedFramesPerBuffer;
}else{
VDBUG( ("Block Size unspecified. Based on Latency, the user wants a Block Size near: %ld.\n",
resultBufferSizeFrames ) );
}
// Clip to the capabilities of the device.
......@@ -1617,16 +1614,16 @@ static UInt32 CalculateOptimalBufferSize( PaMacAUHAL *auhalHostApi,
{
ClipToDeviceBufferSize( auhalHostApi->devIds[inputParameters->device],
true, // In the old code isInput was false!
suggested, &suggested );
resultBufferSizeFrames, &resultBufferSizeFrames );
}
if( outputParameters )
{
ClipToDeviceBufferSize( auhalHostApi->devIds[outputParameters->device],
false, suggested, &suggested );
false, resultBufferSizeFrames, &resultBufferSizeFrames );
}
VDBUG(("After querying hardware, setting block size to %ld.\n", suggested));
VDBUG(("After querying hardware, setting block size to %ld.\n", resultBufferSizeFrames));
return suggested;
return resultBufferSizeFrames;
}
/* =================================================================================================== */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment