How does the Sound Buffer work?

So I started adding sounds to my game and per suggestions from the forum and the documentation of Defolds sound functionality I use a sound controller that plays according sounds on the corresponding message together with a gating functionality.

What happens often is that I have sounds for dragging and dropping objects, now theoretically one can drag an object on an invalid area which makes it disappear and trigger a sound. If the player would want to they could perform this action in rapid succession (not that it would make sense, but anyway). I gate this specific sound but after a certain amount of actions performed I receive an error that the sound buffer is full.

My question in that regard would be on how does the sound buffer get cleared or when are sounds getting removed from it? My sounds are fairly short and should not clog up the sound buffer to my understanding.

ā‚¬: On that note Iā€™ll sneak in another question related to sound. As soon as the game starts I start the background music. But on some devices/browsers the music only actually starts after interacting with the app for others the music starts immediately. Why is that and is there a way to have this work consistently across devices/browsers? This can be easily replicated by navigating to this example (Music) on Firefox and Chrome.

Browsers can require interaction before playing audio. Itā€™s a problem all webgames have to deal with. So if you want to make sure music plays at the right time you need to include an initial ā€œinteract with meā€ scene to enter the game.

Could you upload a small example project where the buffer is full situation happens? Itā€™s strange that it would happen with manual gating.

1 Like

Could not reproduce it in a minimal project, but surprisingly the error is not being thrown in my project anymore. Might have fixed it somewhere along the way :man_shrugging: This was only a problem as I thought that a bug in my project is happening due to this error being thrown, and although the error is now gone my bug persisted. So looks like itā€™s something on my end after all. Iā€™ll post an update in case I get the error to appear again. Cheers for the other answer!

1 Like

For the record, whatā€™s your OS and which engine version were you running?

Engine version is 1.2.186 and I was building from a Windows machine for HTML5 and tested the project in Firefox.

1 Like

Quick follow up on this issue, turns out it was a mistake on my end, in that I simply did not read the error message correctly ā€¦

ERROR:GAMESYS: Sound component could not be created since the sound buffer is full (32). Setting ā€˜sound.max_component_countā€™ in game.project.

As the error message says something about the sound buffer being full I immediately started tinkering with the max sound buffers setting in the game.project, which according to the documentation is unused anyway and therefore did not help. The issue was simply that I was spawning new collections through a factory during runtime containing a parent game object with a few children. One of these children was a sound game object holding a sound component. At some point, I delete the parent object and had to manually delete its children as well (as Defold apparently does not take care of that) and during this operation, I simply forgot to delete the sound game object with the sound component as well, which in the end resulted in the above error message. :slight_smile:

3 Likes

Send a second argument of true to go.delete to delete the children as well (to be honest, I forgot that this wasnā€™t the default myself).

4 Likes