Results 1 to 5 of 5

Thread: 'Pop' at start of sound playback using QAudioOutput

  1. #1
    Join Date
    Sep 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default 'Pop' at start of sound playback using QAudioOutput

    I'm having an issue playing a simple 'wav' file using QAudioOutput. Previously I used the QSound::PlaySound() to play the same wav and it worked fine, however I wanted a bit more control (mainly stop, pause, resume). However when I play the sound (any wav file) using QAudioOutput I get a 'pop' noise at the start of every sound. This did not occur with the QSound::PlaySound().

    I've tried tweaking the QAudioFormat, but no luck there. I did basically just copy the code from the QAudioOutput help documents, with the exception that I determine the QAudioFormat by the WAV file's header. Note that I've also tested setting the QAudioFormat manually so I'm fairly confident the error is not there.

    So basically when I want to play my wav file, I create a new SoundPlayer object, passing it the filename as a QString. The sound is played once the object is constructed.

    SoundPlayer Constructor

    Qt Code:
    1. SoundPlayer::SoundPlayer(QString fileName, QWidget *parent) :
    2. QWidget(parent)
    3. {
    4. this->inputFile.setFileName(fileName);
    5. this->inputFile.open(QIODevice::ReadOnly);
    6.  
    7. QAudioFormat format = getWaveFormat(fileName);
    8. format.setCodec("audio/pcm");
    9.  
    10. this->audio = new QAudioOutput(format, this);
    11.  
    12. connect(audio, SIGNAL(stateChanged(QAudio::State)), SLOT(finishedPlaying(QAudio::State)));
    13.  
    14. //play the sound file 'inputFile'
    15. audio->start(&inputFile);
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 'Pop' at start of sound playback using QAudioOutput

    Well once again with this forum I find myself having to answer my own question. Anyway after finally going back to look at this problem again I realized my previous mistake. I was reading the header of the sound file to get the format, that part was correct. However once I passed the QFile onto QAudioOutput I was starting at byte 0. So it was trying to interpret all the header data as sound samples, hence the 'pop'. Anyway the actual 'DATA' starts a bit after the header, so in the constructor I now seek ahead to the data marker 'data' and then skip over the next 4 bytes after that (the subchuck2 size info). And voila, no more popping!

  3. #3
    Join Date
    Nov 2013
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: 'Pop' at start of sound playback using QAudioOutput

    Hi semajnosnibor. I'm having the same issue with the 'pop' sound. I'm not that experienced with Qt, so do you still have the code to share it? just the part where you modifies the constructor to seek the data marker. This will be very helpful for me.

    Thanks!

  4. #4
    Join Date
    Sep 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 'Pop' at start of sound playback using QAudioOutput

    Took some digging but I found it. Hopefully this works for you. The modification was actually within the 'getWaveFormat' function. It basically reads all the necessary format info from the wave file header, and then sets the play start position of the file.
    Basically when you want to play the file, create a new object of SoundPlayer with the filename as an argument. The sound will play automatically, and should emit the signal 'soundDone()' when done.

    ex:
    Qt Code:
    1. SoundPlayer *sPlay = new SoundPlayer(fName, this); //sound will start playing automatically
    2. connect(sPlay, SIGNAL(soundDone()), SLOT(soundDone())); //delete the sPlay object when done
    To copy to clipboard, switch view to plain text mode 

    Probably the SoundPlayer code could be optimized quite a bit. I only focussed on getting it working, then when I did I happened to move on to another project (typical!).

    Cheers,
    James
    Attached Files Attached Files

  5. #5
    Join Date
    Jun 2014
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: 'Pop' at start of sound playback using QAudioOutput

    Hello. Can you upload the math.h/.cpp too? Thank you a lot!!

Similar Threads

  1. STB Video Playback
    By akhilesh_s in forum Qt for Embedded and Mobile
    Replies: 6
    Last Post: 19th July 2011, 12:50
  2. How to playback a IP cam?
    By rayner in forum General Programming
    Replies: 3
    Last Post: 6th December 2010, 22:52
  3. Multiple wav playback
    By cueMan in forum Qt Programming
    Replies: 2
    Last Post: 14th September 2010, 16:51
  4. QAudioOutput help
    By XavierQT in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2010, 11:35
  5. MP3 Sound / OGG Sound Play on GUI
    By patrik08 in forum Newbie
    Replies: 3
    Last Post: 1st September 2006, 20:01

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.