Sound crackling with QAudioOutput



  • 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);
    

    }
    @



  • jitter is your enemy



  • how to solve this? with a jitter buffer?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.