Skip to content

Implement audio absolute time (DSP time) and scheduled play#107226

Open
PizzaLovers007 wants to merge 1 commit intogodotengine:masterfrom
PizzaLovers007:play-scheduled-v2
Open

Implement audio absolute time (DSP time) and scheduled play#107226
PizzaLovers007 wants to merge 1 commit intogodotengine:masterfrom
PizzaLovers007:play-scheduled-v2

Conversation

@PizzaLovers007
Copy link
Contributor

@PizzaLovers007 PizzaLovers007 commented Jun 6, 2025

This is a rewrite of #105510 that introduces new ScheduledAudioStreamPlayer/2D/3D nodes and moves the silence frames logic into a separate AudioStreamPlaybackScheduled class. The rewrite allows both the AudioServer and the player (mostly) to treat it as if it were a generic playback.

Main differences:

  • ScheduledAudioStreamPlayer/2D/3D are new nodes inheriting from their AudioStreamPlayer/2D/3D counterparts. These nodes only contain one new method: play_scheduled.
  • play_scheduled returns an AudioStreamPlaybackScheduled instance, which is tied to the player that created it.
  • The start time can be changed after scheduling.
  • You can now set an end time for the playback.
  • The scheduled playback can be cancelled separately from other playbacks on the player.

Why new nodes? New nodes prevent feature creep on the original AudioStreamPlayer/2D/3D nodes and follows the "Prefer local solutions" best practice. Scheduling audio is an important use case, but not one that needs to be in core player functionality.

Why not use AudioServer directly? AudioServer methods are not available to GDScript as of writing. While this is not a hard change to make, AudioStreamPlayer/2D/3D nodes provide a significantly better user experience (editor UI) as well as provide panning, doppler effect, and other features that would be non-trivial to reimplement.

A demo of this feature can be found at godotengine/godot-demo-projects#1210.

Fixes godotengine/godot-proposals#1151.
Supersedes #105510.

@PizzaLovers007 PizzaLovers007 requested review from a team as code owners June 6, 2025 19:32
@AThousandShips AThousandShips changed the title v2 Implement audio absolute time (DSP time) and scheduled play Implement audio absolute time (DSP time) and scheduled play Jun 6, 2025
@Calinou Calinou added this to the 4.x milestone Jun 6, 2025
@PizzaLovers007
Copy link
Contributor Author

I tried my best at the icons for these new nodes, but I can remove them if they don't meet standards!

@fire

This comment was marked as outdated.

@LemmaEOF
Copy link

Just to check - does this let you schedule multiple playbacks on the same player without overwriting them? It would be really nice for a rhythm game like mine to be able to queue a big batch of hitsounds at the start of a chart instead of having to schedule each one individually as they come up.

@PizzaLovers007
Copy link
Contributor Author

Yes you can queue multiple sounds, but you'll need to increase max_polyphony to match the number of sounds you want to queue. For many sounds, it may be more performant to schedule them closer to when they're supposed to be played and/or use multiple players.

@Ashlyn39
Copy link

Is it possible to use this new node in C#? It took me a long time, but I managed to get your branch of Godot compiled and set up (building the mono branch took a lot of figuring out for me)

I can see ScheduledAudioStreamPlayer when I'm working in GDScript, but I vastly prefer C#. I suppose I could try to learn enough GDScript to dual wield, but is there a way to reference this class in C#? Thank you for making this, it'll make my rhythm game easier to make

@LemmaEOF
Copy link

If C# bindings don't get autogenned on this branch then they definitely will when this makes it into the engine proper, they get auto-generated upon mono engine build

@Ashlyn39
Copy link

I'll try to run the build_script again (I'm a bit out of my depth when it comes to compiling from source code), If I can't get it, I'll toy around with GDScript until this makes it in

@Ashlyn39
Copy link

Ashlyn39 commented Oct 2, 2025

This branch is so clutch for making a rhythm game. I love being able to pull the absolute time of the audio server and be able to pre-schedule audio stream plays. I have a couple of them in my scene with empty WAVs to throw the finished signal, to dynamically spawn notes in the playfield and account for audio lag. I can't wait for this to hit the main branch. Thank you

@gg-yb
Copy link
Contributor

gg-yb commented Nov 25, 2025

When trying to play sounds (e.g. hammer hitting, gunfire) at a steady rhythm (but not as a premade sound, but instead individual effects), this change is a game changer.

This should really be considered for timely inclusion in official Godot, we cannot realize our projects without it, and as of now are required to always use a custom engine build.

@fire
Copy link
Member

fire commented Nov 25, 2025

Small issue: Can you review the hash on #105510 so it doesn't spam the issue number on forks?

@PizzaLovers007
Copy link
Contributor Author

Small issue: Can you review the hash on #105510 so it doesn't spam the issue number on forks?

I removed the PR reference in the commit (if that's what you intended me to do). Sorry for the spam!

@fire
Copy link
Member

fire commented Dec 2, 2025

I wasn't able to figure out why the pull request is blocked so you probably want to visit an audio team meeting or the godot chat instance #audio channel.

@gmichael27
Copy link

This is an incredible feature, I've been really exercising it while working on a music-making game of sorts. Very pleased with it and would love to see this get merged. Awesome work!

This is a rewrite of PR 105510 that moves the silence frames logic into a separate AudioStreamPlaybackScheduled class and introduces new ScheduledAudioStreamPlayer/2D/3D nodes. The rewrite allows both the AudioServer and the player (mostly) to treat it as if it were a generic playback.

Main differences:
- ScheduledAudioStreamPlayer/2D/3D are new nodes inheriting from their AudioStreamPlayer/2D/3D counterparts. These nodes only contain one new method: play_scheduled.
- play_scheduled returns an AudioStreamPlaybackScheduled instance, which is tied to the player that created it.
- The start time can be changed after scheduling.
- You can now set an end time for the playback.
- The scheduled playback can be cancelled separately from other playbacks on the player.

Co-Authored-By: K. S. Ernest (iFire) Lee <ernest.lee@chibifire.com>
@IntangibleMatter
Copy link
Contributor

Love this! Hoping it can get merged for 4.7 (or another version that's coming soon) because it doesn't look too far off to being done to me. Great work!

@LemmaEOF
Copy link

Are there any more blocks on this PR? It'd be huge to have once the 4.7 cycle spins up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an absolute time (DSP time) feature to play audio effects at specific intervals

8 participants