I am using Qt Multimedia 5 to analyze audio (FFT, LUFS, and dBFS, etc.) from audio input device. To get audio data, there are two main options, QAudioRecorder and QAudioInput. They can all read audio data with PCM (QAudioInput use QBuffer and QAudioRecorder use QAudioBuffer) and set format (e.g., sample rate), what should I use? I want to know the difference between QAudioRecorder and QAudioInput.
Asked
Active
Viewed 844 times
2
-
Is this about Qt 5 or Qt 6? Add relevant version tags please. The multimedia interface has been cleaned up in Qt 6 so the differences are important. – Kuba hasn't forgotten Monica Sep 20 '21 at 13:23
-
Qt 5. Modified in the post. – Creepercdn Sep 20 '21 at 14:24
1 Answers
3
QAudioBuffer
is very convenient, and you'd use the QAudioProbe
class to get notified whenever a new buffer is available - in Qt 5. QAudioProbe
is not supported on Mac OS unfortunately.
QAudioProbe
doesn't exist in Qt 6, and wasn't fully supported in Qt 5 either.
The only way to access "live" raw audio data in both Qt 5 and Qt 6 with minimal latency is by making your own QIODevice
and being fed data from QAudioSource
in push mode - see the Audio Source example, specifically the AudioInfo
class.
The process is as follows:
- Create an instance of your io device.
- Pass it to
QAudioSource::start(QIODevice*)
. The audio source will be writing raw data to the device you provided. - In the device's implementation, you can either work on the data directly, or synthesize a
QAudioBuffer
instance and send it out in a signal.
Something like the following would work:
class AudioProbeDevice : public QIODevice
{
Q_OBJECT
QAudioFormat m_format;
public:
AudioProbeDevice (QObject* parent = {}) : QIODevice(parent) {}
void start(QAudioInput *source)
{
Q_ASSERT(source);
m_format = source->format();
open(QIODevice::WriteOnly);
}
qint64 readData(char *, qint64) override { return 0; }
qint64 writeData(const char *data, qint64 count) override
{
QAudioBuffer buffer({data, static_cast<int>(count)}, m_format);
emit audioAvailable(buffer);
return count;
}
Q_SIGNAL void audioAvailable(const QAudioBuffer &buffer);
};

Mr. Developerdude
- 9,118
- 10
- 57
- 95

Kuba hasn't forgotten Monica
- 95,931
- 16
- 151
- 313
-
-
@JeremyFriesner ??? It's basically "trust the source, Luke" at the moment. The multimedia module is in flux, and the design overall is just weird, so I'm not even sure it's worth using it anymore. There are better audio frameworks out there, much easier to use. That's one side of Qt that got underfunded I'd say, and it's been that way over a decade. – Kuba hasn't forgotten Monica Sep 24 '21 at 17:41