Results 1 to 4 of 4

Thread: Only buzzing sound while playing wav/mp3 files through QAudioOutput

  1. #1
    Join Date
    Apr 2011
    Posts
    216
    Thanks
    136
    Thanked 6 Times in 5 Posts

    Default Only buzzing sound while playing wav/mp3 files through QAudioOutput

    Using Qt 5.5.1 on a Windows 7 desktop and a laptop.

    I have tried the following program with mp3, wav, flac files. I can only hear the buzzing sound, nothing else. Please guide.

    The reproducable example:

    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QAudioOutput>
    3. #include <QFile>
    4. #include <QDebug>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication a(argc, argv);
    9.  
    10. QAudioOutput* audioOutpu;
    11.  
    12. QFile sourceFile;
    13. sourceFile.setFileName("c.wav");
    14. bool p = sourceFile.open(QIODevice::ReadOnly);
    15. if (p == false)
    16. qDebug() << "no file";
    17. else
    18. qDebug() << "yes file";
    19.  
    20.  
    21. QAudioDeviceInfo d1;
    22. QList<QAudioDeviceInfo> l1 = d1.availableDevices(QAudio::AudioOutput);
    23.  
    24. qDebug() << "======================================================";
    25. qDebug() << l1.first().supportedCodecs();
    26. qDebug() << l1.first().supportedChannelCounts();
    27. qDebug() << l1.first().supportedSampleTypes();
    28. qDebug() << l1.first().supportedSampleRates();
    29. qDebug() << l1.first().supportedSampleSizes();
    30.  
    31. QAudioFormat desiredFormat1;
    32. desiredFormat1.setChannelCount(2);
    33. desiredFormat1.setByteOrder(QAudioFormat::LittleEndian);
    34. desiredFormat1.setCodec("audio/pcm");
    35. desiredFormat1.setSampleType(QAudioFormat::SignedInt);
    36. desiredFormat1.setSampleRate(44100);
    37. desiredFormat1.setSampleSize(16);
    38.  
    39. QAudioDeviceInfo info1(QAudioDeviceInfo::defaultOutputDevice());
    40. if (!info1.isFormatSupported(desiredFormat1))
    41. {
    42. qWarning() << "Default format not supported, trying to use the nearest.";
    43. desiredFormat1 = info1.preferredFormat();
    44. }
    45.  
    46. audioOutpu = new QAudioOutput(desiredFormat1);
    47. audioOutpu->setVolume(1.0);
    48.  
    49. audioOutpu->start(&sourceFile);
    50. qDebug() << "bbbbbbbbbb";
    51. QEventLoop loop;
    52. QObject::connect(audioOutpu, SIGNAL(stateChanged(QAudio::State)), &loop, SLOT(quit()));
    53. do {
    54. loop.exec();
    55. } while(audioOutpu->state() == QAudio::ActiveState);
    56.  
    57. return a.exec();
    58. }
    To copy to clipboard, switch view to plain text mode 

    Output:
    Screenshot from 2016-08-16 13:10:31.png

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,357
    Thanks
    36
    Thanked 1,533 Times in 1,484 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Only buzzing sound while playing wav/mp3 files through QAudioOutput

    Is your input file in the format you are trying to play?

    Have you tried a QMediaPlayer instead?

    Cheers,
    _

  3. #3
    Join Date
    Apr 2011
    Posts
    216
    Thanks
    136
    Thanked 6 Times in 5 Posts

    Default Re: Only buzzing sound while playing wav/mp3 files through QAudioOutput

    I realised that the wav file which I was running was not actually a wav file. It was a mpeg compressed file with the extension wav.
    With a real wav file, this example works fine.

  4. #4
    Join Date
    Jun 2019
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Only buzzing sound while playing wav/mp3 files through QAudioOutput

    I know it has been long time.
    Would someone tell me how to play wav file with QAudioOutput ?
    File format is wrong i think but i do not know how to fix it.
    I am using Qt 4.8 and having same buzz problem.

    thanx in advance..

Similar Threads

  1. Playing ulaw file with QAudioOutput
    By sulliwk06 in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2014, 13:41
  2. 'Pop' at start of sound playback using QAudioOutput
    By semajnosnibor in forum Qt Programming
    Replies: 4
    Last Post: 20th June 2014, 07:31
  3. Playing streaming PCM Audio using QBuffer and QAudioOutput Class
    By kapoorsudhish in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2013, 08:08
  4. Sound not playing when using executable file
    By Zotop in forum Qt Programming
    Replies: 0
    Last Post: 25th November 2010, 23:47
  5. Asynchronously playing a sound (.wav) on windows mobile
    By TMan in forum Qt for Embedded and Mobile
    Replies: 10
    Last Post: 20th October 2008, 19:16

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.