godot: WASAPI audio driver produces ringing artifact when project's bit rate doesn't match device's sample rate

Godot version: 3.2.4-rc3 3.2.3-stable (*)

OS/device including version: Windows 10, 64 bit WASAPI audio driver tested on: laptop speakers with 3.5mm headphones; Steelseries Arctis 7 headphones

Issue description: When mix rate property in Project Settings (which defaults to 44100 Hz) is different from current audio device’s sample rate setting in Windows Sound Control Panel (which, for my 2 devices I tested on, defaults to 48000 Hz), you can hear a ringing effect in any audio played in Godot. The ringing is more noticeable when playing low-end frequencies. This happens with WAV, OGG, and as of 3.2.4, MP3.

I have also tried to set devices to 44100 Hz and Godot to 48000 Hz, with same results. Setting both to either 44100 Hz or 48000 Hz removes the ringing.

I also tested samples with sample rate set to 44100 Hz and 48000 Hz, but they don’t make any difference for this issue.

Here is the video demonstrating the issue (listen with headphones to hear low-end frequencies better):

https://user-images.githubusercontent.com/26509794/109671975-d979e800-7b74-11eb-8dbf-eaf3f246a21c.mp4

I played these samples in FL Studio, VLC, and Audacity, and they all sound the same.

In case it is expected that Godot’s and device’s sample rates should match, shouldn’t that be automatic? The tooltip for Mix Rate setting says: In general, it's better to not touch this and leave it to the host operating system. so I’d assume the audio should play just fine with all defaults.

This is a continuation of #23544. CC @Zylann @marcelofg55 @akien-mga

Steps to reproduce:

Try playing audio samples provided below in the minimal reproduction project. You don’t need a node, just play them from the editor.

Mix Rate setting in Godot is located in Project Settings > audio/mix_rate.

Device sample rate in Windows 10 is located in Settings > System > Sound > Sound Control Panel. Double-click your device, go to Advanced tab, and you should see your device’s sample rate:

nav2

(*) note that on 3.2.3-stable, you can hear this ringing for OGG even with matching sample rates. #46086 fixes this issue and is merged in 3.2.4-rc3.

Minimal reproduction project:

godot_wasapi_ringing.zip

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 18 (15 by maintainers)

Most upvoted comments

It might make sense to resample all output in the audio driver before sending it to WASAPI, if the sample rates do not match. I’ll see if I can get something put together that does this.

Another option I’d almost prefer is to keep the current setting and add a “force sample rate” checkbox (default false). The ability to set a sample rate preference on some platforms may be useful, so on every platform except for Windows, the text box will retain its behavior. But you have the checkbox just in case you want to specify the sample rate on Windows too. The reason I like this more is because it breaks compatibility less. No need to change defaults or names of settings. Existing projects will continue to open and be magically fixed once the Godot version is updated. Something like this could be cherry picked for 3.x with no issues, but renaming a setting might be a 4.x only thing.

I’ve fixed a lot of Godot’s audio bugs but I don’t have a windows machine so even if I had time this isn’t something I can do. But the basic idea behind either one of these fixes is to change the interface of the AudioDriver class so that it can surface a platform preference for sample rate to the AudioServer. All of the audio drivers except for WASAPI will simply specify zero as their sample rate preference indicating they don’t care. The AudioServer should take this into consideration along with whatever preference/forcing options are or are not specified by the user at build time. Once the audio server decides on a sample rate, all the AudioStream classes will handle resampling to the decided-upon rate, and everything should work 😃

Would using a sample rate of 48,000 Hz by default alleviate this issue? It seems 48,000 Hz is a more common default on Windows compared to 44,100 Hz.

Reading the Windows-provided value and performing resampling would be ideal, but I don’t know how much work it requires.

From what I googled WASAPI can’t change user-specified sample rate to something else. So I think the options are:

  1. adjust Godot project sample rate to what’s selected by user in Windows settings
  2. continuously resample from Godot selected rate to Windows selected rate
  3. similar to 2, but ask Windows to resample
  4. add DirectSound support back to Godot

Here are some examples from other projects of how it could be done: https://github.com/soundradix/JUCE/commit/1162b8d1ec2542ced126f1d00a7e4ea075615395 https://github.com/thestk/rtaudio/pull/119 https://github.com/thestk/rtaudio/pull/88