Results 1 to 3 of 3

Thread: Playing ulaw file with QAudioOutput

  1. #1
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Playing ulaw file with QAudioOutput

    So I'm trying to set up a simple working example to play a ulaw file and the audio seems to be distorted. I thought someone here might have encountered this before and immediately know what I'm doing wrong.

    the ulaw file is:
    sample rate - 8 khz
    mono
    sample size - 8

    When the ulaw file plays, I can still make out everything, its just fairly distorted, like listening to a radio station going out of range.

    I tried using sox to convert it to a wav file, I played it in windows media player just to make sure the file was good, and it sounded fine. Then I used my code to play the wav file after chopping off the header. And it sounds just as distorted as it did with the ulaw file.

    I don't know how to tell what codec windows media player is using to play the file, but the only codec I get from supportedCodecs() is "audio/pcm".

    Let me know if anything wrong jumps out at you. I'm still pretty new to all this audio stuff.


    Qt Code:
    1. m_format.setSampleRate(8000);
    2. m_format.setChannelCount(1);
    3. m_format.setSampleSize(8);
    4. m_format.setCodec("audio/pcm");
    5.  
    6. QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    7. if (!info.isFormatSupported(m_format))
    8. {
    9. m_format = info.nearestFormat(m_format);
    10. }
    11.  
    12. QAudioOutput output(m_device, m_format, this);
    13.  
    14. QFile audio_file("C:\\track1_in1.ul");
    15.  
    16. if(audio_file.open(QIODevice::ReadOnly))
    17. {
    18. // audio_file.seek(44); //for when I tried to do the same with a WAV file
    19. QByteArray audio_data = audio_file.readAll();
    20. audio_file.close();
    21.  
    22. QBuffer audio_buffer(&audio_data);
    23. audio_buffer.open(QIODevice::ReadOnly);
    24. output.start(&audio_buffer);
    25.  
    26. QEventLoop loop;
    27. QObject::connect(&output, SIGNAL(stateChanged(QAudio::State)), &loop, SLOT(quit()));
    28. do
    29. {
    30. loop.exec();
    31. } while(output.state() == QAudio::ActiveState);
    32. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to sulliwk06 for this useful post:

    TheIndependentAquarius (16th August 2016)

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

    Default Re: Playing ulaw file with QAudioOutput

    I am having the same problem. Did you find a solution?
    Many thanks!!

  4. #3
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Playing ulaw file with QAudioOutput

    Quote Originally Posted by rsafir View Post
    I am having the same problem. Did you find a solution?
    Many thanks!!
    I ended up converting my ulaw file to a wav in the code (its not hard, just adding a header) and played it with QMediaPlayer.

  5. The following user says thank you to sulliwk06 for this useful post:

    TheIndependentAquarius (16th August 2016)

Similar Threads

  1. Playing streaming PCM Audio using QBuffer and QAudioOutput Class
    By kapoorsudhish in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2013, 09:08
  2. can't get o/p by playing mp3 file in Phonon
    By dibyendu in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2011, 14:09
  3. playing a mp3 file ?
    By hcetiner in forum Newbie
    Replies: 1
    Last Post: 13th May 2010, 11:21
  4. playing mp3 file with QSound
    By highlightsong in forum Qt Programming
    Replies: 4
    Last Post: 6th August 2008, 10:24
  5. Playing Video file using Qt
    By sarode in forum Qt Programming
    Replies: 3
    Last Post: 26th March 2007, 19:35

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.