AudioStreamGenerator

package
v0.0.0-...-535787f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 24 Imported by: 0

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

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 Any

type Any interface {
	gd.IsClass
	AsAudioStreamGenerator() Instance
}

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

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

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 (self *Extension[T]) AsAudioStreamGenerator() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

type ID

type ID Object.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.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

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 New

func New() Instance

func (Instance) AsAudioStream

func (self Instance) AsAudioStream() AudioStream.Instance

func (Instance) AsAudioStreamGenerator

func (self Instance) AsAudioStreamGenerator() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) BufferLength

func (self Instance) BufferLength() Float.X

func (Instance) ID

func (self Instance) ID() ID

func (Instance) MixRate

func (self Instance) MixRate() Float.X

func (Instance) MixRateMode

func (self Instance) MixRateMode() AudioStreamGeneratorMixRate

func (Instance) SetBufferLength

func (self Instance) SetBufferLength(value Float.X)

func (Instance) SetMixRate

func (self Instance) SetMixRate(value Float.X)

func (Instance) SetMixRateMode

func (self Instance) SetMixRateMode(value AudioStreamGeneratorMixRate)

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL