Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/hostapi/dsound/pa_win_ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ static HRESULT InitOutputBuffer( PaWinDsStream *stream, PaWinDsDeviceInfo *devic

static void CalculateBufferSettings( unsigned long *hostBufferSizeFrames,
unsigned long *pollingPeriodFrames,
int isFullDuplex,
int hasInput, int hasOutput,
unsigned long suggestedInputLatencyFrames,
unsigned long suggestedOutputLatencyFrames,
double sampleRate, unsigned long userFramesPerBuffer )
Expand Down Expand Up @@ -1753,7 +1753,7 @@ static void CalculateBufferSettings( unsigned long *hostBufferSizeFrames,
else
{
unsigned long targetBufferingLatencyFrames = suggestedInputLatencyFrames;
if( isFullDuplex )
if( hasInput && hasOutput )
{
/* In full duplex streams we know that the buffer adapter adds userFramesPerBuffer
extra fixed latency. so we subtract it here as a fixed latency before computing
Expand Down Expand Up @@ -1790,6 +1790,21 @@ static void CalculateBufferSettings( unsigned long *hostBufferSizeFrames,
*pollingPeriodFrames = maximumPollingPeriodFrames;
}
}

/* In some (most?) systems, DirectSound has an odd limitation where it always uses
a fixed 31.25 ms granularity for the read cursor, regardless of parameters.
This in turn means that if we allocate an input buffer that is less than 31.25 ms,
the read cursor will stay stuck at zero. See https://github.com/PortAudio/portaudio/issues/775
To work around this problem, ensure that the input host buffer is large enough
for at least two 31.25 ms buffer "halves".

On pre-Vista Windows, we don't do this because DirectSound is implemented very
differently, and is therefore unlikely to suffer from the same issue.
*/
if( hasInput && PaWinUtil_GetOsVersion() >= paOsVersionWindowsVistaServer2008 )
{
*hostBufferSizeFrames = max( *hostBufferSizeFrames, 2 * 0.03125 * sampleRate );
}
}


Expand Down Expand Up @@ -2109,7 +2124,8 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,
else
{
CalculateBufferSettings( (unsigned long*)&stream->hostBufferSizeFrames, &pollingPeriodFrames,
/* isFullDuplex = */ (inputParameters && outputParameters),
/* hasInput = */ !!inputParameters,
/* hasOutput = */ !!outputParameters,
suggestedInputLatencyFrames,
suggestedOutputLatencyFrames,
sampleRate, framesPerBuffer );
Expand Down