On Wed May 10 09:58:07 2023 +0000, Florian Will wrote:
Thanks Anton! Never noticed doppler effect was missing from wine dsound before seeing this MR, but now I always notice it in Zusi 3. I don't know a lot about sound programming, but the general approach in this MR might be different from Windows because it changes the pitch by speeding up sound playback, i.e. increasing the buffer sampling frequency. While wondering about the consequences of changing the freq, I modified the test code a bit: Remove the DSBPLAY_LOOPING flag, increase the sleep duration after starting playback to 1200ms, and change the 3D buffer's velocity to -350 / +350 instead of -90 / +90, so that it's easier to notice the effect. Now this MR results in just a very short "blip" for the high-pitched case and a longer-than-600ms sound for the other case (isn't this similar to what actually happens in the real world, too?). On Windows, the same test appears to result in 600ms sounds in both cases, but with a pitch applied. So I believe the general approach may need to be changed, so that sound buffers have a higher/lower pitch when doppler effect applies, but the read position should still progress at the same speed as without doppler effect. As I said, I don't really know a lot about sound programming, so I'm not really sure how that is possible, but it appears to happen on Windows. It would be interesting to test this with an actual sound file (like a siren) and see if Windows really doesn't speed it up when applying the doppler effect, maybe something in my test mislead me? Maybe this isn't an issue in real-world applications at all, in which case this MR would improve the wine status quo.
Thanks for the feedback.
I did some more testing to try and reproduce the pitch shifting behavior, but it turns out not to be the case. I modified wave_generate_la() to change the sine wave pitch over time (like a car alarm), and what I see is that Windows just speeds up the sound playback.
I also tried to reproduce your results and yes, I got the short blip with this MR and a longer tone on Windows. Notice also that the blip has a much higher pitch. I think that the difference is caused by Windows limiting the Doppler effect to half the speed of sound, so +-350 becomes +-180. There is a patch that adds this limit in the development branch: https://gitlab.winehq.org/baskanov/wine/-/commits/dsound-doppler/