Results 1 to 3 of 3

Thread: How to play decoded audio buf using QIODevice

  1. #1
    Join Date
    May 2011
    Posts
    16
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default How to play decoded audio buf using QIODevice

    I am initializing audio device before writing to QIODevice.
    Here is my code:
    initAudioDevice() {
    QAudioFormat audioFormat;
    audioFormat.setChannelCount(mAudioCodecCtx->channels);
    audioFormat.setSampleRate(mAudioCodecCtx->sample_rate);
    audioFormat.setSampleSize(16);

    audioFormat.setByteOrder(QAudioFormat::LittleEndia n);
    audioFormat.setSampleType(QAudioFormat::SignedInt) ;

    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
    if (!info.isFormatSupported(audioFormat))
    {
    qWarning() << "Default format not supported - trying to use nearest";
    audioFormat = info.nearestFormat(audioFormat);
    }

    mAudioOutput = new QAudioOutput(info, audioFormat, this);
    mIOOutput = mAudioOutput->start();

    }

    I am using libavcodec decoder to decode audio frames and writting decoded audio buf to "mIOOutput->write()"
    mIOOutput->write((char *)mAudioBuffer, mAudioSize);

    Here my problem is, Audio is not playing properly.
    1. Am I missing anything here?
    2. I am feeling, while initializing I am missing some thing. Is it?

    Please help me.

    Thanks in advance.
    VijayQt

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to play decoded audio buf using QIODevice

    Quote Originally Posted by vijayQt View Post
    Here my problem is, Audio is not playing properly.
    1. Am I missing anything here?
    Yes, [code] [/code] tags, any of your code that writes to this device, and description of what "Audio is not playing properly" means.
    2. I am feeling, while initializing I am missing some thing. Is it?
    Just looking at the example in the QAudioOutput docs I can see you are not setting the codec in your QAudioFormat object.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. #3
    Join Date
    May 2011
    Posts
    16
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: How to play decoded audio buf using QIODevice

    Yes, tags, any of your code that writes to this device, and description of what "Audio is not playing properly" means.
    Full of noice and lot of breakings in-between . Is it becoz of codec or something else?

    I can see you are not setting the codec in your QAudioFormat object.
    libavcodec and Qt codec's are same or different?
    VijayQt

Similar Threads

  1. play audio file
    By hema in forum Qt Quick
    Replies: 1
    Last Post: 11th August 2011, 05:27
  2. how to play audio file in qml
    By hema in forum Newbie
    Replies: 0
    Last Post: 10th August 2011, 10:57
  3. Unable to play audio outside Qt creator
    By somnathbanik in forum Newbie
    Replies: 0
    Last Post: 9th November 2010, 06:47
  4. play audio url
    By tungvc in forum Qt Programming
    Replies: 0
    Last Post: 15th July 2010, 11:04
  5. Which dll is needed to play the audio files
    By addu in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2009, 23:20

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.