-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to use AudioStreamGenerator #76373
Document how to use AudioStreamGenerator #76373
Conversation
b81775f
to
26d0e95
Compare
your code snippet is invalid, since you have to call @onready var sample_hz: float = $AudioStreamPlayer.stream.mix_rate
var playback: AudioStreamGeneratorPlayback
var pulse_hz := 440.0 # The frequency of the sound wave.
func _ready() -> void:
$AudioStreamPlayer.play()
playback = $AudioStreamPlayer.get_stream_playback()
fill_buffer()
func fill_buffer():
var phase := 0.0
var increment := pulse_hz / sample_hz
var frames_available := playback.get_frames_available()
for i in range(frames_available):
playback.push_frame(Vector2.ONE * sin(phase * TAU))
phase = fmod(phase + increment, 1.0) |
I think it's a bug. Neither Juan's announcement nor the demo do this. I believe it shouldn't be the case with AudioStreamGenerator, as the announcement moreover claims:
For reference: The error thrown is this: godot/scene/audio/audio_stream_player.cpp Line 315 in 7a0977c
It was added 3 months ago in #71906 |
26d0e95
to
238461f
Compare
Fixed a typo and addressed the concerns above. |
238461f
to
9d77caa
Compare
Thanks! Merged. |
Cherry-picked for 4.0.3. |
This class doesn't have many (if any) resources online for how to use it. Other than our own, linked under tutorials:
I changed up the description (to remove any confusion that AudioStreamGenerator produces sounds on its own). I also added a simple GDScript example and removed the second link.