Unstable Audio Latency (Audio: Play Sound)

Discussion and feedback on Construct 2

Post » Tue Mar 01, 2016 9:40 pm

I'm working on an update for my APP "Easy Chords Studio", in which I've build a so called arpeggiator.
This ARP is nothing more than playing notes after each other with a certain delay (determined by the BPM)

I'm running into a audio latency / delay issue when using the default audio plugin in Construct 2.
(the sounds are played after very noticeble different delays instead of a stable delay)
Basicly, this is what I do in the construct code:

AUDIO : Play Sound
SYSTEM: Wait 0.1875 seconds
AUDIO : Play Sound
SYSTEM: Wait 0.1875 seconds
AUDIO : Play Sound
SYSTEM: Wait 0.1875 seconds
AUDIO : Play Sound
SYSTEM: Wait 0.1875 seconds
ETC ...

Running the app in preview mode in browser sounds smooth.
But running the APP on actual devices, things get messed up in the timing.
(Exported the project to XDK using cordova and build for both iOS and Android)

Logging the time difference after each play shows a quite stable playback:
But the actual delay (measured by recording back the audio output and analysing it) varies way more.

Delay took: 198ms (actual delay: 246ms)
Delay took: 202ms (actual delay: 246ms)
Delay took: 203ms (actual delay: 161ms)
Delay took: 201ms (actual delay: 243ms)
Delay took: 203ms (actual delay: 161ms)

Already tried stopping all sounds after each delay, so no polophony, but unfortunatly the same result.
And yes, preloading of sounds is enabled in this project ;)

Is there a way I can make, at least the delays between the notes the same?
B
8
S
2
Posts: 24
Reputation: 694

Post » Wed Mar 02, 2016 11:33 am

The problem with audio scheduling is right now you can only start audio playback in events, which run at 60 FPS (every 16.6ms) under good conditions. Even on desktop since 1875ms does not divide in to 16.6ms, it will not be able to schedule those sounds at exactly the right time. If the framerate is low, e.g. 30 FPS, the problem gets worse. The solution is to allow scheduling playback at a time in the future, which the Web Audio API can do sample-accurately, so the sound kicks in exactly when you want it, even between frames. I'll look in to adding this in a beta release some time...
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,762

Post » Wed Mar 02, 2016 2:25 pm

Thanks @Ashley for the technical explanation, I'll do some additional testing with this knowledge on various devices.
I'm very curious if keeping the delay divisible to the current frame rate will make the ARP run (more) steady ;)

Really looking forward to have this scheduled playback in Construct!
B
8
S
2
Posts: 24
Reputation: 694

Post » Fri Mar 25, 2016 8:11 am

The new audio feature "Schedule next play" which is available in Construct 2 r225, seems to nail this problem.
Audio timing is (nearly) perfect on various devices (which support advanced audio)

Thanks again @Ashley !
B
8
S
2
Posts: 24
Reputation: 694


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 10 guests