[Qt-interest] High CPU Usage With QAudioOutput

Justin McPherson justin.mcpherson at nokia.com
Fri Apr 8 03:25:51 CEST 2011


Hi,

On 7/04/11 9:45 PM, ext Barnes, Clifton A. wrote:
>
> class AudioTest : public QObject
> {
>      Q_OBJECT
> public:
>        QFile audioFile;
>        QAudioFormat audioFormat;
>        QAudioOutput *audioOutput;
>
>      AudioTest() :
>           audioFile("/Testfile.wav")
>      {
>          this->audioFormat.setFrequency(16000);
>          this->audioFormat.setChannels(1);
>          this->audioFormat.setSampleSize(16);
>          this->audioFormat.setCodec("audio/x-wav");

The ALSA backend ignores this ("audio/x-wav") as it only supports PCM, 
it should put up a warning. The correct value is "audio/pcm". 
QAudioOutput does not support a container format such as wav.

>          this->audioFormat.setByteOrder(QAudioFormat::LittleEndian);
>          this->audioFormat.setSampleType(QAudioFormat::SignedInt);

It's better to ask after what is supported, rather than assume, see 
QAudioDeviceInfo ::isFormatSupported(), ::preferredFormat(), 
::nearestFormat(), for various format negotiation functions. Some 
devices, particularly on embedded - where you might be, only support a 
limited range of formats.

>
>          this->audioOutput = new QAudioOutput(this->audioFormat);
>          QTimer::singleShot(1000, this, SLOT(playAudio()));
>      }
>
>      ~AudioTest()
>      {
>          delete this->audioOutput;
>      }
>
> public slots:
>      void playAudio()
>      {
>          this->audioFile.open(QFile::ReadOnly);
>          this->audioOutput->start(&this->audioFile);
>          QTimer::singleShot(60000, this, SLOT(exitApplication()));
>      }
>
>      void exitApplication()
>      {
>          QApplication::exit();
>      }
> };
>
> int main(int argc, char *argv[])
> {
>      QApplication a(argc, argv);
>
>      AudioTest audioTest;
>
>      a.exec();
> }
>
> Like you described, there's some noise at the beginning I'm assuming from
> the .wav header, but then it plays fine but with a high CPU usage on my
> ARM platform.

Looks OK to me, there are a few tests that could be done from here, it's 
best to open a bug report, someone will look at it and try and 
understand what is happening.


- Justin


> - Clif




More information about the Qt-interest-old mailing list