[Qt-interest] High CPU Usage With QAudioOutput

Barnes, Clifton A. cabarnes at indesign-llc.com
Thu Apr 7 13:45:50 CEST 2011


On Thursday, April 07, 2011 Justin McPherson wrote:

> It shouldn't. You should file a bug.

> All the comments about .wav etc are true, but probably not related. Most 
> .wav files in the wild have PCM data inside, and apart from odd bursts 
> of noise, should at least "work" when passed directly to QAudioOutput 
> via the start(QIODevice*) method - if you have the correct format set.

> Code to look at would be nice, if you can.

It's just the simple test program below:

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");
        this->audioFormat.setByteOrder(QAudioFormat::LittleEndian);
        this->audioFormat.setSampleType(QAudioFormat::SignedInt);

        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.

- Clif



More information about the Qt-interest-old mailing list