SOLVED Multiple audio listener point

BizonTR

Member
Hi guys, I tried a very basic sound distance effect. For example, when obj_character moves away from the object_gun that has a gun_sound, sound comes to as low volume. Also moves away more, sound doesn't come. Okay that is working like this.

obj_gun (Step Event)
GML:
if instance_exists(obj_character) and (distance_to_object(obj_character))>128{
audio_sound_gain(gun_sound,0,false)
}

if instance_exists(obj_character) and (distance_to_object(obj_character))<128 and 96 < (distance_to_object(obj_character)){
audio_sound_gain(gun_sound,0.25,false)
}

if instance_exists(obj_character) and (distance_to_object(obj_character))<96 and 64 < (distance_to_object(obj_character)){
audio_sound_gain(gun_sound,0.5,false)
}

if instance_exists(obj_character) and (distance_to_object(obj_character))<64 and 32 < (distance_to_object(obj_character)){
audio_sound_gain(gun_sound,0.75,false)
}

if instance_exists(obj_character) and (distance_to_object(obj_character))<32 and 0 < (distance_to_object(obj_character)){
audio_sound_gain(gun_sound,1,false)
}
Okay it's enough for me but I have a problem. If i put only one obj_gun and one obj_character in the room, it is working but if I put two obj_character and one obj_gun in the room, it is not working healthy. The problem is exactly, if obj_gun has 2 obj_character both near and far, I want to hear gun_sound but no sound due to far object. How can i solve that?
 

Tobey

Member
Rather than changing the volume for set distances, you should look into 3D audio. The gun will make a sound with this: audio_play_sound_at(YOUR SOUND, x, y, 0, 500, 1000, 1, true, 2); and then the player object will be an audio listener.

The player listener code:
GML:
///Create event
audio_listener_orientation(0, 1, 0, 0, 0, 1);

///Step event
audio_listener_position(x, y, 0);
Gun audio code:
Code:
///Create event
sound = audio_play_sound_at(sfx_heart_beat, x, y, 0, 500, 1000, 1, true, 2);

///Cleanup event
audio_stop_sound(sound);
This should fix your issue.

Also, PLEASE read the manual for more information about this.
 

BizonTR

Member
I did that but that codes are making the "audio_listener_position" valid for only 1 object now. So, it is working for one obj_character that I put but no for other. If working obj_character destroyed, other one is starting to audio_listener_position. How can I do multiple "audio_listener_position" at the same time for two or more objects? I tried the "audio_listener_set_position" I don't know that I couldn't maybe but it didn't work too.
 

BizonTR

Member
Rather than changing the volume for set distances, you should look into 3D audio. The gun will make a sound with this: audio_play_sound_at(YOUR SOUND, x, y, 0, 500, 1000, 1, true, 2); and then the player object will be an audio listener.

The player listener code:
GML:
///Create event
audio_listener_orientation(0, 1, 0, 0, 0, 1);

///Step event
audio_listener_position(x, y, 0);
Gun audio code:
Code:
///Create event
sound = audio_play_sound_at(sfx_heart_beat, x, y, 0, 500, 1000, 1, true, 2);

///Cleanup event
audio_stop_sound(sound);
This should fix your issue.

Also, PLEASE read the manual for more information about this.
Also in the future maybe I need to use 2 different objects as listeners rather than using the same object multiple times. That's why I need just like multiple "audio_listener_position"
 

Tobey

Member
Also in the future maybe I need to use 2 different objects as listeners rather than using the same object multiple times. That's why I need just like multiple "audio_listener_position"
I haven't tested this but I see no reason why 2 instances of an object that are both listeners wouldn't work.

EDIT: I didn't see the above post. Just try 2 different objects because the docs lead me to believe that you can have 2 listeners
 
Last edited:

BizonTR

Member
I tried but it doesn't work buddy. Does anyone have any different idea? Still I need help...
 
Last edited:

kburkhart84

Firehammer Games
I'd like to know what exactly you are expecting. In a general sense can only be one listener. This makes sense though, a sound can't be both soft and loud at the same time because it is close to one listener and far from another....you'd have to play multiple copies of the sound for that.
 

FoxyOfJungle

Kazan Games
I'd like to know what exactly you are expecting. In a general sense can only be one listener. This makes sense though, a sound can't be both soft and loud at the same time because it is close to one listener and far from another....you'd have to play multiple copies of the sound for that.
Exactly. I believe the OP is forgetting to use audio emitters. You can have 1 listener and infinite audio emitters. And you need to update the emitter position always in Step.
Example:

GML:
// Create Event
audio_emitter = audio_emitter_create();
audio_falloff_set_model(audio_falloff_linear_distance);
audio_emitter_falloff(audio_emitter, 100, 300, 1);
audio_play_sound_on(audio_emitter, snd_sound, true, 100);

// Step Event
audio_emitter_position(audio_emitter, x, y, 0);

// Cleanup
audio_emitter_free(audio_emitter);
 
Last edited:

kburkhart84

Firehammer Games
If the sound doesn't move you don't even need to use emitters for it, you can just play it in 3d space with the alternative one-off function. If the sound moves though, that's when you want the emitter, so you can change it over time as it moves. My audio system(now free) actually does that. You can give it an instance for an emitter and it will follow it around automatically, including setting velocity for that nice doppler.

But my sound system can't get around the 1 listener limitation. That's just the way things are. If you listen on local multiplayer console games(since PC ones are pretty rare), the ones that do split screen have to base sounds off of only one of the players. They typically do workarounds like not having the player's sounds be 3d as much, but things like enemies on the other hand they have to choose a player's position and go with it.

The rare instance where you can have multiple listeners is if the device you are on directly supports using multiple output devices at a time. I honestly don't know what those devices would be, and it certainly isn't going to be your typical PC without some good tweaking done to it. In those cases, it could make sense to have multiple listeners. The same way the game world gets drawn multiple times if you have multiple view, the sounds get "rendered" multiple times for the multiple listeners in those cases. This isn't really something I would ever count on having available unless I was devving for that specific device and really knew ahead of time that it was a thing.
 

BizonTR

Member
@Tobey, @FoxyOfJungle and @kburkhart84 Alright, I guess you don't understand my issue exactly. I'm putting a video here. It is certainly not for earning money. I already set this video unlisted on YouTube. It can only be viewed from this link. I will delete the video after the problem is solved.

 
Last edited:

kburkhart84

Firehammer Games
It's exactly what we have told you. You can't have both white and black squares be listeners of the sound. There can only be one listener. So what is happening is the black square is setting the listener position, and then right after the white square is overriding the position. The step event order for objects is pretty much random/undocumented, so you can't count on which one will be the last one to run.

That is how 3d sound works, you get one listener. You CAN make that listener be the black square instead of the white square. That means that you need some object that determines which one is closer to the sound, and then you set the listener to be on the one square instead of the other square.....but you can't have multiple listeners at the same time. You will have to have the listener bounce around to whatever object is closer to the sound emitter.
 

BizonTR

Member
It's exactly what we have told you. You can't have both white and black squares be listeners of the sound. There can only be one listener. So what is happening is the black square is setting the listener position, and then right after the white square is overriding the position. The step event order for objects is pretty much random/undocumented, so you can't count on which one will be the last one to run.

That is how 3d sound works, you get one listener. You CAN make that listener be the black square instead of the white square. That means that you need some object that determines which one is closer to the sound, and then you set the listener to be on the one square instead of the other square.....but you can't have multiple listeners at the same time. You will have to have the listener bounce around to whatever object is closer to the sound emitter.
Okay then, thanks for the information.
 
Top