There is no direct relationship between QAudioInput::bytesReady()
and the QIODevice
on which it writes its samples.
QAudioInput
supports an internal I / O device (system dependent) to an audio system that is an analog read-only QIODevice
. When you call bytesReady
, it returns the number of bytes available for reading, the analog value of QIODevice::bytesAvailable()
. Those who do not have not yet written to the output of QIODevice
, so when you do m_audioInputIODevice->read
immediately after it, without event processing, you actually get samples that were written earlier, and not those that are still in the sound buffer.
This plus IODevice buffering, explains why numbers can be different, and I donβt see a way to synchronize them.
Actually, you should do:
const qint64 bytesRead = m_audioInputIODevice->read(m_buffer.data() + m_dataLength, bytesSpace);
to get everything that is available in IODevice, up to your available buffer space.
source share