Author Topic: Short silence between music tracks when using .PlayQueued  (Read 387 times)

Hi! I'm trying to make two music tracks play seamlessly one after the other, but no matter what I do, there is a little bit of silence between them (around 20ms). What's worse, if I use the .ogg format, the track change occurs before it should (the ending gets chopped). .WAV files are fine in that regard. The most infuriating thing is that this happens almost all the time and with every track that plays in this fashion but, once in a while (I'd say way less than 10% of the time), it randomly works fine...

Since most of the OST's tunes don't loop at the start point, or some sounds at the end bleed onto the beginning of the loop, the idea behind this is to play one track with everything that's different first just once, then move onto one that will always stay the same and loop it.

This is how it should sound:
https://soundcloud.com/alejandro-tiscornia/a11-field2a-fl/s-S2gFO (the transition occurs at 2:02)

That's one of the tunes from the game, split into two tracks. And this is how it sounds when playing the game (captured straight from the soundcard):

https://soundcloud.com/alejandro-tiscornia/a11-field2a-ogg-ogg/s-HFtKw (.ogg)
https://soundcloud.com/alejandro-tiscornia/a11-field2a-wav-wav/s-NDk2J (.WAV)
This is what the code for the music I'm using for the example looks like:

Code: Adventure Game Studio
  1. SetGameOption(OPT_CROSSFADEMUSIC, 0);
  2. a11_Field2A_1st.Play();
  3. a11_Field2A_loop.PlayQueued();

Before anyone asks, removing the first line doesn't make the problem go away. Both tracks are set to "normal" priority and their loop state are set to "false" and "true", respectively. The audio "Type" ("Music") is set to only use one channel (otherwise, they'll both play at the same time). I've also tested this with the demo game that comes with AGS: same results. The engine is up to date (Build but the problem happens with older versions too.

I think it's important to say at this point that I'm a composer and not a programmer, that I've never used AGS before and that I'm only programming the music. I know it's unusual, but due to the complexity of the soundtrack, its length, and how it interacts with the game, its implementation needs a lot of iteration and, since the game's programmer and I are on opposite ends of the world, any back and forth concerning implementation will take ages... so I'm doing it myself. Anyways, what I want to say with this is that I cannot rule out user-error on my part (though I read the manuals and tried to know what I was doing before writing any code), and that I'm trying to keep everything I do as self-contained as possible, so as to not mess the other guy's code up.

What can be causing this? At first I thought it was the engine decompressing the .ogg files for playback (I had a similar problem in the past with a game made in flash that used .mp3s) but .WAVs aren't compressed at all, and the problem happens with them too. So... I'm stumped, and the deadline is not far away... Could this be problem with AGS itself?

If this cannot be fixed (hopefuly it can!), I've been thinking of alternative solutions. One is making the initial tracks way longer, but that'll make the music weight several GigaBytes (the soundtrack is close to 5 hours long and it's already several times heavier than the game!). I've also thought about doing something with the "repeatedly_execute" function (thus, only using one track instead of two) but I decided not to because I suspect this will have a serious detriment on performance (and might not even work, as I need the looping to be sample-perfect so as to not have glitches).

Any help is appreciated, and please don't hesitate to ask for any information you might need to solve this. I hope I'm posting in the correct part of the forum (since this seems like it's a problem with the engine itself) but if not, please accept my apologies and feel free to move it where it should be. Thanks in advance for any ideas, and apologies for my broken english!

I have no solution to suggest yet, but just wanted to comment that similar problem was reported before by another person, so this might be some kind of issue inside the engine: https://github.com/adventuregamestudio/ags/issues/501

Thanks for taking the time to answer, Crimson Wizard!

It does sound like a similar problem... but I'm not sure if it's the same thing. There is no gap when looping the tracks here, at least not that I could hear. The silence (and the other stuff when using .ogg) only appears when one track ends and the other begins. I have the second track in the sequence set to loop and that works fine... it's the transition that's the problem. But maybe the two things are related, somehow...

Monsieur OUXX

  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting
There is no gap when looping the tracks here. The silence only appears when one track ends and the other begins.
Could it be related to the fraction of a second required to load the file into memory?

There is no gap when looping the tracks here. The silence only appears when one track ends and the other begins.
Could it be related to the fraction of a second required to load the file into memory?

I thought about it... but I don't think it is: the issue is present using both compressed formats and .WAV files and, while the timing changes each and every time, the format does not affect this in any way. One would expect .mp3s and .oggs to take longer to load than .WAVs. Still, who knows...

I do appreciate the response, though! Thanks for your time!