PDA

View Full Version : Using QAudioOutput to play sounds for a metronome



tcampos
7th March 2012, 11:24
Hi there,

Since I want my application resources to be included inside a single .exe file I can't use QSound for playing simple .wav files, because it doesn't support resources.
I tried to use QAudioOuput to play the simple sounds and i managed to do it but I only can play the same QAudioOuput object once. The start() function only works for the first time it is invoked. Any tips about this?

Thanks in advance.
Tiago Campos

high_flyer
7th March 2012, 13:05
What happens if your call stop() before start() again?

tcampos
7th March 2012, 13:59
What happens if your call stop() before start() again?

Calling stop() before start() produces the same result as before.
It seems that I needed to call inputFile->open(QIODevice::ReadOnly) before every single audio->start(inputFile). Isn't this supposed to be a bug of the library? I wasn't calling inputFile->close() at any moment. Now I can manage to call start() sucessfully using a simple timer in the main thread.

Now I have another issue. Running audio->start(inputFile) inside the execution of a QThread, many of the metronome beats are not played while others are. There seems to exist no pattern between the events... Any idea?

It's important to state that using a QSound object the sounds played without any problems inside the QThread.

d_stranz
8th March 2012, 19:57
QTimer relies on the event loop, so if your application is busy doing something else that also generates a lot of events, the execution of the timer's timeout signal may be delayed. If QAudioOutput works in such a way that two start events are triggered in quick succession, the first one might be ignored. Same way paint events work, possibly.

Since a metronome obviously needs high precision in sounding its beats, you may need to set the priority of the metronome thread to be higher than normal so that it gets better service than the GUI thread.