-
Hi,
float listPosX = 642; int main()
ma_engine_listener_set_cone(&engine, 0, ma_degrees_to_radians_f(15), ma_degrees_to_radians_f(360), 0.0);//No idea what constitutes meaningful values for these.
} Kind regards, Jordan. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
So the cone attenuation is just a very basic mechanism for attenuating sounds based on whether or not a sound is being heard from behind or in front. It is not a replacement for something like HRTF. Most of the time a cone won't actually be needed, and while you're just getting things working at a basic level I would highly suggest that you just ignore it for the time being. But for completeness sake, there are two scenarios off the top of my head where you'd might want to consider setting the cone: the first is on the listener so that sounds behind the listener sound slightly quieter than those in front (again, this is very simple - it's nothing like HRTF); and the second is on a sound that might represent something like a horn where it will sound louder when it's pointed in your direction but quieter if it's pointed away from you. The cone is not the tool you want to be using for the directional perception of a sound, and I think that might be what's causing your confusion here. The default angle is 360 degrees for both the inner and outer cone which means there is no cone attenuation happening at all by default. When the sound is being heard from inside the inner cone, the sound will not have any cone attenuation applied. When the sound is being heard from the outer cone it will have the attenuation that you specified with For your second point, the cone will not help you at all when it comes to the perception of a sound's direction. The relative position between the sound source and the listener is the only thing that controls the directional perception of a sound. For your third point, this is a finicky one because it's all about the attenuation model being used and the scale of your coordinate system. It's something you'll need to fiddle with a bit. I can tell you that with default settings, 500 units is gigantic. Sounds at that distance will be totally imperceptible. The function you'll want to use is Alternatively, you can set the attenuation model to linear which will give you a simpler model. This will allow you to assign a radius to a sound, but comes at the expense of a less physically accurate attenuation. This may still work well enough for your game though. In this case, when the listener is at the edge of the sound's radius, the volume will be exactly 0. When the listener is at the dead centre of the sound (or the value you set with With your code, make sure your coordinate system matches with miniaudio. The Y axis is up and down, and the Z axis is in and out. Negative Z is into the screen. Also, the sound direction will have little impact on anything here. As a starting point while you get things working, just focus on the position of the sound and ignore it's direction. If the position of the sound and the listener at on top of each other you will not get any directional perception. As soon as you move the sound to the left or right of the listener you'll start to perceive the direction. If you position the sound like the code below you should hear something come predominately from the left speaker and a little on the right:
Also, it looks like you're trying to rotate around the Y axis by setting the Y direction to 45 degrees. That's incorrect - the direction is specified as a direction vector, not an axis rotation. So a 45 degree rotation around the Y axis would actually be something like this:
Hopefully that helps get you started. |
Beta Was this translation helpful? Give feedback.
-
Hi, Thank you very much; I'm starting to get the hang of this. |
Beta Was this translation helpful? Give feedback.
-
Here is a code example that demonstrates what I'm talking about. I even have rolloff set to exponential. Rolloff is 1.0, min and max gain are 0.0 and 1.0 respectively. Max distance is 500, but the listener is 6000 units away from the sound; the attenuation flatlines at some point and it doesn't matter how much further you move away, it never gets any quieter. #include float listPosX = 642; int main()
} |
Beta Was this translation helpful? Give feedback.
-
Sorry for the triple post. I wanted to correct something else I had stated. The value 5.5 is not actually the distance covered by Link's footstep. It is actually Link's linear velocity. The game runs at 20 frames per second, and Link travels approximately this distance every frame. So he moves roughly 110 units per second. |
Beta Was this translation helpful? Give feedback.
-
min and max distances are always uses by all attenuation models. When calculating the attenuation, it takes the distance between the listener and the sound, and then clamps that distance between min_distance and max_distance before doing the calculations. The flatlining you mentioned sounds consistent with the distance getting clamped, and based on your description sounds exactly like I'd expect. The maximum distance is set to 500, but the distance between the sound and the player is 6000. That means your distance of 6000 will be clamped to 500 when doing the attenuation. I would ignore max distance for now - I don't think it will help you with what you're trying to achieve, at least with non-linear attenuation (for linear attenuation you'll need to use it to define your sound radius). Also keep in mind that the inverse and exponential models will never result in a sound being absolute silence, but it'll get quiet enough that it'll become imperceptible. I tested just now, and at 100 units away with default settings, the sound will just barely be audible - you need to really focus to be able to hear it. I did some testing now, and here's some suggestions for you to as a starting point:
That should give you a workable starting point. |
Beta Was this translation helpful? Give feedback.
So the cone attenuation is just a very basic mechanism for attenuating sounds based on whether or not a sound is being heard from behind or in front. It is not a replacement for something like HRTF. Most of the time a cone won't actually be needed, and while you're just getting things working at a basic level I would highly suggest that you just ignore it for the time being. But for completeness sake, there are two scenarios off the top of my head where you'd might want to consider setting the cone: the first is on the listener so that sounds behind the listener sound slightly quieter than those in front (again, this is very simple - it's nothing like HRTF); and the second is on a sound t…