# How do I create Doppler Effects for Sound

Get help using Construct 2

### » 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
16
S
5
G
2
Posts: 54
Reputation: 2,183

### » 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.
examples31/doppler.capx
https://www.dropbox.com/s/sfs9uqb7vy9bo ... .capx?dl=1
Last edited by R0J0hound on Thu Nov 09, 2017 2:26 am, edited 1 time in total.
B
100
S
38
G
134
Posts: 5,551
Reputation: 85,315

### » 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
16
S
5
G
2
Posts: 54
Reputation: 2,183

### » Sat Feb 06, 2016 9:03 pm

No problem. It was fun to make.
B
100
S
38
G
134
Posts: 5,551
Reputation: 85,315

### » Thu Nov 09, 2017 12:05 am

Wouldn't still have that source around would you? It would save a bit of time...
B
253
S
65
G
34
Posts: 907
Reputation: 41,569

### » Thu Nov 09, 2017 2:27 am

@paradox
Updated link in post
B
100
S
38
G
134
Posts: 5,551
Reputation: 85,315

### » Thu Nov 09, 2017 4:35 am

Since this post is about audio effects, is there any way to do Pitch?
I want to add a bit of variation to repeating sounds in my game.
I know I can create and upload different versions of the same sound, but I hope there is an easier solution.

The closest effect I could find that does something similar is "Ring modulator", but it doesn't work well with some sounds.
Changing playback rate is also not a good option.

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
155
Posts: 2,199
Reputation: 82,479

### » Thu Nov 09, 2017 7:50 am

Changing the playback rate works to change pitch. I've used it to make a piano from one sound. I guess a drawback is the length of the sound changes too, but there isn't another way to change pitch.
B
100
S
38
G
134
Posts: 5,551
Reputation: 85,315

Return to How do I....?

### Who is online

Users browsing this forum: MaxM, ultrafop and 6 guests