Fix improper calculation of big buffer sizes. See bug #187
This fixes a click heard with big buffers.
This commit is contained in:
parent
3aad8c0a9f
commit
edac3c99eb
3 changed files with 47 additions and 69 deletions
|
|
@ -223,7 +223,7 @@ PaError PaUtil_InitializeBufferProcessor( PaUtilBufferProcessor* bp,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Under the assumption that no ADC in existence delivers better than 24bits resoultion,
|
/* 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. */
|
since the host samples will just be padded with zeros anyway. */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1838,7 +1838,6 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
|
||||||
|
|
||||||
if( outputParameters )
|
if( outputParameters )
|
||||||
{
|
{
|
||||||
|
|
||||||
outputLatencyFrames += PaUtil_GetBufferProcessorOutputLatencyFrames(&stream->bufferProcessor);
|
outputLatencyFrames += PaUtil_GetBufferProcessorOutputLatencyFrames(&stream->bufferProcessor);
|
||||||
stream->streamRepresentation.streamInfo.outputLatency = outputLatencyFrames / sampleRate;
|
stream->streamRepresentation.streamInfo.outputLatency = outputLatencyFrames / sampleRate;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -531,11 +531,12 @@ PaError setBestFramesPerBuffer( const AudioDeviceID device,
|
||||||
Float64 min = -1; /*the min blocksize*/
|
Float64 min = -1; /*the min blocksize*/
|
||||||
Float64 best = -1; /*the best blocksize*/
|
Float64 best = -1; /*the best blocksize*/
|
||||||
int i=0;
|
int i=0;
|
||||||
AudioValueRange *ranges;
|
AudioValueRange range;
|
||||||
|
|
||||||
if( actualFramesPerBuffer == NULL )
|
if( actualFramesPerBuffer == NULL )
|
||||||
|
{
|
||||||
actualFramesPerBuffer = &afpb;
|
actualFramesPerBuffer = &afpb;
|
||||||
|
}
|
||||||
|
|
||||||
/* -- try and set exact FPB -- */
|
/* -- try and set exact FPB -- */
|
||||||
err = AudioDeviceSetProperty( device, NULL, 0, isInput,
|
err = AudioDeviceSetProperty( device, NULL, 0, isInput,
|
||||||
|
|
@ -545,63 +546,41 @@ PaError setBestFramesPerBuffer( const AudioDeviceID device,
|
||||||
kAudioDevicePropertyBufferFrameSize,
|
kAudioDevicePropertyBufferFrameSize,
|
||||||
&propsize, actualFramesPerBuffer);
|
&propsize, actualFramesPerBuffer);
|
||||||
if( err )
|
if( err )
|
||||||
|
{
|
||||||
return ERR( err );
|
return ERR( err );
|
||||||
|
}
|
||||||
|
// Did we get the size we asked for?
|
||||||
if( *actualFramesPerBuffer == requestedFramesPerBuffer )
|
if( *actualFramesPerBuffer == requestedFramesPerBuffer )
|
||||||
|
{
|
||||||
return paNoError; /* we are done */
|
return paNoError; /* we are done */
|
||||||
|
}
|
||||||
|
|
||||||
/* -- fetch available block sizes -- */
|
// Clip requested value against legal range for the device.
|
||||||
err = AudioDeviceGetPropertyInfo( device, 0, isInput,
|
propsize = sizeof(AudioValueRange);
|
||||||
kAudioDevicePropertyBufferSizeRange,
|
|
||||||
&propsize, NULL );
|
|
||||||
if( err )
|
|
||||||
return ERR( err );
|
|
||||||
ranges = (AudioValueRange *)calloc( 1, propsize );
|
|
||||||
if( !ranges )
|
|
||||||
return paInsufficientMemory;
|
|
||||||
err = AudioDeviceGetProperty( device, 0, isInput,
|
err = AudioDeviceGetProperty( device, 0, isInput,
|
||||||
kAudioDevicePropertyBufferSizeRange,
|
kAudioDevicePropertyBufferFrameSizeRange,
|
||||||
&propsize, ranges );
|
&propsize, &range );
|
||||||
if( err )
|
if( err )
|
||||||
{
|
{
|
||||||
free( ranges );
|
|
||||||
return ERR( err );
|
return ERR( err );
|
||||||
}
|
}
|
||||||
VDBUG(("Requested block size of %lu was not available.\n",
|
if( requestedFramesPerBuffer < range.mMinimum )
|
||||||
requestedFramesPerBuffer ));
|
|
||||||
VDBUG(("%lu Available block sizes are:\n",propsize/sizeof(AudioValueRange)));
|
|
||||||
#ifdef MAC_CORE_VERBOSE_DEBUG
|
|
||||||
for( i=0; i<propsize/sizeof(AudioValueRange); ++i )
|
|
||||||
VDBUG( ("\t%g-%g\n",
|
|
||||||
(float) ranges[i].mMinimum,
|
|
||||||
(float) ranges[i].mMaximum ) );
|
|
||||||
#endif
|
|
||||||
VDBUG(("-----\n"));
|
|
||||||
|
|
||||||
/* --- now pick the best available framesPerBuffer -- */
|
|
||||||
for( i=0; i<propsize/sizeof(AudioValueRange); ++i )
|
|
||||||
{
|
{
|
||||||
if( min == -1 || ranges[i].mMinimum < min ) min = ranges[i].mMinimum;
|
requestedFramesPerBuffer = range.mMinimum;
|
||||||
if( ranges[i].mMaximum < requestedFramesPerBuffer ) {
|
|
||||||
if( best < 0 )
|
|
||||||
best = ranges[i].mMaximum;
|
|
||||||
else if( ranges[i].mMaximum > best )
|
|
||||||
best = ranges[i].mMaximum;
|
|
||||||
}
|
}
|
||||||
|
else if( requestedFramesPerBuffer > range.mMaximum )
|
||||||
|
{
|
||||||
|
requestedFramesPerBuffer = range.mMaximum;
|
||||||
}
|
}
|
||||||
if( best == -1 )
|
|
||||||
best = min;
|
|
||||||
VDBUG( ("Minimum FPB %g. best is %g.\n", min, best ) );
|
|
||||||
free( ranges );
|
|
||||||
|
|
||||||
/* --- set the buffer size (ignore errors) -- */
|
/* --- set the buffer size (ignore errors) -- */
|
||||||
requestedFramesPerBuffer = (UInt32) best ;
|
|
||||||
propsize = sizeof( UInt32 );
|
propsize = sizeof( UInt32 );
|
||||||
err = AudioDeviceSetProperty( device, NULL, 0, isInput,
|
err = AudioDeviceSetProperty( device, NULL, 0, isInput,
|
||||||
kAudioDevicePropertyBufferSize,
|
kAudioDevicePropertyBufferFrameSize,
|
||||||
propsize, &requestedFramesPerBuffer );
|
propsize, &requestedFramesPerBuffer );
|
||||||
/* --- read the property to check that it was set -- */
|
/* --- read the property to check that it was set -- */
|
||||||
err = AudioDeviceGetProperty( device, 0, isInput,
|
err = AudioDeviceGetProperty( device, 0, isInput,
|
||||||
kAudioDevicePropertyBufferSize,
|
kAudioDevicePropertyBufferFrameSize,
|
||||||
&propsize, actualFramesPerBuffer );
|
&propsize, actualFramesPerBuffer );
|
||||||
|
|
||||||
if( err )
|
if( err )
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue