So I’m trying to simulate river sounds in Unity 3D (version 2020.3.19). It’s an known issue with FMOD that it only supports point source.
The dumbest way is, of course, to get a number of sound emitters and line them up together, forming a line. That is too cumbersome, however.
After some research I decided to draw a spline and have the sound emitter follows the player when the player is within audible distance based on the closest point on the line to the current position of the player.
So far it works, kinda. It has one big issue though.
When the river, or the spline takes a sharp turn geographically. Even just one pixel (I’m exaggerating for the sake of argument) can make the sound emitter to jump from one place on the spline to another, creating this abrupt change in the perceived location of the sound source.
For example:
The illustration above shows the top-down view of a 3D space. The blue line represents the river; the red dots represent the sound source respectively; and the green dots represent the current position of the player at different time.
From this illustration we can see the problem very easily. When I move from green dot 1 to green dot the sound source (the red dot) will jump all the way from the left position to the right. Theoratically, yes, the red dot on the right is indeed the closest point to the current player position (represented by the green dot on the right). The actual change was so little and yet the output changed so radically. In other words, there has to be a way to soften this transition.
Here is a solution that I came up with. See the illustration below:
The player now has a circle area of hearing. When the circle (represented with black line) intersects with the river (represented with blue line), it gives back the locations of point A and point B. Then it calculates the angle between APB (represented with letter ‘theta’). Then set the spread angle to that number. This means that I need to be able to access and modify the spread value of a sound within FMOD to do it dynamically.
This would hypothetically solve the problem I raised previously. See the illustration:
However, here comes another problem with this solution I gave. See the illustration below:
This is a more complicated situation, but very well possible in realistic environments. This little stream has a lot of twists and turns. Where should the sound emitter be when the player is literally surrounded by river streams? Theoratically, the player should be hearing sounds from all direction. However, under this situation it is not useful at all.
After doing some more research, I came across this video online in which two audio engineers from a huge studio (it was a studio from EA iirc, but I’m not sure) demonstrate a solution they had. See the illustration below:
They used raycast to implement this. Since I’m not very familiar with programming I’ll try my best to explain it.
The idea is that the river cuts the rays off at their intersections, creating multiple sections of river that should be audible for the player. Then spawn a sound emitter and attach it onto every intersection.
So here are my questions:
-
How is my solution? Is there a better solution?
-
How do I access the angle of spread in FMOD through codes in Unity in realtime?
-
Looking at the solution the pros gave, how do I accomplish this through code? I imagine I would have to access the FMOD api, how do I do that?