3.6.0: Sound queue plays with small gaps between clips #1687
Labels
context: audio
context: code
fixing/improving existing code: refactor, optimise, tidy...
type: bug
unexpected/erroneous behavior in the existing functionality
Context
AGS has AudioClip.PlayQueued function that supposed to queue sounds if they cannot play right away. This may be used to sequence clips, provided there's a restricted number of channels for this audio type, preventing them from starting simultaneously. As such, this is also a sort of workaround for AGS's lack of a proper sound sequencer/mixer script API.
Problem
The queued sounds are regularly played with a small but noticeable gap between them. The reason is that the sound queue is updated along with the rest of the game logic, one per game frame (depends on fps). Therefore it cannot react to the previous playback's ending fast enough.
Before 3.6.0, and before the proper audio control thread was implemented, the audio was polled on the main thread, and maybe that somehow made it more "in sync" with the main game's update, so the queued sound had higher chance to start quick enough (it was still quite random). Now when the playback is processed on its thread it is "disconnected" from the game updates, and some things no longer work same way.
Expected behavior
Users expect the queued sounds to play seamlessly.
Potential workarounds
Implementation problems
One big issue here is that the queue and audio core are not connected. Queue works within the game logic, and needs knowledge of the logical audio channels, where it will find a free one according to clip types and priorities. Audio core knows nothing about the game's channels and other things.
Audio core works on its own "audio thread", sound queue is updated along with a game on the game update thread (aka main thread).
Thus the solution may have to involve one of the following:
The logical audio channels are represented with SOUNDCLIP array controlled using some internal api.
One important nuance about these channels is, that in order to keep things consistent with script, those must not be modified at any random times, but only in between script callbacks (currently - only once per frame). There's a thorough explanation in the description to the commit ff05f69 that enforced such rule in 3.6.0.
This also means that we cannot modify this array as a reaction to the audio core slot stopping and queue being processed at any random time. OR we'll have to change how this array serves as a "frontend" to channels, by introducing more intermediate objects or something...
EDIT:
Another issue, the audio core is currently reporting sound position as (approximate) playback position of the openal source, not the position of the sound decoder (reader). This means that when the decoder is done reading, the openal may still have samples in buffer to be processed. May this add to the delay between previous and next sound, if the new sound is triggered by checking the position of the previous one?
The text was updated successfully, but these errors were encountered: