AudioStreamWAV

package
v0.0.0-...-e10d1cd Latest Latest
Warning

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

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

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

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
	AsAudioStreamWAV() Instance
}

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]) AsAudioStreamWAV

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

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.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

func LoadFromBuffer(stream_data []byte, options Options) Instance

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

func LoadFromFile(path string, options Options) Instance

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 New

func New() Instance

func (Instance) AsAudioStream

func (self Instance) AsAudioStream() AudioStream.Instance

func (Instance) AsAudioStreamWAV

func (self Instance) AsAudioStreamWAV() 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) Data

func (self Instance) Data() []byte

func (Instance) Format

func (self Instance) Format() Format

func (Instance) ID

func (self Instance) ID() ID

func (Instance) LoopBegin

func (self Instance) LoopBegin() int

func (Instance) LoopEnd

func (self Instance) LoopEnd() int

func (Instance) LoopMode

func (self Instance) LoopMode() LoopMode

func (Instance) MixRate

func (self Instance) MixRate() int

func (Instance) SaveToWav

func (self Instance) SaveToWav(path string) error

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) SetData

func (self Instance) SetData(value []byte)

func (Instance) SetFormat

func (self Instance) SetFormat(value Format)

func (Instance) SetLoopBegin

func (self Instance) SetLoopBegin(value int)

func (Instance) SetLoopEnd

func (self Instance) SetLoopEnd(value int)

func (Instance) SetLoopMode

func (self Instance) SetLoopMode(value LoopMode)

func (Instance) SetMixRate

func (self Instance) SetMixRate(value int)

func (*Instance) SetObject

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

func (Instance) SetStereo

func (self Instance) SetStereo(value bool)

func (Instance) SetTags

func (self Instance) SetTags(value map[string]interface{})

func (Instance) Stereo

func (self Instance) Stereo() bool

func (Instance) Tags

func (self Instance) Tags() map[string]interface{}

func (Instance) Virtual

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

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"`
}

Jump to

Keyboard shortcuts

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