New Audio API Features: Directional Audio, AudioLimiter and More

Hey @Nogalo, under the hood SoundService:PlayLocalSound behaves the same way as Sound.PlayOnRemove – both of these create & play hidden, internal copies of a sound, which don’t get surfaced to the DataModel – we don’t plan to add anything similar to the new audio API

Although the copied playbacks are engine-internal, they don’t offer many discernible perf benefits over playing a Sound from a LocalScript and :Destroying it once it has Ended – on the other hand, since the internal copies aren’t controlled by any instance, these APIs have been something of a supermagnet for bugs :sweat_smile:

6 Likes

Man Rohlox really be cooking with features.

This Right here is pretty epic and calls for alot of cool Effects.

This is what I love the most.

5 Likes

all i need is the AudioAnalyzer.WindowSize property so i can make a good visualizer :pray: 512 window isn’t enough for an accurate visualizer, but still works just fine.

3 Likes

This is pretty cool and it will be a great feature for horror games.

2 Likes

Love that audio is getting even more awesome! Kudo’s to everyone working on making it that way.

One thing I would absolutely LOVE to see added to this is the ability to get the left/right channels of audio listeners and/or be able to attenuate the directionality of them separately.

3 Likes

The angle attenuation is awesome!


I brought up another suggestion in an existing post, but I would like to reiterate it here more clearly. This example is similar to an issue I faced when working with the new audio API.

Let’s say I want to make a top-down game where the camera is locked to some orientation but the character it looks at can move around freely. I want sounds to be heard spatially so I add an AudioListener to the character’s root part. However, this does not work. If a sound is heard from the right while the character is facing a direction, then they turn around the sound will now be heard from the other ear. This switch contradicts how the camera is oriented and leads to incorrect spatial sounds.

A hacky solution is to set the cframe of some part or attachment to match the position of the character, but maintain some orientation (updated each frame). Then add the AudioListener to that.

Instead, it would be convenient to have a property maybe “AlignmentMode”. If this property is set to an enum called “Parent” the AudioListener would listen as it does currently; the orientation matches the parent. Another mode “Global” could be added to force the orientation/alignment to a certain direction.

4 Likes

@jonbyte we’ve run into the same thing and factored that into the behavior of SoundService.DefaultListenerLocation – when that’s set to Character, an Attachment is created on your character that faces the same direction as Workspace.CurrentCamera.

So the listener uses your character’s position but your camera’s orientation

5 Likes

Oh gotcha, had to read that part again. I’ll see if it fixes the issue in my project. Sounds like it will. Thanks!

3 Likes

Great examples! I do have to ask though, all the features seem to work in the 2D over-head view great, but does this work in 3D as well? The documentation is fine, but I don’t understand if this would allow me to create an audio emitter that is limited in height? Say, I have a building with 2 floors and I don’t want sounds on the 1st floor to be heard by players on the 2nd floor but I want to make sure the players on the 1st floor can hear the audio just fine without the bleed through the floors. Am I asking the right question? :sweat_smile:

5 Likes

So that is where you use the DistanceAttenuation for. With the Direction audio support we can make a speaker that only fires sound in a certain direction.

So let’s take your example of a building with 2 floors, and you don’t want the sounds of the 1st floor to be heard by the people on the 2nd floor

  • Create an invisible floor part, add an AudioEmitter to this invisible floor, and wire that to an AudioPlayer using a ‘Wire’ instance. Now we got an Player > Speaker setup
  • Using AngleAttenuation we now make sure that the sound only plays ‘up’ wards, and not downwards. Because else you get ‘leaking’ sounds in the basement!
  • Using DistanceAttenuation we can now limit the ‘Distance’ that the sound travels. We simple set our ‘Min’ to 0, 1 (Which means at 0 we want to have 100% volume), and then at our ceiling cap we want to hear 0% volume. So that is CEILING_HEIGHT, 0

See the attached example file, simple go to the radio and press play :slight_smile:
The magic happens within the AudioEmitter instance, which is located underneath the Floorspeaker in the workspace.

AudioExampleTest.rbxl (96.1 KB)

3 Likes

I think what they were talking about and I am also confused about now is: there is only one angle value so how would you specify it upwards but not downwards.

Building on my last point, this isn’t clear on how it would work with only one angle value.

The usage of angle in the video makes sense somewhat, but I think it there may be some confusion around it. Can you clarify?

3 Likes

Hi! So we basically do that in the ‘AngleAttenuation’ dialog. We basically define in which angles the sound is at 1 volume, and at which the sound is at 0% volume.

So if we take a look at the example below we are basically cutting out everything on the ‘Back’ portion of the sound by simple setting their volume to 0.

3 Likes

My confusion is how a single angle translates to 3d emittance. For it to make sense I think there would need to either be 2 angles for spherical coordinates or some steradian value. One radian angle can only be based around one axis in space.

The angle attenuation curve can filter based on direction but since there is only one angle it seems this would only be possible along one axis (not clear which axis as well).

If you can clarify how you might use the angle attenuation to emit up but not down and then something like right but not left or vice versa that would be helpful.


Side Note: Perhaps a 3D visualization to supplement the angle attenuation window would help? Think of how lights can have a wireframe showing the space they illuminate, without it, the range and angle bounds are not exactly clear.

4 Likes

So, think about it like this:

The angle used for AngleAttenuation is relative to the direction of the part’s front and back faces.

So - if the “front” of your part is pointing upwards, then the front angle of the AngleAttenuation is pointing upwards as well. Though, because this doesn’t have a 3 dimensional sense of angles, it means that you have to be very peculiar about how you position your audio emitters.

So, basically, in engine, this pink side is the bottom side, and the white side is the top side. So here, I have rotated the part so that the bottom side is facing me, and then I rotate it so that the top is facing me, and I may hear the sound again.

(The place here is the one made by @Velibor up here)

So yeah, you can only do 2 axises at a time under AngleAttenuation. Maybe you could do a hacky solution for 3D axises by using multiple audio emitters? Also having a 3D space visualization for this would be extremely helpful.

6 Likes

Oh gotcha. Before I just wasn’t sure which axis it was relative to but you clarified it. Do you also know if the radial pattern is the same along the up-axis but fades based on distance attenuation?

If so, the example of a sound only being played on one floor only really works in the case of vertical filtering. Unless you painstakingly match the distance attenuation to the size of the room and even then a complete solution couldn’t be achieved without volumetric audio.

What we are talking about is somewhat related to my idea of AlignmentMode (doesn’t have to be called that). The idea is emittance or the listener equivalent word would be explicitly defined for each emitter or listener. For example, by default the AlignmentMode might be Parent or Inherit and then you might choose which axis of the parent cframe it is oriented with. Currently, the DefaultListenerLocation solves one issue related to this when the camera is separated from the character, but that is not a general solution. It would remove the implicit orientation assumptions with the current implementation.

4 Likes

Thanks for all the work to answer my question, it’s really appreciated.

So, this would work well for an object that was on the floor “emitting” sound, aimed at the ceiling, the waveform could be like a semi-circle so that players can hear it in the room around it, but underneath it for example, players on the floor underneath would Not hear it and as long as I set the distance right, players on the floor above would also “not” hear the sound to give the illusion of “sound” blocking floors?

My only other question would be, is this effect mobile and travel with the part? :thinking:

3 Likes

Yes, the effect would travel with the part. You can either do this in Studio, or during runtime.
Please see the details provided by @YuNoGuy123.

The angle is based on the front and back direction of the 3D object. So for example if you rotate your part 180 degrees you will hear nothing :wink: So let’s say we rotate the surface to the top, and align it there. We now need to also flip the angles.

5 Likes

Thanks for all the technical info, that solves a long standing issue I’ve had with floors leaking sound from each other since the sound objects radiate in a sphere. :+1:

5 Likes

that would lack some accuracy and be more complex for meshparts… not even considering the performance implications if your using this for alot of objects

would love to see a built in method to do this return!

1 Like

that would lack some accuracy and be more complex for meshparts

There is a BasePart:GetClosestPointOnSurface method, which can be used to implement the getRandomPointInPart function pretty elegantly; and that works for all part shapes!

To date, volumetric sound has only been implemented for simple shapes like Blocks, Balls, and Cylinders – if we extended it to meshes, we’d probably end up doing something similar under the hood

This does encounter sampling error, but AudioEmitters themselves are pretty cheap, so you can use a lot :sweat_smile:

2 Likes