• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED [LEGACY GM] Audio group volume doesn't change as expected when using audio listener

G

Gojisaurus_Rex

Guest
I'm working in a test project in GMS 1.4.9999 to try to figure out how to properly set up my audio system before I implement it into my main project. More specifically, it involves positional audio in 2D via an audio listener while also letting you change the overall volume of the sounds in the settings, which I could only get to work at the same time by using an audio group (which admittedly was probably a more effective method than what I originally tried to do anyways, but I didn't realize audio groups were a thing at the time).

Here's the issue: when the project first loads up, the volume changing seems to work fine. However, moving the camera causes the audio to mess up. Let me clarify: The test project has a camera that is moved with the arrow keys, and it starts out on top of an object in the middle of the room that makes a sound coming from it whenever the space bar is pressed. Page Up/Down change the volume of the sound (and by that I mean the audio group it plays from), and the audio listener follows the camera. The volume changing works fine while the camera is in the initial spot on top of the object that makes the sound play, but as soon as it moves it starts not changing the volume at all for gain values between 1 and 0.5. Once going below 0.5, it starts decreasing as if 0.5 is 1, although 0 is still 0.

I'll post the code below. There are really only two objects in the room, the camera object (obj_cam) and the sound object (obj_3dsound). The camera object only moves around, the sound object does literally everything else. For that reason, all the code will be from that object. I don't know if I set up something wrong or if this is a bug with GameMaker or what. I'm not the best with programming audio stuff, so I wouldn't be surprised if it was the former.

The audio listener I'm using is called "audiolistener_test", and it only contains the sound "snd_3d".

obj_3dsound code below

Create Event:
GML:
audio_group_load(audiogroup_test) //set up audio group (gets error attempting to call default one at any point for some reason)
audio_listener_orientation(0,1,0,0,0,1) //setting up listener for positional audio
audio_listener_position(x,y,0)
audio_falloff_set_model(audio_falloff_exponent_distance)
volume_setting = 1
Step Event:
GML:
audio_listener_position(obj_cam.x,obj_cam.y,0) //updates listener with camera movement
Draw GUI Event:
GML:
//debug text
draw_text(10,10,volume_setting)
draw_text(10,20,string(audio_group_is_loaded(audiogroup_test)))
Press Space Event:
GML:
audio_group_set_gain(audiogroup_test,volume_setting,0) //set audio group volume
audio_play_sound_at(snd_3d,x,y,0,750,1000,1,false,1)
Press Page Up Event:
GML:
volume_setting += 0.1
Press Page Down Event:
GML:
volume_setting -= 0.1
For obj_cam, it's just four events for holding the different arrow keys which each do x += 1, x-= 1, y += 1, and y -= 1.
 
Last edited by a moderator:
G

Gojisaurus_Rex

Guest
bumping cause rules say to bump if still having issues and that I am
 
G

Gojisaurus_Rex

Guest
sound still broke, tried it with other audio groups and sounds and it generally isn't that different
 
G

Gojisaurus_Rex

Guest
Ok I just solved my problem. I'm pretty sure it was because of how the different falloff models worked. For the exponent graph (the one I was currently testing with) I took a good look at the graphs in the manual and saw the space between distance 0 and where the red line actually started, explaining why the volume changing was different when I had some distance as opposed to when I didn't. I saw that the blue line for the clamped version started right at distance 0, so I set the falloff model to audio_falloff_exponent_distance_clamped and that solved the problem!
 
Top