Two tests for not filling a buffer:
if( m_iBufferBytesFilled > m_iWriteAhead ) int iNumBytesEmpty = m_iWriteAhead - m_iBufferBytesFilled; if( iNumBytesEmpty < iChunksize ) The latter, manipulated a bit, is actually: if( m_iBufferBytesFilled+iChunksize >= m_iWriteAhead ) These do almost the same thing. This isn't what was intended. The former checks whether we *want* to write another buffer (based on our preferred writeahead). The latter was meant to check whether it's *possible* to fit another chunk into the buffer. It should check against m_iBufferSize, not m_iWriteAhead. This fixes writeahead: 4096 means "write if we have less than 4096 frames buffered", not "write if writing the new chunk would result in still having less than 4096 frames buffered". This is important on slower devices, like USB headsets.
This commit is contained in:
@@ -544,16 +544,15 @@ bool DSoundBuf::get_output_buf( char **pBuffer, unsigned *pBufferSize, int iChun
|
||||
CheckUnderrun( iCursorStart, iCursorEnd );
|
||||
|
||||
/* If we already have enough bytes written ahead, stop. */
|
||||
if( m_iBufferBytesFilled > m_iWriteAhead )
|
||||
if( m_iBufferBytesFilled >= m_iWriteAhead )
|
||||
return false;
|
||||
|
||||
/* If we don't have enough free space in the buffer to fill a whole chunk, stop. */
|
||||
if( m_iBufferSize - m_iBufferBytesFilled < iChunksize )
|
||||
return false;
|
||||
|
||||
int iNumBytesEmpty = m_iWriteAhead - m_iBufferBytesFilled;
|
||||
|
||||
/* num_bytes_empty is the amount of free buffer space. If it's
|
||||
* too small, come back later. */
|
||||
if( iNumBytesEmpty < iChunksize )
|
||||
return false;
|
||||
|
||||
// LOG->Trace("gave %i at %i (%i, %i) %i filled", iNumBytesEmpty, m_iWriteCursor, cursor, write, m_iBufferBytesFilled);
|
||||
|
||||
/* Lock the audio buffer. */
|
||||
|
||||
Reference in New Issue
Block a user