GameMaker Sound Tutorials

E

Elgarion

Guest
Hello dear fellow developers!

Recently, the clunky sound system I spent days to develop seem to have been quite broken, probably by an update, (or maybe it just collapsed under the weight of my bad practice ^^).

I just spent some time looking for decent & recent sound tutorials (3D, emiters, general sound handling, etc.). I've got some in youtube, but very incomplete and frustrating (and most of them seemed too basic for my needs); that's all...

Do you know where I can find any complete ressource, with examples, for the way the sound is handled in GMS 2 ?
 

Yal

🐧 *penguin noises*
GMC Elder
How about answering your implicit question instead, perhaps... what does your sound system need to do? It might not be that complicated after all... (or it might be, kinda hard to tell unless you tell us what you want to do)
 
E

Elgarion

Guest
Thank you for you kind words @Yal . I'm gonna try to fix it by myself using the doc, as @johnwo said. If I'm still not satisfied with my work in a few day I will come back here to seek some help from you and others. It's about distance, sounds that should be heard and are not (and were before some point, which is strange, that's why I think about some GM update, because once settled I didn't touched the sound area).
 

Yal

🐧 *penguin noises*
GMC Elder
Oh, in that case I think I know what you wanna do.

To play a sound, do something like this:

Code:
///sfx_position(sound,x,y)
var n = audio_play_sound_at(argument0,argument1,argument2,0,VIEW_H*0.5,VIEW_W,1,false,10);
//use the variable "n" to apply effects like a global volume option here if you want
return n;
Have your player do this every step:
Code:
//Positional audio
audio_listener_position(x,y,0)
audio_listener_orientation(x,y,1000,0,-1,0)
audio_listener_velocity(xspeed,yspeed,0)

This is copypasted from a project I'm working on atm so replace the constants with whatever values work in your project. It's surprisingly easy to use play_sound_at to play the sound at a position in 3D space, the tricky bit is that the listener orientation defaults to upside-down. Also, this was for a 2D project so note that the z coordinate is zero everywhere.
 
E

Elgarion

Guest
Thank you @Yal !
My problem is that I melt some old GMS1 code of mine with some 3D from GMS2, so everything was clumsy.

I have to clean everything up. Will use your piece of code and modernize my own code.

Have a nice day !
 
Last edited by a moderator:
E

Elgarion

Guest
Okay... my dear @Yal (or any other good soul of the forum) I need your help ! :'(

I want my sound to fade in, fade out, depending on the position of the listener and an emitter. Things are settled for a top down game, ie objects on the left of my listener must make noise on the left, objects on the right of my listener must make noise at the right.

Here is my (basic) setting for testing purpose :

--- Obj_Listener

Create :
Code:
audio_listener_orientation(0,1,0,0,0,1);

Step :
Code:
x = mouse_x ;
y = mouse_y ;
audio_listener_position(x,y,0);
--- Obj_Emitter :

Create :
Code:
audio_play_sound_at(sound0, x, y, 0, 100, 300, 1, true, 1);

It's not subtle but it seems to work, except that I can't get any fade out / fade in. I've already tried things with audio_play_sound_on, etc, but it gives similar results with more complex settings (and I try to avoid that if possible ^^).

I've made a script which modify volume gain depending on the distance, but it's far from perfect and I would prefer a simplier setting.
 
Last edited by a moderator:

Yal

🐧 *penguin noises*
GMC Elder
I'm pretty sure these two lines were in the step event for a reason:
Code:
audio_listener_orientation(x,y,1000,0,-1,0)
audio_listener_velocity(xspeed,yspeed,0)
I don't remember if _velocity() was necessary for sound to be positional at all or if it just affected doppler things when moving past a sound source quickly, but it probably can't HURT to use it. And you use completely different orientation settings, this might also screw with things (the ones I use are for using only the XY plane and not the Z axis).
 
E

Elgarion

Guest
I'm pretty sure these two lines were in the step event for a reason:
Code:
audio_listener_orientation(x,y,1000,0,-1,0)
audio_listener_velocity(xspeed,yspeed,0)
I don't remember if _velocity() was necessary for sound to be positional at all or if it just affected doppler things when moving past a sound source quickly, but it probably can't HURT to use it. And you use completely different orientation settings, this might also screw with things (the ones I use are for using only the XY plane and not the Z axis).
Yep, just after posting I told myself that I should have used pricesely your entire setting before calling for help (I cleaned up mine, using your 'sound_at'). I feel stupid ! Thank you for your answer, I will test all this. I'll post a feedback here when I'm done. Thanks again !
 
E

Elgarion

Guest
@Yal, I made some experiments and I thought you could be interested in the result.

For a top-down view, in the create of the player (no need for it to be called each time in the step event, if it doesn't change it's orientation) :
Code:
audio_listener_orientation(0,0,1000,0,-1,0); // if orientation changes while in-game, put it in the step. In my case, no.
audio_falloff_set_model(audio_falloff_exponent_distance); // it appears to be hugely important
In the step, only :
Code:
audio_listener_position(x,y,0)
It's working very well, provided you play a litlle with the drop off values. For my object emitter, I just put in the step :
Code:
if !audio_is_playing(sound0)
   {
   audio_play_sound_at(sound0,x,y,0,30,200,1,true,10);
   };
Thank you for your answers and your patience.
 
  • Like
Reactions: Yal
Top