Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

audio: push vs. pull mode: howto set pull interval in msec?



  • if you open the "Audio Output Example" that comes with Qt, it demonstrates both push and pull mode.

    in push mode, you can specify the interval that the push will happen when you start the timer with this:

    m_pushTimer->start(mSec);
    

    where mSec is defaulted to 20. In my app, i do some heavier processing DURING the call to generator->read(), so if i leave it at the default 20, I get audio dropout during playback (short bursts of silence). So i need to call the push at a higher frequency.

    it's easy to do this in push mode, i specify mSec to be 5 and i'm all set, my audio sounds smooth and clean.

    But what if i want to use pull mode? I don't see a way to tell the m_audioOutput that it needs to call more often. How do i do this?

    -dave



  • You should not do heavy processing in readData function.
    It should return the needed data as fast as possible in pull mode.
    And I don't think you can control the frequency to msec. That's what pull mode means: it pulls when needed.
    The only approach may be setBufferSize to a smaller size than default before start(), or return less data in readData , but I'm not sure if those will work.



  • well it's not really "heavy" processing, just volume control or key changing (preserving tempo). the PCM is already unpacked (it's not mp3 decoding on the same thread). so that really shouldn't affect things?

    and i most certainly am returning the data s fast as possible.

    and yes, i, too, thought it was "pull when needed" but apparently its notion of "need" is somehow a little late?

    setBufferSize() to smaller didn't affect things, nor did returning half of what was requested in readData(), so i'm mystified.

    i could try substituting a the tone-generator (from the Example code) for my audio generator, just to rule that out? but before i do that, any other thoughts or clues?

    -dave



  • I don't have your project, so I just used the Audio Output Example to have a test (in Windows).
    I print the interval that Generator::readData is called.
    While setBufferSize does not do any difference, but make len /= 2 in Generator::readData does make it be called more frequently.
    [EDITED]
    Hey, I've looked into the source code (Windows only) and found something.
    If you open the Generator by open(QIODevice::ReadOnly | QIODevice::Unbuffered), then the readData will be called much more frequently (and read less for one call).
    And in that case setBufferSize will also have affect on the frequency.
    It seems like if you open the device without QIODevice::Unbuffered it will always try to read at least 16384 bytes.


Log in to reply