RetroFed Forum
Your home away from modern life.
Godot can import WAV loop points. Don't restart AudioStreamPlayer in _process
Post Reply
AuthorMessage
Lemmit.Online bot Bot bot@lemmit.online
Joined: 2023-06-18
Quote

This is an automated archive made by the Lemmit Bot.

The original was posted on /r/godot by /u/composingkeys on 2026-08-14 04:36:06+00:00.


One easy mistake is treating music looping like a frame-timing problem: check get_playback_position() in _process() and restart the player when it reaches a boundary. That check runs on the game thread, while Godot mixes audio separately, so the restart can land late, especially during a hitch.

For WAV files, Godot already has native sample-based loop points:

  1. Import the WAV.
  2. In the Import dock, set Edit > Loop Mode to Detect From WAV if the file has loop metadata, or Forward to define it in Godot.
  3. Set Loop Begin and Loop End in samples, then reimport.
  4. Play the stream normally with an AudioStreamPlayer; the stream handles the wrap instead of _process().

You can also set the values at runtime:

gdscript var wav := $Music.stream as AudioStreamWAV wav.loop_mode = AudioStreamWAV.LOOP_FORWARD wav.loop_begin = 441000 wav.loop_end = 1852200 $Music.play()

loop_begin and loop_end are sample positions relative to the start of the stream. Embedded WAV loop metadata is imported automatically when present.

OGG Vorbis and MP3 work differently in Godot: they have a loop offset in seconds and loop from that point to the end of the file. WAV is the useful choice when you need both a distinct loop start and loop end.

There is still a second problem that perfect loop points do not solve: the reverb tail. If the last chord is still ringing after the loop end, a one-voice wrap discards that decay as the fresh beginning starts. The timing can be sample-accurate and the seam can still sound like a hole.

The practical fixes are:

  1. Render a genuinely dry boundary.
  2. Fold the tail under the beginning and export a self-contained one-voice loop.
  3. Use two AudioStreamPlayer voices so the outgoing pass can ring out while the next pass begins.

This is where a dedicated workflow saves time compared with doing it manually in a waveform editor: exact sample markers, bar snapping, immediate seam auditioning, and separate one-voice or two-voice deliveries all stay tied to the same loop definition.

Full disclosure: this came out of building Loopsmith, my looping-audio tool. It can read or set exact markers, audition the hard cut against a tail overlap, and export a marked WAV or a Godot two-voice recipe. None of the technique above requires it.

Godot's relevant documentation is here: https://docs.godotengine.org/en/stable/tutorials/assets_pipeline/importing_audio_samples.html

Happy to test edge cases or compare WAV versus OGG delivery setups.

1   Original
Post Reply
Back to top