# Simulating a moving sound source perceived by a listener on a 2d plane.

Member Posts: 28 Member

I want to simulate a basic moving sound source and a ‘microphone’ on a 2-dimensional Cartesian plane. The plane will range from, say, -10 to 10 on both axes, and the sound source/listener will both be somewhere along those lines.

Then I want to be able to calculate the perceived amplitude and Doppler effect when the sound source moves away from, or closer to the microphone, in both directions.

Doing the Doppler effect is a piece of cake, I use a delay line and change the time of the delay to change the wavelength of the sound.

The problem that I’ve run into is that I don’t know how to do the AM math. I’ve came up with this formula for amplitude modulation across a single direction

```Amplitude = 1 / (Sound position - Ear position)
```

This works okay-ish with the case I’ve demonstrated but the closer it gets to the sound source, the higher risk it is at to explode. This is because the result of (Sound position - Ear position) gets closer to 0 the closer they are in values, and 1 div 0 is theoretically infinity, which is just interpreted as 0 by Reaktor.

When I try to do this along 2 axes, with both the sound emitter and the microphone having 2 values corresponding to the X and Y axes, it doesn’t work as intended.

I want to do the same thing that game engines like Unity do to manage sound AM, but across a 2-dimensional plane and in Reaktor.

Tagged:
«1

• Member Posts: 2,766 Expert

I would add small number into the bracket, than it would not go to 0 in any case. Maybe adding 1 would be sound. It would mean, that xy plane is 1 m away from listener/source.

edited March 2023

@Laureano Lopez doesn't your project in the UL kinda deal with that?

https://www.native-instruments.com/en/reaktor-community/reaktor-user-library/entry/show/14421/

• Member Posts: 2,766 Expert

Maybe this helps.

• Member Posts: 756 Guru

Pretty sure the energy drops off with the square of the distance not just linearly (Could be the cube?)... you'll probably need to scale the volume, and add that minimum offset as suggested by kubrak...

```Amplitude = 1 / (minimum + Sound position - Ear position) ^ 2﻿
```
• Member Posts: 2,766 Expert
edited March 2023

It is second order, I forgot mention that earlier, also...

Amplitude = 1 /(minimum + (s1-l1)^2+(s2-I2)^2) where s1,s2 are coordinates of source and I1,I2 coords of listener.

--------------------

The distance of source and listener is sqrt( (s1-l1)^2+(s2-I2)^2 ) .... euclides

So squared it is (s1-l1)^2+(s2-I2)^2.

• Member Posts: 756 Guru

And don't forget there are two listeners at different positions... left ear and right ear!

• Member Posts: 1,328 Expert

Is it something like Absynths Pipe effect?

edited March 2023

. . . . . .

I am sad that laureano lopez redacted his comment

• Member Posts: 756 Guru

It is annoying though when you put the effort in and the op doesn't respond

agreed. but it was a wonderful response and it was gone before I was able to draft a reply :/

• Member Posts: 2,766 Expert

I agree, it is a pitty. Generally it was that the amplitude is proportional to 1/d and not to 1/d^2 as we thought.

And he had smart solution to smooth aproaching to limiting distance. Do not remember well, but it was about power to four and to 1/4 after that.

• Member Posts: 756 Guru

Hmm iirc he said the sound pressure was 1/d but there was some other thing that was 1/d^2... can't remember exactly what is was though...

• Member Posts: 2,766 Expert

Yes, but if I remember it correctly in this doppler case it should be 1/d. Otherwise it would not be 4th root of sum of powers of four. It would be squareroot of powers of four.

Sorry, I do not know the exact mathematical terms in english.