I am trying to convert captured audio samples from a USB microphone QAudioDevice. The USB microphone reports that it supports 3 audio formats (QAudioFormat::SampleType::Uint8, QAudioFormat::SampleType::Int16 & QAudioFormat::SampleType::Float) - with a preferred audio format of QAudioFormat::SampleType::Int16.
When I start the capture, I pass a QAudioFormat parameter with QAudioFormat::SampleType::Float - indicating that I want the device to call write on my QIODevice.
// QAudioSource will write audio bytes here in pull mode when
// audio sample data is captured from the microphone
qint64
SourceDevice::writeData(const char* data, qint64 len) {
// handler in main will plot the audio data
Q_EMIT audioAvailable({data, len}, m_format);
return len;
}
In Uint8 and Int16 sample format modes, the range of values is easy and therefore the conversion is straight forward, however when the capture device is opened with the sample format set to float, I am not sure about the corresponding range of float values. I thought these values would range between +1.0f/-1.0f however I am seeing values outside this range. This is on windows so the windows resampler is also involved.
There is a helper method float normalizedSampleValue(const void *sample) const but I am not sure if this method should be used here.