godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.21k stars 21.22k forks source link

Cracking audio with Godot 4 no-threads Web builds #87329

Closed akien-mga closed 5 months ago

akien-mga commented 10 months ago

Tested versions

Reproducible in 4.3.dev (1952f64b07b2a0d63d5ba66902fd88190b0dcf08) with a threads=no Web template. The issue was "introduced" in #85939 since it wasn't possible to make single-threaded Web builds in Godot 4 before that.

System information

Mageia 9 - Vulkan (Forward+) - dedicated AMD Radeon RX Vega M GL Graphics (RADV VEGAM) () - Intel(R) Core(TM) i7-8705G CPU @ 3.10GHz (8 Threads)

Issue description

The newly reintroduced single-threaded Web export has audio issues, as expected.

On my Linux system, it's pretty dire on any demo that has background music, sfx, and any game logic or rendering effort that's non trivial (i.e. the CPU is kept busy).

Here's an example with the GDQuest TPS demo, uploaded to itch.io, with threads disabled (built from #85939):

https://akien.itch.io/godot4-nothreads-audio-test

(Ignore the weird rendering (Compatibility while the demo is designed for Forward+) and the fact that rotating the camera with the mouse seems to be broken in the Web build.)

Here's how the game sounds like on a native Linux build (editor):

https://github.com/godotengine/godot/assets/4701338/638685d6-553d-4755-92df-6658ea57245d

Here's the threads=no Web build (debug) on currently Firefox Nightly (123.0a1 (2024-01-17)) on the same Linux system:

https://github.com/godotengine/godot/assets/4701338/cc9d8aac-4fe0-4e2f-8c60-06b6b6a4e860

And the same on Chromium (120.0.6099.216) on the same Linux system:

https://github.com/godotengine/godot/assets/4701338/d35431cb-a6f4-4250-8db2-7e63813e9c74


The issue is likely linked to OS, browser, and CPU, so for testers who can or cannot reproduce it, please include full info about what platform you tested on.

$ inxi -CSG
System:
  Host: cauldron Kernel: 6.5.13-desktop-6.mga9 arch: x86_64 bits: 64
    Desktop: KDE Plasma v: 5.27.5 Distro: Mageia 9
CPU:
  Info: quad core model: Intel Core i7-8705G bits: 64 type: MT MCP cache:
    L2: 1024 KiB
  Speed (MHz): avg: 900 min/max: 800/4100 cores: 1: 900 2: 900 3: 900 4: 900
    5: 900 6: 901 7: 900 8: 900
Graphics:
  Device-1: Intel HD Graphics 630 driver: i915 v: kernel
  Device-2: AMD Polaris 22 XL [Radeon RX Vega M GL] driver: amdgpu v: kernel
  Device-3: Cheng Uei Precision Industry (Foxlink) HP Wide Vision FHD Camera
    type: USB driver: uvcvideo
  Display: x11 server: X.org v: 1.21.1.8 with: Xwayland v: 22.1.9 driver: X:
    loaded: intel,v4l dri: i965 gpu: i915 resolution: 2048x1152~60Hz
  API: OpenGL v: 4.6 Mesa 23.3.2 renderer: Mesa Intel HD Graphics 630 (KBL
    GT2)

Steps to reproduce

Minimal reproduction project (MRP)

https://akien.itch.io/godot4-nothreads-audio-test

akien-mga commented 10 months ago

Same issue on Android 14 with a Pixel 7a, both with Firefox Beta 122.0b9 and Chrome 120.0.6099.210.

popcar2 commented 10 months ago

Windows 11 v23H2 here (full specs later). I'm also getting audio cackling in your example project on Firefox, Chrome, and Edge. It sometimes sounds fine probably when the game is running at full speed though. Chrome and Edge also have major artifacts on the intro screen.

Firefox 121.0.1:

https://github.com/godotengine/godot/assets/16920817/53b808d0-1321-4c5e-a2c8-47ad6edcb13f

Notes: Similar results to the post above, but it runs a lot smoother on my end due to better specs.

Microsoft Edge 120.0.2210.144 (WARNING: FLASHING COLORS):

https://github.com/godotengine/godot/assets/16920817/22012fda-94e7-4348-9fd5-1009f1ab42d7

Notes:

Google Chrome Version 120.0.6099.225:

Notes: Exact same results as Microsoft Edge (see video above). Broken intro screen, good audio after shader compilation, audio breaks when exiting fullscreen.

Here are my specs:

Windows 11 Home - Version 23H2 / Build 22631.3007
Processor: AMD Ryzen 5 5600 @ 3.5GHz
GPU: RTX 3060 Ti - driver 546.33
RAM: 16GB
starry-abyss commented 10 months ago

I'm a newbie in this, but maybe we could use Web Audio backend code from miniaudio library in Godot?

wojtekmal commented 10 months ago

The audio in my game runs perfectly when I run the linux release export, but my game isn't cpu intensive so this isn't very significant. Anyway, two things caught my attention. Firstly, audio from MRP on itch.io is of low quality, but when I switch to another tab, the audio quality suddenly increases to near perfect. I use firefox 122.0 64 bit. Secondly, the game is completely silent when I launch my game from the editor with f5, however as I said previously, it works in the export. Here are my specs:

System:
  Host: lapwo Kernel: 6.5.0-14-generic x86_64 bits: 64 Desktop: GNOME 42.9
    Distro: Ubuntu 22.04.3 LTS (Jammy Jellyfish)
CPU:
  Info: quad core model: 11th Gen Intel Core i5-1135G7 bits: 64 type: MT MCP
    cache: L2: 5 MiB
  Speed (MHz): avg: 1053 min/max: 400/4200 cores: 1: 1200 2: 559 3: 1088
    4: 976 5: 1200 6: 1069 7: 1176 8: 1158
Graphics:
  Device-1: Intel TigerLake-LP GT2 [Iris Xe Graphics] driver: i915 v: kernel
  Device-2: Realtek LG Camera type: USB driver: uvcvideo
  Display: x11 server: X.Org v: 1.21.1.4 driver: X: loaded: modesetting
    unloaded: fbdev,vesa gpu: i915 resolution: 2560x1600~60Hz
  OpenGL: renderer: Mesa Intel Xe Graphics (TGL GT2)
    v: 4.6 Mesa 23.0.4-0ubuntu1~22.04.1

Edit: updated the specs to ones printed out by inxi. Also, the thing where switching to another tab improves audio quality also works on Chrome, but I think that this is happening just because looking away from the game is optimized and reduces cpu load.

octanejohn commented 9 months ago

pixel 6 android 13 Kiwi Browser 120.0.6099.116, cracking and missing textures

Screenshot_20240203-192618

wojtekmal commented 9 months ago

I noticed that audio is broken regardless of whether I export with the option "Thread support". Of course when I export from the normal editor with normal templates (built without --treads=no) it still works.

ChronoDK commented 9 months ago

If you increase audio output latency.web to 90 it mostly goes away.

popcar2 commented 9 months ago

If you increase audio output latency.web to 90 it mostly goes away.

This... Actually works, thanks! Hopefully that can help track down the issue. Here's my testing with the no threads template:

Latency.web 50 (default) - audio starts at 0:17 - Notice the insane crackling in the game over screen

https://github.com/godotengine/godot/assets/16920817/437bfbce-c991-4edb-9d1d-dfc7b1dd6e10

Latency.web 90 - audio starts at 0:11 - Audio has minor skips on frame drops but does not crackle

https://github.com/godotengine/godot/assets/16920817/07944539-cadc-457e-a56f-ad3551a57221

fire commented 9 months ago

@jasonwinterpixel Mentioned using Latency.web 150 in Godot Engine 3, but I didn't get the complete details on what harm this causes.

jasonwinterpixel commented 9 months ago

It seems like audio should only crack if the CPU is maxed out. If the CPU isnt maxed, it should be able to fill the buffer properly. In the case where the CPU is maxed, the audio should stop and not 'ring' around the other side like it does in web on godot 3 right now.

We use a high audio latency in our games in single threaded builds, and tbh it bothers me quite a bit. I think I'd only be willing to tolerate ~50ms of audio latency.

akien-mga commented 9 months ago

Needs testing on several projects/devices, but I suggest we look into increasing the default audio latency for the Web export in 4.3, mitigating the current issues. I agree with @jasonwinterpixel that high latency is a bother, but it's better than the kind of cracking we have currently.

It's not a long term solution, but it should be a good first step to make things at least usable.

graphific commented 4 months ago

Just FYI changing the audio output latency.web from 50 to 90 fixed the crackling issue almost entirely (having about 4-6 audio players procedurally playing different sound layers and only sometimes a tiny bit hickup, but the sound stays clear), for this jam game: https://graphific.itch.io/bird-ruckus

Silvanuz commented 4 months ago

FYI too: Can confirm that changing the latency.web to 100 (max value) does nothing in my case. But the sound cracks only on the left channel on iOS. With a panner to the right channel only everything sounds clean.