QAudioOutput notify() doesn't emit on set interval
-
According to several examples online about using QAudioOutput in Push mode, I have to specify an interval e.g. 100ms, and then write some data. Now once 100ms worth of audio has been processed, notify() event will be emitted and I can can queue more audio.
The logic I'm using is to initially queue 300ms audio/pcm data (being received over network) but set notify interval to 100ms. That way once first 100ms of audio has been processed and 200ms is left in buffer, notify() will be emitted, then I'll write another 100ms of data and so on. That way there is always 200ms of data in buffer - and audio should play smoothly.
For some reason, and I've tried in debug & release mode. This approach works fine 50% of the time, remaining time, the first notify is emitted after ALL of the 300ms initial audio has been processed and the buffer is empty so when my code queues next 100ms worth of data, it results in laggy audio because the 200ms buffer is consumed already.
Here's a screenshot. Notice after first 115200 bytes were written, program waited for almost 300ms before notify was called and audio buffer was consumed, resulting in output state also going into Idle. Am I doing something wrong here? whats the proper way to Push data to audio device?
OS: Windows 10, Qt: 5.12.10
-
Hi,
Did you check that you actually get the interval you asked for as suggested in the setNotifyInterval documentation ?
-
Do you also handle the stateChanged signal in your code ?
-
@SGaist Yes, that's where I'm just outputting "State: IdleState" or "State: ActiveState" lines
When it works fine i.e. initial notify() is emitted after 100ms and there is still 200ms of audio data in buffer and I queue additional 100ms of data (and so on), then the state never goes to Idle and audio plays smoothly.
Also, the program either works completely fine or delays first notify() until entire initial 300ms audio is played in which case State goes back and forth between Idle and Active, resulting in breaks in audio.
-
Can you share your code ?