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

Options
cs5947
cs5947 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.

«1

Comments

  • Kubrak
    Kubrak Member Posts: 2,789 Expert
    Options

    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.

  • ANDREW221231
    ANDREW221231 Member Posts: 299 Advisor
    edited March 2023
    Options

    @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/

  • Kubrak
    Kubrak Member Posts: 2,789 Expert
    Options
  • colB
    colB Member Posts: 821 Guru
    Options

    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
    
  • Kubrak
    Kubrak Member Posts: 2,789 Expert
    edited March 2023
    Options

    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.

  • colB
    colB Member Posts: 821 Guru
    Options

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

  • Paule
    Paule Member Posts: 1,328 Expert
    Options

    Is it something like Absynths Pipe effect?


  • Laureano Lopez
    Laureano Lopez Member Posts: 102 Advisor
    edited March 2023
    Options

    . . . . . .

  • ANDREW221231
    ANDREW221231 Member Posts: 299 Advisor
    Options
  • colB
    colB Member Posts: 821 Guru
    Options

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

  • ANDREW221231
    ANDREW221231 Member Posts: 299 Advisor
    Options

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

  • Kubrak
    Kubrak Member Posts: 2,789 Expert
    Options

    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.

  • colB
    colB Member Posts: 821 Guru
    Options

    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...

  • Kubrak
    Kubrak Member Posts: 2,789 Expert
    Options

    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.

  • Laureano Lopez
    Laureano Lopez Member Posts: 102 Advisor
    edited March 2023
    Options

    Sorry, I thought it was too long and didn't have the time to revise it... It's annoying not being able to actually delete comments though -.-

    Hmm iirc he said the sound pressure was 1/d but there was some other thing that was 1/d^2

    Yep, sound intensity is inv. proportional to the squared distance but sound pressure only to the linear distance, and the amplitude of an audio signal represents pressure.

    it was about power to four and to 1/4 after that

    I used d' = (d^4+min^4)^(1/4) on the plain distance d = (x^2+y^2)^(1/2), which turns zero into min with a soft curve and fast convergence. Simplifying d into d' gives ((x^2+y^2)^2+min^4)^(1/4), which is the actual code in the distance | abs macro. Gain is then computed as min/d' to have unity gain at min distance.

Back To Top