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:
Step Event:
Draw GUI Event:
Press Space Event:
Press Page Up Event:
Press Page Down Event:
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.
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
GML:
audio_listener_position(obj_cam.x,obj_cam.y,0) //updates listener with camera movement
GML:
//debug text
draw_text(10,10,volume_setting)
draw_text(10,20,string(audio_group_is_loaded(audiogroup_test)))
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)
GML:
volume_setting += 0.1
GML:
volume_setting -= 0.1
Last edited by a moderator: