Unsolved 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 togenerator->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 besetBufferSize
to a smaller size than default beforestart()
, or return less data inreadData
, 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 inreadData()
, 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 thatGenerator::readData
is called.
WhilesetBufferSize
does not do any difference, but makelen /= 2
inGenerator::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 theGenerator
byopen(QIODevice::ReadOnly | QIODevice::Unbuffered)
, then thereadData
will be called much more frequently (and read less for one call).
And in that casesetBufferSize
will also have affect on the frequency.
It seems like if you open the device withoutQIODevice::Unbuffered
it will always try to read at least 16384 bytes.