Documentation
¶
Overview ¶
AudioStreamWAV stores sound samples loaded from WAV files. To play the stored sound, use an AudioStreamPlayer (for non-positional audio) or AudioStreamPlayer2D/AudioStreamPlayer3D (for positional audio). The sound can be looped.
This class can also be used to store dynamically-generated PCM audio data. See also AudioStreamGenerator for procedural audio generation.
Index ¶
- type Advanced
- type Any
- type Extension
- type Format
- type ID
- type Instance
- func (self Instance) AsAudioStream() AudioStream.Instance
- func (self Instance) AsAudioStreamWAV() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) AsResource() Resource.Instance
- func (self Instance) Data() []byte
- func (self Instance) Format() Format
- func (self Instance) ID() ID
- func (self Instance) LoopBegin() int
- func (self Instance) LoopEnd() int
- func (self Instance) LoopMode() LoopMode
- func (self Instance) MixRate() int
- func (self Instance) SaveToWav(path string) error
- func (self Instance) SetData(value []byte)
- func (self Instance) SetFormat(value Format)
- func (self Instance) SetLoopBegin(value int)
- func (self Instance) SetLoopEnd(value int)
- func (self Instance) SetLoopMode(value LoopMode)
- func (self Instance) SetMixRate(value int)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetStereo(value bool)
- func (self Instance) SetTags(value map[string]interface{})
- func (self Instance) Stereo() bool
- func (self Instance) Tags() map[string]interface{}
- func (self Instance) Virtual(name string) reflect.Value
- type LoopMode
- type Options
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 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]) AsAudioStreamWAV ¶
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
func (*Extension[T]) AsResource ¶
type Format ¶
type Format int //gd:AudioStreamWAV.Format
const ( // 8-bit PCM audio codec. Format8Bits Format = 0 // 16-bit PCM audio codec. Format16Bits Format = 1 // Audio is lossily compressed as IMA ADPCM. FormatImaAdpcm Format = 2 // Audio is lossily compressed as [Quite OK Audio]. // // [Quite OK Audio]: https://qoaformat.org/ FormatQoa Format = 3 )
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.AudioStreamWAV
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 LoadFromBuffer ¶
Creates a new AudioStreamWAV instance from the given buffer. The buffer must contain WAV data.
The keys and values of 'options' match the properties of ResourceImporterWAV. The usage of 'options' is identical to AudioStreamWAV.LoadFromFile.
func LoadFromFile ¶
Creates a new AudioStreamWAV instance from the given file path. The file must be in WAV format.
The keys and values of 'options' match the properties of ResourceImporterWAV.
Example: Load the first file dropped as a WAV and play it:
package main import ( "path/filepath" "graphics.gd/classdb/AudioStreamPlayer" "graphics.gd/classdb/AudioStreamWAV" "graphics.gd/classdb/Node" "graphics.gd/classdb/Window" ) type MyAudioLoader struct { Node.Extension[MyAudioLoader] AudioPlayer AudioStreamPlayer.Instance } func (m *MyAudioLoader) Ready() { Window.Get(m.AsNode()).OnFilesDropped(func(files []string) { if filepath.Ext(files[0]) == "wav" { m.AudioPlayer.SetStream(AudioStreamWAV.LoadFromFile(files[0], AudioStreamWAV.Options{ ForceMaxRate: true, ForceMaxRateHz: 11025, }).AsAudioStream()) m.AudioPlayer.Play() } }) }
func (Instance) AsAudioStream ¶
func (self Instance) AsAudioStream() AudioStream.Instance
func (Instance) AsAudioStreamWAV ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) AsResource ¶
func (Instance) SaveToWav ¶
Saves the AudioStreamWAV as a WAV file to 'path'. Samples with IMA ADPCM or Quite OK Audio formats can't be saved.
Note: A .wav extension is automatically appended to 'path' if it is missing.
func (Instance) SetLoopBegin ¶
func (Instance) SetLoopEnd ¶
func (Instance) SetLoopMode ¶
func (Instance) SetMixRate ¶
type LoopMode ¶
type LoopMode int //gd:AudioStreamWAV.LoopMode
const ( // Audio does not loop. LoopDisabled LoopMode = 0 // Audio loops the data between [LoopBegin] and [LoopEnd], playing forward only. // // [LoopBegin]: https://pkg.go.dev/graphics.gd/classdb/#Instance.LoopBegin // [LoopEnd]: https://pkg.go.dev/graphics.gd/classdb/#Instance.LoopEnd LoopForward LoopMode = 1 // Audio loops the data between [LoopBegin] and [LoopEnd], playing back and forth. // // [LoopBegin]: https://pkg.go.dev/graphics.gd/classdb/#Instance.LoopBegin // [LoopEnd]: https://pkg.go.dev/graphics.gd/classdb/#Instance.LoopEnd LoopPingpong LoopMode = 2 // Audio loops the data between [LoopBegin] and [LoopEnd], playing backward only. // // [LoopBegin]: https://pkg.go.dev/graphics.gd/classdb/#Instance.LoopBegin // [LoopEnd]: https://pkg.go.dev/graphics.gd/classdb/#Instance.LoopEnd LoopBackward LoopMode = 3 )
type Options ¶
type Options struct { CompressionMode int `gd:"compress/mode"` LoopBegin int `gd:"edit/loop_begin"` LoopEnd int `gd:"edit/loop_end"` LoopMode int `gd:"edit/loop_mode"` Normalize int `gd:"edit/normalize"` Trim bool `gd:"edit/trim"` ForceMinRate bool `gd:"force/8_bit"` ForceMaxRate bool `gd:"force/max_rate"` ForceMaxRateHz float32 `gd:"force/max_rate_hz"` ForceMono bool `gd:"force/mono"` }