Topic was automatically imported from the old Question2Answer platform.
Asked By
fuxoft
I was looking at the Audio Generator Demo which references AudioStreamPlayback and its methods. I wanted to know more about this class and its methods but the official docs page only contains the link to the demo linked above, nothing else. Where can I see how exactly push_frame() works and what other methods this class provides (e.g. for clearing the sample buffer).
In the inspector for this node, click Stream to create a new AudioStreamGenerator resource.
Attach a script to the node – here’s working C# code that generates noise.
using Godot;
public class AudioStreamPlayerSynth : AudioStreamPlayer
{
AudioStreamGeneratorPlayback _Playback;
RandomNumberGenerator _Rng = new RandomNumberGenerator();
public override void _Ready() {
_Playback = GetStreamPlayback() as AudioStreamGeneratorPlayback;
Fill();
Play();
}
public override void _Process(float delta) {
Fill();
}
void Fill() {
int i = _Playback.GetFramesAvailable();
while (i > 0) {
i--;
_Playback.PushFrame(Vector2.One * (_Rng.Randf() * 2 - 1));
}
}
}
Note: AudioStreamPlayerSynth is not a Godot thing, just the custom node script class. I sometimes name nodes by tacking on the node’s purpose at the end of the default type name.