QMediaDevices audio outputs have wrong sample rates
Solved
Qt 6
-
I'm trying to play some audio on output devices. Since I was getting some errors with format I printed all devices preferred foramt and found out that they accept a sample rate less than showed in system info.
Here system info default audio output:
Here what Qt6.3 says about preferred format:
This is sample code I used to create audio output:
QAudioOutput *audioOutput = new QAudioOutput(QMediaDevices::defaultAudioOutput()); for (QAudioDevice a : QMediaDevices::audioOutputs()) { QAudioFormat t = audioOutput->device().preferredFormat(); qDebug() << a.description() << t.channelCount() << t.sampleRate() << t.sampleFormat(); } QAudioSink* testAudio = new QAudioSink(audioOutput->device().preferredFormat(), baseWidget); QIODevice* audioDevice = testAudio->start();
This leads to an incorrect playback of input file (a little bit "slowed" since his sample rate is 48000)
-
Hi,
The preferred format is one thing, why not set the one that you actually want ?