Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sound crackling with QAudioOutput
Forum Updated to NodeBB v4.3 + New Features

Sound crackling with QAudioOutput

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    billconan
    wrote on last edited by
    #1

    Hello guys,

    I'm trying to play streamed audio with QAudioOuput. although I could hear some sound, but it is crackling a lot. the quality is very bad.

    the logic of my code is very simple, renderAudioFrameProc is a callback function. whenever there is an audio buffer, this function is called. I simply direct the audio buffer to QAudioOutput.

    I can't figure out why this issue happens. my feeling is that QAudioOutput is not processing the data fast enough, so some data is dropped.

    it's not an endianess issue or data type issue, as I could hear sound, it is just the quality is bad.

    @void renderAudioFrameProc(AudioFrame audioFrame)
    {
    if (!m_audioOutput)
    {
    m_format.setSampleRate(48000);
    m_format.setChannelCount(2);
    m_format.setSampleSize(16);
    m_format.setCodec("audio/pcm");
    m_format.setByteOrder(QAudioFormat::BigEndian);
    m_format.setSampleType(QAudioFormat::Float);

        QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
        if (!info.isFormatSupported(m_format)) {
            qWarning() << "Default format not supported - trying to use nearest";
            LOG(ERROR, MISC, 0, "Default format not supported - trying to use nearest");
            m_format = info.nearestFormat(m_format);
        }
        m_audioOutput = new QAudioOutput(m_device, m_format, this);
        m_output=m_audioOutput->start();
        m_audioOutput->setVolume(1.0);
    }
    
    int written = 0;
    while(written &lt; audioFrame.streamSizeBytes)
    {
        if (m_audioOutput-&gt;bytesFree())
        {
            int bytefree = m_audioOutput->bytesFree();
            int willwrite = qMin((int)(audioFrame.streamSizeBytes-written),(int) bytefree);
            m_output->write(((const char*)audioFrame.streamBuffer)+written, willwrite);
    
            if (willwrite< bytefree)
            {
                break;
            }
    
            written+=willwrite;
    
        }
        else
        {
           // Sleep(5);
        }
    }
    
    audioFrame.releaseProc(audioFrame);
    

    }
    @

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bnogal
      wrote on last edited by
      #2

      jitter is your enemy

      1 Reply Last reply
      0
      • B Offline
        B Offline
        billconan
        wrote on last edited by
        #3

        how to solve this? with a jitter buffer?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved