-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doppler effect #115
base: main
Are you sure you want to change the base?
Doppler effect #115
Conversation
I realized 2 points that I'm gonna address: first the Second, being not familiar with audio I applied the result to the
|
@Roms1383 Dammit, I was going to take this feature :P I too am not a super math audio nerd. I also have not looked at your code in detail yet (and I'm new to Kira). However, having worked on a couple shooters, the doppler effect is best when you can tune it/amplify it per sound emitter. If you look at FMOD they just straight up have a multiplier on it, which isn't all that realistic but I find the effect is very much a stylistic choice more than anything. For some things you will want it toned down, for other things you want it cranked up (usually on projectiles), for things like modern vehicles you'll want it somewhat realistic because we're just so used to hearing it in real life, so there's a certain level of expectation there. Point being, having that control is super important. I will check out the PR tonight. |
@Roms1383 Yes, doppler effect is definitely meant to affect pitch, not volume. I'm not sure what you mean by playback rate affecting volume and pitch...did you mean speed and pitch? If so, I believe a doppler effect should affect both. |
Overall I think the maths are correct, but I didn't apply it to the right parameters (it shouldn't affect the Frame directly, but more like the playback rate currently does). I briefly looked into the playback rate implementation this morning and I'm not sure yet how to proceed because the playback rate is defined on the sounds which are (rightfully) decoupled from Effect. I need more time, and I definitely appreciate your help. |
Maybe look into how oddio does it? |
Hi everybody, sorry for the delay. I took a brief look, but not sure exactly where to do the resampling. @tesselode I didn't get enough time to dig deep into I'm quite overworked atm so @BrianWiz if you want to take over (even reuse ideas / snippets of code) feel free to do so I won't take it personally. Otherwise, I'll keep looking into it at a later point. |
Hey! I'm ready to take a look at this now. @tesselode if I make progress, should I start another PR? Or maybe @Roms1383 would be willing to give me permission to your fork, then I can commit directly onto this branch EDIT: Okay I'm not actually seeing how it's currently affecting the playback rate if at all right now. I've been struggling to actually hear the effect. So I think that's going to be the trick, is getting the playback rate set correctly. EDIT 2: Okay I see that's what you already mentioned |
I totally be willing to ! I just don't know where to set it, could you point me where ? |
@Roms1383 yeah you need to go to your fork in GitHub, then you'll see Settings at the top, and then on the left sidebar, Collaborators. Then you can send an invite from there. |
Done @BrianWiz 👌 |
So I managed to get something working
Example of what I mean: let mut spatial_track = audio_manager
.add_spatial_sub_track(
&listener,
SPATIAL_TRACK_POSITION,
SpatialTrackBuilder::new()
.distances(SpatialTrackDistances {
min_distance: 1.0,
max_distance: 400.0,
})
// NOTE: Even though the doppler effect is enabled, the sound will not be affected by it
// until the listener and the spatial track have set the game loop delta time. See below!
.doppler_effect(true)
)
.unwrap();
loop {
let delta_time = get_frame_time(); // Macroquad's delta time
// this will track the previous position, but not enough, need to divide by delta time to get the correct velocity
listener.set_position(camera_controller.position, Tween::default());
spatial_track.set_position(some_position, Tween::default());
// need to set this every frame unless you're dealing with a fixed timestep
listener.set_game_loop_delta_time(delta_time);
spatial_track.set_game_loop_delta_time(delta_time);
} The other option would be the user has to set the velocity directly, but I figured it's easier for them to set the delta time. Any other way would be a lot more involved I think. The following video uses a speed of sound at 343 m/s 2025-03-04.19-23-07.movedit: @Roms1383 noice! Thank you, code pushed |
// "Sonic boom" | ||
// It may sonic boom at the start of the emitter's life because the previous position | ||
// is 0,0,0 not sure how to get around this, or if it even matters. | ||
// But it would be kind of cool to emit an event when this happens. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what you mention here is what is described in oddio
over POSITION_SMOOTHING_PERIOD and further in set_motion. Hope this helps :)
Fantastic job by the way, I'm super hyped!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing that could solve this particular scenario is on the first time we set position, the previous position is the same. That would make the velocity 0,0,0 on spawn and not cause a sonic boom (I like to pretend it's really causing a sonic boom)
@Roms1383 I think this can probably be moved out of draft and into review |
@BrianWiz Thanks for your work on this! This works pretty well, but I do have a couple thoughts:
|
I'll look into using tweens this weekend! |
Here's my attempt at implementing Doppler effect. I'm by no means a mathematics person, but it sounds right when (briefly) tested. I'm gonna let it as a draft for now, as there's some cool additions I'd like to make.