Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1005125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:14:39+00:00 2026-05-16T08:14:39+00:00

I’m working on playing audio from an audio stream using VC++ with the QtMultimedia

  • 0

I’m working on playing audio from an audio stream using VC++ with the QtMultimedia library. Since I’m not too experienced with Qt’s libraries I started by reading in a .wav file and writing it to a buffer:

ifstream wavFile;
char* file = "error_ex.wav";
wavFile.open( file, ios::binary );

After that, I used ifstream’s .read() function and write all the data into a buffer. After the buffer is written it’s sent off to the audio writer that prepares it for Qt:

QByteArray fData;

for( int i = 0; i < (int)data.size(); ++i )
{
    fData.push_back(data.at(i));
}

m_pBuffer->open(QIODevice::ReadWrite);
m_pBuffer->write( fData );

m_pBuffer->close();

(m_pBuffer is of type QBuffer)

Once the QBuffer is ready I attempt to play the buffer:

QIODevice* ioDevice = m_pAudioOut->start();
ioDevice->write( m_pBuffer->buffer() );

(m_pAudioOut is of type QAudioOutput)

This results in a small pop from the speakers and then it stops playing. Any ideas why?

Running Visual Studios 2008 on Windows XP SP2 using Qt library 4.6.3.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:14:39+00:00Added an answer on May 16, 2026 at 8:14 am

    As Frank pointed out, if your requirement is simply to play audio data from a file, a higher-level API would do the job, and would simplify your application code. Phonon would be one option; alternatively, the QtMobility project provides the QMediaPlayer API for high-level use cases.

    Given that the question is specifically about using QIODevice however, and that you mentioned that reading from a WAV file was just your intitial approach, I’ll assume that you actually need a streaming API, i.e. one which allows the client to control the buffering, rather than handing over this control to a higher-level abstraction such as Phonon.

    QAudioOutput can be used in two different modes, depending on which overload of start() is called:

    • “Pull mode”: void QAudioOutput::start(QIODevice *)

      In this mode, QAudioOutput will pull data from the supplied QIODevice without further intervention from the client. It is a good choice if the QIODevice being used is one which is provided by Qt (e.g. QFile, QAbstractSocket etc).

    • “Push mode”: QIODevice* QAudioOutput::start()

      In this mode, the QAudioOutput client must push mode to the audio device by calling QIODevice::write(). This will need to be done in a loop, something like:

      qint64 dataRemaining = ... // assign correct value here
      while (dataRemaining) {
          qint64 bytesWritten = audioOutput->write(buffer, dataRemaining);
          dataRemaining -= bytesWritten;
          buffer += bytesWritten;
          // Then wait for a short time
      }
      

      How the wait is implemented will depend on the context of your application – if audio is being written from a dedicated thread, it could simply sleep(). Alternatively, if audio is being written from the main thread, you will probably want the write to be triggered by a QTimer.

      Since you don’t mention anything about using a loop around the write() calls in your app, it looks like what is happening is that you write a short segment of data (which plays as a pop), then don’t write any more.

    You can see code using both modes in the examples/multimedia/audiooutput app which is delivered with Qt.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.