getting float array from QAudioInput's qbytearray

543 views Asked by At

When reading low level audio from QAudioInput, the resulting data is a QByteArray. When setting up QAudioInput, you can tell it the Sample Type you want from the data. If you specify float there, does that mean the data in QByteArray is already in this format? If it is, do you simply cast the output data to read the float array? If it isn't how is it being stored to get the expected floats out?

1

There are 1 answers

0
dtech On

All computer memory is individual bytes, but you can store in those bytes whatever you want. Do not mistake QByteArray for a QVector<char>, QByteArray is Qt's "generic memory buffer" class.

If the recording format is a float, then simply read floats from the byte array, no need to convert, in fact it will give you more samples than you have since floats are bigger than a byte, and you will get garbage.

You can directly get access to the byte array data pointer and read size() / sizeof(float) floats from it.