godot
godot copied to clipboard
Audio files distort inside Godot when using a Focusrite DAC
Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.
Godot version
Godot 4.0 stable
System information
Windows 10
Issue description
I have been having inconsistent bugs with audio files being played weirdly in Godot, as if Godot can't read them correctly.
I made a project that worked completely fine, and then in some way when I switched some audio files the audio started stuttering. I tried many different formats but nothing really worked. This can happen both when you preview the sound in the inspector and in game. Switching to a new project, with the same file, the audio worked fine again for a few minutes until it started stuttering again. So I think its more about the engine somehow messing up with how it reads the files. Reopening the projects seems to fix this sometimes.
I tried recreating what could make this happen but couldn't really find a reason, but its still happening, with old/new projects, although again inconsistently changing between stuttering and working normally, with all types of files.
I tried with 32bit float, 24bit int, and 16bit int .wav files, mp3 320kbps, all at 44.1khz.
Obviously the files themselves are not corrupted as if you play them externally they sound just fine. My audio is fine anywhere else outside of Godot, so I don't think its a problem with my setup.
Steps to reproduce
Just try dragging in audio files into Godot and preview them in the inspector, see if anything happens I guess. As I said, this is pretty inconsistent so I don't know how to reproduce it. It happened to me in a brand new project, as well in a project that I have been working for a few hours on.
Currently I can't reproduce it for some reason, if it comes back again ill try recording it.
Minimal reproduction project
N/A
- Related to https://github.com/godotengine/godot/issues/74779 and https://github.com/godotengine/godot/issues/25875.
Are you using Bluetooth audio with microphone enabled? This limits audio output to mono and will greatly decrease its quality.
No, I'm using good quality wired headphones and speakers with a Focusrite mini audio interface. I'm not talking about mono signal. When it happens, it sounds like the file is "half corrupted", meaning the information you hear is still some what related to the original signal, but is weirdly distorted. And again, hearing anything else outside of Godot works completely fine, I A/B tested it in real time. Hopefully I'll have something to show for when this happens again and I record it.
This doesn't seem to be related to these other issues you mentioned imo.
I'm having the same issue. I'm using Godot 4.0.1 Stable. Headphones are wired and no audio issues outside of Godot. I tried mp3 wav and ogg. Every format is working fine on windows10 media player or VLC media player. As soon as i import them to Godot the Audio is laggy/crackling on the prewiev and on AudioStreamPlayer and also in-game
Edit: i tried using my cheap wireless headband hedphones and for my surprise the audio lagging/cracking is gone. my main headphones are going through a scarlett 2i2 (3rd gen) audio interface which sample rate is set to 44100 and the Buffer size was 512. Reducing the Buffer size to 256 solved my problme inside Godot
I'm having the same issue.
Edit: i tried using my cheap wireless headband hedphones and for my surprise the audio lagging/cracking is gone. my main headphones are going through a scarlett 2i2 (3rd gen) audio interface which sample rate is set to 44100 and the Buffer size was 512. Reducing the Buffer size to 256 solved my problme inside Godot
This is the exact problem I'm pretty sure. I also had the problem reoccur to me, and when switching from 512 to 256 buffer size the audio stopped stuttering. I have a Scarlett mini. this might have to do specifically with Focusrite products, needs checking. This also happens with exported godot games made on godot 4.0.x, I figured this out because I entered the Godot Wild Jam where I'm sure most of the people used godot 4.0.x. all their games had that problem on my pc, and ours which was made on godot 3.5.2 stable didn't have that audio stuttering problem regardless of the buffer size.
Video attached here. Notice that there are some stutters even when being on 256 buffer size.
https://user-images.githubusercontent.com/73611276/234338547-85ac23a6-be5e-44b9-9450-e0a9049a9ba3.mp4
@Calinou
I can attest to this possibly being related to focusrite products, I have a scarlet 2i2 and get the exact same audio corruption usually until a pc restart
@Psiice, @fkeyzuwu, @yaboigraves did you also test without scarlett (the usb audio interface) and directly connecting the (good) headphones to your computer? (And I don't mean wireless/bluetooth)
I am also running into this issue; when Godot output is through my Focusrite 2i2, the sounds played from Godot are inconsistently distorted (in a bitrate way).
Plugging into and using any other standard audio outputs on my PC makes the issue go away. My audio files are all Mono 16 bit 44100 Hz .WAV files.
I fiddled around a little bit this afternoon, I was able to fix the distortion by going into Focusrite Control and setting the sample rate (under Device in the toolbar) to 44.1 kHz. the default setting is 48 kHz. Edit: I also found that playing the same files in Audacity with the 48kHz samplerate produced the same distortion, so I am inclined that this is not really godot's fault.
@MJacred
I am encountering this issue as well, with the Focusrite Scarlett 2i2, and can confirm that when plugging directly into my computer the audio is fine. Setting the Scarlett's sample rate to 44100 did not help, although strangely setting it to 192000 did make the audio in Godot no longer bug for the moment. However, this bugs out all of my other audio software, meaning I'll have to switch back and forth a bunch.
hey. been running into this issue a lot. Audio sounds like its cutting out and stuttering, happens frequently but at unpredictable times. Happens in game when the game is running, but it also happens in editor when playing an audio file
Here is an example of the waveforms of a recording, showing gaps in the audio:
I have a Steinberg brand UR22mkII USB audio interface that my headphones are connected to. Reducing the buffer size the driver settings from 512 to 256 seems to have improved the issue, as well as seeming to improve the overall smoothness of the game. However, the stuttering still occurs, just much less frequently
@Psiice, @fkeyzuwu, @yaboigraves did you also test without scarlett (the usb audio interface) and directly connecting the (good) headphones to your computer? (And I don't mean wireless/bluetooth)
Sorry, didnt see your message. but no, It doesn't happen while directly connecting my headphones to the pc.
Is anyone looking at solving this problem? I would assume it should be relatively high importance. Depending on severity it can happen very commonly, and be almost unfixable(for me changing the buffer size doesn't guarantee it being fixed 95% of the time). Also might be happening on other audio interfaces as implied by @moehnked. And as I said, this is not a problem with JUST the editor, it also happens on exported projects, meaning pretty much any project that is out from this Godot version onwards will very likely have this problem. It can pretty much make the game unplayable with audio for some people. It's also worth mentioning that these Focusrite audio interfaces are very common.
@Psiice, @fkeyzuwu, @yaboigraves did you also test without scarlett (the usb audio interface) and directly connecting the (good) headphones to your computer? (And I don't mean wireless/bluetooth)
Without using my scarlet 2i2 and just using my PC soundcard this does not occur ever.
Is anyone looking at solving this problem?
We have relatively few audio contributors (I am not one of them). Also, not all of them have access to a Focusrite DAC (which isn't cheap for something you'd buy just to fix a bug).
What's the cheapest Focusrite DAC on which the issue has been confirmed?
scarlet 2i2 i believe is the cheapest model, I'd honestly be willing to be put in contact with an audio engine dev who's interested in tackling this and shipping them mine to borrow, as I have a 6i6 I use for daily work anyways. Worth a shot I suppose!
Including this issue, I'm aware of 3 other issues that sound very similar. All of them have in common that there is another audio-related process running. And that the issue popped up between v4.0-beta 14 and 15 (source). @Calinou referenced the Engine commits here. They are an excellent starting point for the investigation.
Therefore, if I'm not mistaken about the issue relations, it should be possible to find and solve the issue without requiring an audio interface. Unless proven otherwise.
In turn, this means that also non-audio engine devs can bisect the regression and look out where audio code was touched. Anyone who can compile the engine from source can greatly help fixing the root cause!
This issue happens no matter what sample rate you are using in the project settings and no matter what sample rate you are using in the Focusrite settings. This is an isolated bug in Godot since this stuttering issue only happens inside Godot and programs made by using Godot (ie, using Godot code). I have been using a Focusrite device for over 5 years and Godot is the only place where this issue happens, which makes it safe to say that this is not any external issue or user error. I have worked on and developed low latency audio playback software and never came across this issue either (while using a Focusrite device with latest Focusrite drivers).
Changing the sample rate inside the Focusrite settings is not a fix, it only resets the Windows output device, and Godot probably catches that event. It will still slowly drift away and it will start stuttering again which makes this seem like an accumulation error (such as missing a loop somewhere when feeding the output device).
This issue does not appear when not using a studio audio interface (for example BT headphones), which makes me think that the Godot code makes big assumptions about the output device in the audio code that is not correct.
Ok an update. I did some work on this today and I believe that I have resolved this issue in my local build. Back to back testing with the official Godot 4.1 build and my local build, also testing with different Focusrite sample rates and the issue does not appear in my local build, while it occurs in the official build.
I have also tested with BT headphones and it also works there.
I modified the WASAPI driver quite a bit to resolve this issue. I also looked at the XAudio2 implementation but it doesn't build (probably why it is excluded from the build also), so I will not touch that. But I am very certain this issue would not have happened in the XAudio2 implementation if it was used for speaker playback.
Great work :slightly_smiling_face: Could you open a pull request on master
with your changes, please?
I also looked at the XAudio2 implementation but it doesn't build (probably why it is excluded from the build also),
The XAudio2 driver has been disabled by default for a long time, so it probably bitrot over time.
I have opened https://github.com/godotengine/godot/pull/81938 now. Probably did something wrong with the Git side of thing though. My least favorite part.
Hi, I just wanted to add that the issue with crackling audio is not exclusive to FocusRite stuff. I have the same problem with my Asus Xonar DSX sound card.
@crashfort Tested your PR with my Focusrite 18i8, and it had no differences regarding the crackling audio. The crackling always occurs regardless of 1 sound playing or 100 sounds playing, but it can't really be replicated easily as it seems to be at complete random.
Happy to help with testing as much as needed on this issue as this is a huge blocker to development of my current game, an audio-focused game
Edit: I don't know if this helps at all but the crackling sounds identical to what happens in Ableton when you have too many VSTs running at once, it's caused by using too much CPU. However, that shouldn't be happening in a project with pretty much nothing going on. Also noting that this issue does not seem to occur when not using the interface, but as others said before, that is pretty irrelevant since a high percentage of people use audio interfaces, especially Focusrite ones.
I have opened #81938 now. Probably did something wrong with the Git side of thing though. My least favorite part.
checked with my Focusrite mini, seems to fix it. cross checked with other versions of the engine and changing around buffer sizes still stutters with them, but with this one i couldn't get it to stutter across a few different configurations of 128/256/512 buffer size and 44100/48000 sample rate.
For what it's worth, I can confirm that this appears to also affect my Sennheiser GSP 670. I came across this issue while trying to play Halls on Torment. Some of the other reports on the forum finally pointed me towards this issue.
After reading the whole thread, just wondering if anyone has considered ASIO drivers/hardware as part of the root cause? That may be the commonality between all the devices mentioned.
After reading the whole thread, just wondering if anyone has considered ASIO drivers/hardware as part of the root cause? That may be the commonality between all the devices mentioned.
fix has already been mentioned here - #81938. im not too familiar with audio drivers but it seemed to be a problem with WASAPI.
but we need more people testing that branch to see if it really fixes it for most people.
idk if this would be relevant but I've been noticing this error message pop up:
" modules/vorbis/audio_stream_ogg_vorbis.cpp:332 - Burning negative samples doesn't make sense. Check seek algorithm."
@mberymon Can confirm that ASIO might be the issue.
Upper two channel is from godot build, lower two is original sound. I've synced start position thus difference in length proves that godot indeed has trouble.
Considering all the pop sound and overall slower playback suggest godot has trouble filling buffer or something.
Whenever Virtual ASIO is enabled (for me, Voicemeeter Banana) - despite having same sampling rate audio, even just playing track in editor's audio preview window has this issue.
If you disable exclusive mode for physical playback device then finally sound plays normally.
I wonder what's the cause though, never seen any other program having issue with Voicemeeter other than Godot.
Considering all the pop sound and overall slower playback suggest godot has trouble filling buffer or something.
Can you reproduce this if you increase Output Latency in the Project Settings (then restart the editor)?
I have this exact issue on my Windows PC, and Godot 4.1.3 is the only application that does that. I have several audio devices, including an external DAC (Steinberg UR12) and wireless headphones (Steelseries Artics 7, radio, not Bluetooth). This issue even persists with Remote Audio sound device via Remote Desktop connection.
Output Latency does not make any difference whatsoever (I suspect it doesn't even work). Changing Mix Rate to the same as or different from the current audio device does not help. ASIO drivers/devices are not used.
UPD: Unfortunately, the fix https://github.com/godotengine/godot/pull/81938 did nothing to resolve the issue.
UPD 2: Reinstalled Windows, this issue is not fixed.
@Calinou Yes actually first answer I saw on reddit suggested it, so I even set it as high as 200ms and still same issue happened, and still is.
Tried reinstalling VB again, no luck. Wonder if extra latency helps others with physical audio interfaces, as I don't have one.