How do I create Doppler Effects for Sound

Get help using Construct 2

Post » Sat Jan 23, 2016 7:27 am

Hey guys,

I've been reading on the forum and the whole internet about how easy it was to implement Doppler effects with sound. Then I read it was removed due to some google update (thanks so much for making life hard, google!) Even though this feature is no longer something that can be done using a pre-made construct 2 feature, is it possible to create a doppler sound and how can this be accomplished?

Reason I am asking is because my game is going to rely on this effect to help make it reeaaaaaaallly cool with sound.

Thanks for your help!
B
11
S
3
G
2
Posts: 35
Reputation: 1,809

Post » Sat Jan 23, 2016 10:32 pm

Wikipedia gives the equation for the doppler effect. Basically it's to change the frequency of the sound based on the speeds of the source and the listener.

The speeds need to be relative between the objects. For the source for example:

ang = angle(source.x,source.y,listener.x,listener.y)
speedsource = source.velocityX*cos(ang) + source.velocityY*sin(ang)

The listener speed is about the same but uses it's speed instead and the ang is from the listener to the source.

The frequency is calculated with:
(speedofsound + listenerspeed)/(speedofsound + sourcespeed)

"speedofsound" is something you can tweak, I used something like 3400 to make the effect more subtle.
Use the frequency to set the playback speed.

Here's an experiment of it. In it I used positional sound and some volume fade off.
https://dl.dropboxusercontent.com/u/542 ... ppler.capx
B
89
S
30
G
95
Posts: 5,155
Reputation: 63,446

Post » Sat Feb 06, 2016 1:32 am

Hello R0j0hound,

I apologise for taking so long to respond. I have had to work on other problems first before coming back to this.

I am trying to iron out some issues, but you really helped put me in the right direction. Thank you so much for your help, I could not have implemented this appropriately for my game without your help!
B
11
S
3
G
2
Posts: 35
Reputation: 1,809

Post » Sat Feb 06, 2016 9:03 pm

No problem. It was fun to make.
B
89
S
30
G
95
Posts: 5,155
Reputation: 63,446


Return to How do I....?

Who is online

Users browsing this forum: Ajbael, ColombageEnPLS and 9 guests