Mac OS X: QIODevice::Read(char *data, qint64 size) reading exactly 1024 bytes
I am trying to record audio into a buffer using QAudioInput as the recorder and a QByteArray as the buffer.
I have setup both very similarly to the spectrum analyzer example (including the initialization of the other objects to support QAudioInput). I use QAudioInput::start() to start the recording and keep a copy of the QIODevice pointer it returns. I connect a slot to the readyRead() signal belonging to the QIODevice. In that slot I call QIODevice::Read(data, size) and pass in my byte array along with the qint64 reported by QAudioInput::bytesReady() (Actually I pass the minimum of remaining in the byte array and the bytes reported by bytesReady()).
On Windows XP, this works perfectly. I can record audio into the buffer (QByteArray), play it back, and hear just what I would expect. However on Mac OSX I've run into three problems:
First, QIODevice::Read( ... ) is only reading exactly 1024 bytes. The audio hardware on the Mac reports having about ~650 bytes ready per readyRead() signal. However, I cannot read any of those bytes until a second or subsequent readyRead() signal has been sent and there are atleast 1024 bytes available to read.
Second, my QByteArray buffer fills up much faster on the Mac than it does on Windows. I've set it to record exactly 5 seconds of audio based on the audio recording format. On Windows it appears to record exactly 5 seconds. However, on Mac it only appears to record about 3 seconds. Note that I haven't timed either of these precisely, just counted one one thousand.
Third, (likely a function of problem #2 which is likely caused by #1) the audio recording on the mac sounds very slow and low pitch when replayed on the Mac. I imagine it is stretching the 3 second recording to 5 seconds. This doesn't happen on Windows.
Is there some sort of setting that needs to be set on Mac but not on Windows? Or is this possibly a bug in the API on Mac?
I can give additional info about this if needed, but I won't be able to actually test anything until tomorrow evening.
I've done some searching on the forums and in the documentation for this, but haven't found anything mentioning it. Forgive me if I overlooked something.
Thanks for any help!
The low pitch problem and the different time needed to fill the buffer seems to indicate you are recording at a higher sample rate on MacOsX than on Windows.
Did you check that the format was supported (like in "the example code from QAudioInput documentation":http://doc.trolltech.com/latest/qaudioinput.html#details), and that the "nearestFormat" returned the same sampleRate as the one you requested ?