Legacy GM Audio Queue

MeBoingus

Member
Hi all,

I'm trying to set up a system where 3 different sounds play, one after the other.

Long story short; I have many audio files, reading out numbers 1-99. I need to play an audio sample that says "Level", followed by a specific number, followed by a sound that says "Get ready."

I've looked into audio queues in the GMS docs, but the concept boggles me, and it doesn't even seem like it'd be right for this situation.


I tried setting up a simple system involving a timer that played the next sound after the previous sound had completed, but it seems overly complicated, and I ran into a few teething problems.



Any tips on how to achieve this?
 

Yal

🐧 *penguin noises*
GMC Elder
You could use an audio buffer, load both sounds into the buffer right after each other (thus filling it with one continuous blob of audio data), and then play its entire contents as a sound.
 

samspade

Member
It seems like the audio queue system is the way to go. Is there some reason you don't want to use it?

Otherwise, you could probably make your own version of the system. In pseudo code, it would look something like this:

Code:
///add_audio_to_queue(audio)
ds_queue_enqueue(audio_queue, argument0);

///audio_monitor_sound
if (audio_is_playing(sound)) {
    sound = play_next_audio();
}

///play_next_audio
var sound = ds_queue_dequeue(audio_queue);
audio_play_sound(sound, 1, false);
return sound;
The primary issue with this is that it isn't asynch so if your game lagged there could be issues.
 

Joe Ellis

Member
I don't get why you can't use timers\alarms, "Level" "1" "Get Ready!", just set them to the right time you want, you really don't need audio queues for this, they're for way more complicated things than this
To get the right time for the alarms, just remember there are 60 steps per second, so get the length of the sounds and find the right time in steps for them
 

Joe Ellis

Member
...and hope the game doesn't encounter a lag spike in the field that throws off the timing...
That's true but if the game lagged the queue would still get delayed, I'm not sure how much difference it'd make, it might be best to use the async audio playback event which is triggered when a sound finishes playing, play the next sound when the current one finishes, and when the last one finishes start the game

-EDIT
sorry actually I just realized the only time the queue would lag is if one of the sounds finished while the game's lagging, so it's alot less likely to see any effect than with using timers, however the queue method would result in the sounds being played as accurately with no lag between them as possible, it might not be wanted cus its more possible for the game to go out of sync with the sounds this way, and the timer method would result in the sounds beginning at the same time as other things in the game more consistently if there was lag, so each method has bad sides and it depends which one you'd prefer
 
Last edited:

Yal

🐧 *penguin noises*
GMC Elder
One of the big differences is that alarm precision is limited to one game step (typically either a thirthieth or a sixtieth of a second) so if your sounds don't have a pause between them (e.g. intro and main loop of a song) and aren't an even multiple of the time between two steps long, they will not overlap perfectly... this isn't an issue when using an audio buffer.
 

Joe Ellis

Member
That's a good point, I think an audio buffer would be best for this after thinking about it, and they are quite simple to set up. I was trying to think of the simplest way for Liam but I think its worth learning how to use audio buffers and buffers in general. Although do you know if it's bad or worse for performance to play audio from a buffer instead of a resource?
 

Yal

🐧 *penguin noises*
GMC Elder
Although do you know if it's bad or worse for performance to play audio from a buffer instead of a resource?
Depends a bit. Resources can be compressed audio (OGG, MP3), which needs to be uncompressed on the fly. Audio buffers can only contain uncompressed (i.e., WAV) audio data, so they play faster, but use up more memory.
 

GMWolf

aka fel666
Why can't you keep and ds_queue of sounds.
Then continuously check if the top sound is playing. If it is not, pop it of, and start the next sound.

If you don't need it to be stiched together with high precision it should work just fine. I recommend that for music queues, voices, stuff that can have small gals in between.

If you need them to be stiched together tightly, then an audio queues/audio buffers are your best bet. But rather than buffering the entire audio for large files like music. Instead use a few buffers to keep the queue fed. (You will need to use the audio queue events to get the next chunk of audio and add it to the queue).
This will ensure your audio is stiched together tightly.
This would be best used for music, or other audio where the timing needs to be perfect.
 
Top