Documentation
¶
Overview ¶
graphics.gd/classdb/AudioStreamGenerator is a type of audio stream that does not play back sounds on its own; instead, it expects a script to generate audio data for it. See also graphics.gd/classdb/AudioStreamGeneratorPlayback.
Here's a sample on how to use it to generate a sine wave:
package main import ( "graphics.gd/classdb/AudioStreamGenerator" "graphics.gd/classdb/AudioStreamGeneratorPlayback" "graphics.gd/classdb/AudioStreamPlayer" "graphics.gd/classdb/Node" "graphics.gd/variant/Angle" "graphics.gd/variant/Float" "graphics.gd/variant/Object" "graphics.gd/variant/Vector2" ) type ExampleAudioStreamGenerator struct { Node.Extension[ExampleAudioStreamGenerator] AudioStreamPlayer AudioStreamPlayer.Instance playback AudioStreamGeneratorPlayback.Instance sample_hz, pulse_hz Float.X phase Angle.Radians } func (eg *ExampleAudioStreamGenerator) Ready() { eg.sample_hz = Object.To[AudioStreamGenerator.Instance](eg.AudioStreamPlayer.Stream()).AsAudioStreamGenerator().MixRate() eg.AudioStreamPlayer.Play() eg.playback = Object.To[AudioStreamGeneratorPlayback.Instance](eg.AudioStreamPlayer.GetStreamPlayback()) eg.FillBuffer() } func (eg *ExampleAudioStreamGenerator) FillBuffer() { increment := Angle.Radians(eg.pulse_hz / eg.sample_hz) frames_available := eg.playback.GetFramesAvailable() for range frames_available { eg.playback.PushFrame(Vector2.AddX(Vector2.One, Angle.Sin(eg.phase*Angle.Tau))) eg.phase = Float.Mod(eg.phase+increment, 1.0) } }
In the example above, the "AudioStreamPlayer" node must use an graphics.gd/classdb/AudioStreamGenerator as its stream. The fill_buffer function provides audio data for approximating a sine wave.
See also graphics.gd/classdb/AudioEffectSpectrumAnalyzer for performing real-time audio spectrum analysis.
Note: Due to performance constraints, this class is best used from C# or from a compiled language via GDExtension. If you still want to use this class from GDScript, consider using a lower Instance.MixRate such as 11,025 Hz or 22,050 Hz.
Index ¶
- type Advanced
- type Any
- type AudioStreamGeneratorMixRate
- type Extension
- type ID
- type Instance
- func (self Instance) AsAudioStream() AudioStream.Instance
- func (self Instance) AsAudioStreamGenerator() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsResource() Resource.Instance
- func (self Instance) BufferLength() Float.X
- func (self Instance) ID() ID
- func (self Instance) MixRate() Float.X
- func (self Instance) MixRateMode() AudioStreamGeneratorMixRate
- func (self Instance) SetBufferLength(value Float.X)
- func (self Instance) SetMixRate(value Float.X)
- func (self Instance) SetMixRateMode(value AudioStreamGeneratorMixRate)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type AudioStreamGeneratorMixRate ¶
type AudioStreamGeneratorMixRate int //gd:AudioStreamGenerator.AudioStreamGeneratorMixRate
const ( // Current [graphics.gd/classdb/AudioServer] output mixing rate. MixRateOutput AudioStreamGeneratorMixRate = 0 // Current [graphics.gd/classdb/AudioServer] input mixing rate. MixRateInput AudioStreamGeneratorMixRate = 1 // Custom mixing rate, specified by [Instance.MixRate]. MixRateCustom AudioStreamGeneratorMixRate = 2 // Maximum value for the mixing rate mode enum. MixRateMax AudioStreamGeneratorMixRate = 3 )
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsAudioStream ¶
func (self *Extension[T]) AsAudioStream() AudioStream.Instance
func (*Extension[T]) AsAudioStreamGenerator ¶
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
func (*Extension[T]) AsResource ¶
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.AudioStreamGenerator
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsAudioStream ¶
func (self Instance) AsAudioStream() AudioStream.Instance
func (Instance) AsAudioStreamGenerator ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsResource ¶
func (Instance) BufferLength ¶
func (Instance) MixRateMode ¶
func (self Instance) MixRateMode() AudioStreamGeneratorMixRate
func (Instance) SetBufferLength ¶
func (Instance) SetMixRate ¶
func (Instance) SetMixRateMode ¶
func (self Instance) SetMixRateMode(value AudioStreamGeneratorMixRate)