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.