开发者

Play a sound immediately with QT Phonon (not waiting for event loop)

I am playing sound for user interactions in C++ using QT's Phonon component. After a lot of testing I can confirm that a queued sound will only start playing when the main thread returns to the main message loop. For long processing code this introduces a delay in sound playback. I need to find a way to avoid that delay.

I've tried doing the sound in a separate thread, but a defect in Phonon prevents some of the objects from being created in that thread. Thus some signals are always s开发者_如何转开发tuck in the main thread.

Simply returning to the event loop quickly is not an option for a few reasons:

  1. Some object creations is simply slow and can't be sped up or easily done in a thread (like database connections)
  2. Phonon uses multiple signals, so even if you return quickly other signals/events will nonetheless block/interfere with the phonon signals

I'm just looking to cover the most basic use case for a sound API: play a sound when a user does something (like click a button) and have that sound play immediately. Surely that must be covered somehow in Phonon?


I haven't looked if phonon in qt 4.7 has been improved but I considered using it for a similar purpose (in qt 4.6) and rejected it because it could not play/mix two sounds at the same time. I did not even get to any run time testing. I went with SDL Audio, specifically SDL Mixer it has low latency on playing and you can play multiple sounds at the same time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜