[SOLVED] Spatial Sound Issues


So im super new to GDevelop and ive been playing around with spatial sound but only to medium success. There is a couple of things that dont quite work out as intended.

Here is what im trying to do:

Place an object in a grid and only then make it play a sound depending on its position and the listeners position. The listeners position is in the middle of the grid. I want this to work for multiple sound objects, where each object emmits sound from its respective positions.

For now spatial audio depending on the objects position only works when i have a song looped at the beginning of the scene. If i set the position of the sound and the playback of my audio as condition of the object beeing placed in the grid it doesnt update its position and the sound is just beeing played genericly.

The second issue is that while the condition is true the audio file just keeps looping incredibly fast without playing out the whole file. So in the end i just get noise. If i put trigger once it will only play once but i want it to play as long as the condition is true but have it only repeat after the whole sound file has played to the end.

Third issue im not even sure if gdevelop is suited for playing multiple sounds from different locations as the only option is to route the audio from different locations to different channels. And im not sure how to fuse them again.

By the looks of it i am not allowed to post images yet :frowning: so im not sure how to describe it any better with just text. Edit: Imgur link (Event and Layout)

Thanks a lot in advance and shoot away if things arent clear!

Something like this could be useful

Each object is draggable so I can put them colliding with the goals. Once done each goal plays a sound in a different channel.

The volume of each channel is calculated, based on the distance of the goals and the mouse:

  • in the formula, 100 is the max volume. To this value I substract the distance between the object and the mouse, and divide it between 5.2 since the max distance I want between the mouse and the object is 520. Just to be safe and for the formula working all around, I use the absolute value, so no negative numbers.

Moving the mouse around you can notice the sounds’ volume changing, according to the distance with the mouse.

I hope this helps

Second version of the code, with a fix on the distance formula and the way to apply it to the volume.

Check out this thread, maybe you can find answers to some questions about working with spatial sound there: (SOLVED) How to create a Spatial sound?

Hey! Thanks for the example. Ive rebuilt it and while it doesnt work me to some extend this sadly wont solve the spatial issue as this will only fiddle with the volume and no the direction of the sound. Both should be controlled by the “set position of sound” action.

Hey, thanks for pointing me there, but this is the thread i come from originally and it already helped alot! Though i believe your example will only work when i have the song playing from the beginning of the scene and not depending on a condition as in my imgur example. The X and Y Position from the Sound Source do update, im checking this with textboxes, but it wont translate to the spatial audio. Neither Volume nor Position will translate to what im hearing (headphones on) when i move my soundsource and the condition is fullfilled.

EDIT: While the X and Y Position of my Object do update, the Volume of the SoundChannelVolume(1) does not. Which makes me think the the Position of the Sound on Channel 1 doesnt update to the location of the object properly. Is there a way to return this variable?

Unfortunately, I don’t understand what exactly doesn’t work for you. If you look at the code (from the example):

  1. We start the sound on the channel. Volume to maximum, looping.
  2. Set (and change) the position of the source sound (SourceSound), which comes from channel 1.
  3. We establish the position of the listener.

The volume changes depending on the distance between the source and the listener. The position of the sound changes depending on the position. I can clearly hear all this.
The volume on the channel does not change, because the spatial sound functions change it for the listener, not for the channel. I do not know if it is possible to get the current value of the sound volume.
If you need to reproduce several sounds, then I suppose you need to run them on different channels and, accordingly, create the same number of sources and listeners (for each channel).

The difference between your example and mine would be that i dont introduce a looping sound at the beginning of the scene but only when a certain condition is met. If the condition is met i do hear the sound but not according to the objects (=sound source) position.

I do play a sound at the beginning with vol = 0 to initate the scene. Else it wont start.

Thanks for clarifying the volume value issue!

1 Like

Sorry, I was wrong: there is no need to create a listener for each sound, since the channel is not specified there. I think one is enough.
In terms of volume, to be honest, this is my guess, but I can’t find another explanation. I hope the developers will correct me if I’m wrong.

Thanks for the update!

Could you try and recreate my issue? Its such a trivial use of the function really and im probably just doing something stupid.

Edit: Incorrect info removed to avoid further confusion.

Oh thats quite surprising. @E1e5en example sounded really convincing to my ears as it didnt sound like only stereo panning at all :frowning:

Thanks for clearing that up though!

@dqunbp I’m actually double checking with the contributors right now. I might be misreading the source code.

Edit: Yep, I’m wrong. The built-in example has positional audio as well as spatial. https://game-previews.gdevelop-app.com/1636741976626-200951/index.html

1 Like

If you prepare a test case. Now I don’t have time, maybe later.

Phew! Thanks for double-checking. So im back to my inital problem :slight_smile:

Why don’t you have a value specified here?

Also note that sound must be played on a channel to use positional audio.

Channels are not used for “play the sound” events, only for “Play the sound on a channel” events.


I didnt specify a value becasue, the default value for this argument is 100.

My Game can be found on this google drive

If you have time to test it, that would be great!

EDIT: Upped the version where the sound is specified to a channel.

Ive tried this at first and it totally bugs out for me. I just get a random click and thats it. Thanks for reminding me though, totally forgot that i didnt specifiy the channel again.

EDIT: Sorry if im beeing confusing, i fixed the bug but the inital problem remains.

EDIT2: Im out of replies for 21 hours as this is my first day. Ill try and comment/edit on this post if needed :slight_smile: Thanks for the help so far!!

The click was caused by a second specification of the Sound Source Position somewhere else in the code. I am now using two channels but i can only ever hear channel 1. Is there a way to combine them in a “Master Section”? Or how do i listen to multiple channels at once?

EDIT 13.11: I think ive made it work! Actually all 3 of my issues stated in the inital post are solved i believe. Ill report when i can post again. @E1e5en No need to test my game for now, thanks :slight_smile:

You also shouldn’t be using the same channel for different sound files (in most cases). They’ll overwrite each other. So you’ll want one channel to be used for the Flooote file, and a totally different channel for Vogel kick.

if you’re only getting a click than you have something else overwriting those channels.

Also, even if the default matches what you’re looking for, I always strongly recommend populating all parameters on an event condition/action, otherwise it becomes that much harder to change it later if you need to.