I am busy making a reverb algorithm. While working with QSound I found a few problems.
First, the sound doesn't play while trying the QSound::play() like this:
/// Play output .wav file.
QSound sound("C:/Users/mvdelft/Documents/Reverb_configurator/output.wav", this);
sound.play();
It only plays the sound if I give the path againt with the QSound::play (QString file) like this:
/// Play output .wav file.
QSound sound("C:/Users/mvdelft/Documents/Reverb_configurator/output.wav", this);
sound.play("C:/Users/mvdelft/Documents/Reverb_configurator/output.wav");
A related problem I have has to do with the function bool QSound::isFinshed() which doesn't work for me. Code:
/// Play output .wav file.
QSound sound("C:/Users/mvdelft/Documents/Reverb_configurator/output.wav", this);
sound.play("C:/Users/mvdelft/Documents/Reverb_configurator/output.wav");
sound.setLoops(10);
/// Check is sound is finished
while (!sound.isFinished()){}
ui->listWidget->addItem("Finished playing sound");
}/// End of scope
In the first version, you create a
QSoundobject on stack with a file, start playing it, and immediately destroy it. This will stop the sound playing, so you won't hear anything.In the second version,
QSound::play(const QString &)is a static method. It will play the sound in the background. That's why you hear something. With the static method, the calls tosetLoopsandisFinishedwill not work. Also, the busy loop (while (!sound.isFinished()) ;) is very bad, as it will consume 100% CPU, and probably block playing the sound.For the sound to work, you should create it on the heap, and regulary check the
isFinished()on a timer event. However, I suggestQSoundEffect, as it gives you more control. Most importantly, theplayingChanged()signal, that will inform you when the playing has finished without the need to constantly check.Outline: