Search code examples
androidaudiosoundpool

Create sound less intense when moving from sound source


I'm developing an android application with Augmented Reality. Where we can place different sound sources in planes. When users move away from those objects I want to make the sound less intense according to the distance. I've distance from the sound source but how can I manipulate audio? Is there any good library for working with sound in android or java.

I know a little bit about Doppler Effect where sound source moves from a stationary object when the sound source moves towards stationary object pitch increase on the other hand when moves away then pitch decreases. Does it make sense to use in my case?


Solution

  • I don't know about libraries available in Android. But the basics elements for 3D sound are to taper the volume and add low-pass filtering with distance, as high frequencies drop off more quickly than lows in open air.

    Also, using timing (a small delay calculated from the speed of sound in air and the width of the head) between the left and right channels) is generally preferred over using volume for simulating stereo. As far as Doppler, this only pertains to objects in motion.

    You might check out the Signal Processing and Sound Design areas where I recall related questions occasional come up.

    If the goals are not too ambitious, simply using volume decay with distance and volume-based stereo can get you by if the visual elements strongly reinforce the illusion. But using timing and filtering are more realistic if executed correctly.

    If you decide to roll your own, it's a bit involved, and includes the need to create a framework for mixing audio signals and some good reverberation effects. Reverb is maybe the most cpu-intensive element and lies just over my tech-knowledge horizon--I've only coded primitive versions. Oh, and there is also the aspect of knowing about the location of reflective walls and surfaces in the environment and creating the appropriate echoes. IDK to what extent that has or has not been effectively handled yet--a couple years ago when I was looking into this, a system for handling early reflections in real time as the avatar moves about was mostly theoretical and aspirational.