explicit casts for double->int. comment cleanups. fixed an bug where uninited pointer could be freed during teardown if memory allocation failed during directsound host api init (extremely unlikely).

This commit is contained in:
rbencina 2012-04-02 07:45:18 +00:00
commit e2f0932362

View file

@ -480,7 +480,7 @@ static PaError ExpandDSDeviceNameAndGUIDVector( DSDeviceNameAndGUIDVector *guidV
else
{
newItems[i].lpGUID = &newItems[i].guid;
memcpy( &newItems[i].guid, guidVector->items[i].lpGUID, sizeof(GUID) );;
memcpy( &newItems[i].guid, guidVector->items[i].lpGUID, sizeof(GUID) );
}
newItems[i].pnpInterface = guidVector->items[i].pnpInterface;
}
@ -1167,6 +1167,8 @@ PaError PaWinDs_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInde
goto error;
}
memset( winDsHostApi, 0, sizeof(PaWinDsHostApiRepresentation) ); /* ensure all fields are zeroed. especially winDsHostApi->allocations */
result = PaWinUtil_CoInitialize( paDirectSound, &winDsHostApi->comInitializationResult );
if( result != paNoError )
{
@ -1306,7 +1308,7 @@ error:
TerminateDSDeviceNameAndGUIDVector( &deviceNamesAndGUIDs.inputNamesAndGUIDs );
TerminateDSDeviceNameAndGUIDVector( &deviceNamesAndGUIDs.outputNamesAndGUIDs );
Terminate( winDsHostApi );
Terminate( (struct PaUtilHostApiRepresentation *)winDsHostApi );
return result;
}
@ -1703,9 +1705,9 @@ static void CalculateBufferSettings( unsigned long *hostBufferSizeFrames,
unsigned long suggestedOutputLatencyFrames,
double sampleRate, unsigned long userFramesPerBuffer )
{
unsigned long minimumPollingPeriodFrames = sampleRate * PA_DS_MINIMUM_POLLING_PERIOD_SECONDS;
unsigned long maximumPollingPeriodFrames = sampleRate * PA_DS_MAXIMUM_POLLING_PERIOD_SECONDS;
unsigned long pollingJitterFrames = sampleRate * PA_DS_POLLING_JITTER_SECONDS;
unsigned long minimumPollingPeriodFrames = (unsigned long)(sampleRate * PA_DS_MINIMUM_POLLING_PERIOD_SECONDS);
unsigned long maximumPollingPeriodFrames = (unsigned long)(sampleRate * PA_DS_MAXIMUM_POLLING_PERIOD_SECONDS);
unsigned long pollingJitterFrames = (unsigned long)(sampleRate * PA_DS_POLLING_JITTER_SECONDS);
if( userFramesPerBuffer == paFramesPerBufferUnspecified )
{
@ -1771,9 +1773,9 @@ static void CalculatePollingPeriodFrames( unsigned long hostBufferSizeFrames,
unsigned long *pollingPeriodFrames,
double sampleRate, unsigned long userFramesPerBuffer )
{
unsigned long minimumPollingPeriodFrames = sampleRate * PA_DS_MINIMUM_POLLING_PERIOD_SECONDS;
unsigned long maximumPollingPeriodFrames = sampleRate * PA_DS_MAXIMUM_POLLING_PERIOD_SECONDS;
unsigned long pollingJitterFrames = sampleRate * PA_DS_POLLING_JITTER_SECONDS;
unsigned long minimumPollingPeriodFrames = (unsigned long)(sampleRate * PA_DS_MINIMUM_POLLING_PERIOD_SECONDS);
unsigned long maximumPollingPeriodFrames = (unsigned long)(sampleRate * PA_DS_MAXIMUM_POLLING_PERIOD_SECONDS);
unsigned long pollingJitterFrames = (unsigned long)(sampleRate * PA_DS_POLLING_JITTER_SECONDS);
*pollingPeriodFrames = max( max(1, userFramesPerBuffer / 4), hostBufferSizeFrames / 16 );
@ -2471,6 +2473,8 @@ static int TimeSlice( PaWinDsStream *stream )
framesToXfer = numOutFramesReady = bytesEmpty / stream->outputFrameSizeBytes;
/* Check for underflow */
/* FIXME QueryOutputSpace should not adjust underflow count as a side effect.
A query function should be a const operator on the stream and return a flag on underflow. */
if( stream->outputUnderflowCount != previousUnderflowCount )
stream->callbackFlags |= paOutputUnderflow;
@ -2536,7 +2540,7 @@ static int TimeSlice( PaWinDsStream *stream )
{
/*
We don't currently add outputLatency here because it appears to produce worse
results than non adding it. Need to do more testing to verify this.
results than not adding it. Need to do more testing to verify this.
*/
/* timeInfo.outputBufferDacTime = timeInfo.currentTime + outputLatency; */
timeInfo.outputBufferDacTime = timeInfo.currentTime;
@ -2729,7 +2733,7 @@ PA_THREAD_FUNC ProcessingThreadProc( void *pArg )
LARGE_INTEGER dueTime;
int timerPeriodMs;
timerPeriodMs = stream->pollingPeriodSeconds * MSECS_PER_SECOND;
timerPeriodMs = (int)(stream->pollingPeriodSeconds * MSECS_PER_SECOND);
if( timerPeriodMs < 1 )
timerPeriodMs = 1;
@ -2953,7 +2957,7 @@ static PaError StartStream( PaStream *s )
if( stream->streamRepresentation.streamCallback )
{
TIMECAPS timecaps;
int timerPeriodMs = stream->pollingPeriodSeconds * MSECS_PER_SECOND;
int timerPeriodMs = (int)(stream->pollingPeriodSeconds * MSECS_PER_SECOND);
if( timerPeriodMs < 1 )
timerPeriodMs = 1;
@ -2967,7 +2971,7 @@ static PaError StartStream( PaStream *s )
if( timeGetDevCaps( &timecaps, sizeof(TIMECAPS) == MMSYSERR_NOERROR && timecaps.wPeriodMin > 0 ) )
{
/* aim for resolution 4 times higher than polling rate */
stream->systemTimerResolutionPeriodMs = (stream->pollingPeriodSeconds * MSECS_PER_SECOND) / 4;
stream->systemTimerResolutionPeriodMs = (UINT)((stream->pollingPeriodSeconds * MSECS_PER_SECOND) * .25);
if( stream->systemTimerResolutionPeriodMs < timecaps.wPeriodMin )
stream->systemTimerResolutionPeriodMs = timecaps.wPeriodMin;
if( stream->systemTimerResolutionPeriodMs > timecaps.wPeriodMax )