Results 1 to 4 of 4

Thread: Using QAudioOutput to play sounds for a metronome

  1. #1
    Join Date
    Mar 2012
    Posts
    12
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Using QAudioOutput to play sounds for a metronome

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Using QAudioOutput to play sounds for a metronome

    What happens if your call stop() before start() again?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2012
    Posts
    12
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using QAudioOutput to play sounds for a metronome

    Quote Originally Posted by high_flyer View Post
    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.
    Last edited by tcampos; 7th March 2012 at 14:14.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Using QAudioOutput to play sounds for a metronome

    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.

Similar Threads

  1. QAudioOutput Play Audio Buffer chat voice ?
    By Thành Viên Mới in forum Qt Programming
    Replies: 5
    Last Post: 11th May 2011, 19:35
  2. QaudioOutput play buffer audio real time disconnect network ?
    By Thành Viên Mới in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2011, 12:20
  3. [Tab play list]Load play lists on start
    By petrusPL in forum Qt Programming
    Replies: 0
    Last Post: 18th March 2011, 18:12
  4. Replies: 1
    Last Post: 29th July 2010, 13:35
  5. Sounds in Qt
    By Dante in forum Qt Programming
    Replies: 1
    Last Post: 20th April 2009, 14:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.