audio

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	OutputSampleRate = 48000
	OutputChannels   = 2
	BytesPerSample   = 4
	BytesPerFrame    = OutputChannels * BytesPerSample
	BytesPerSecond   = OutputSampleRate * BytesPerFrame
)

Variables

This section is empty.

Functions

func NormalizeSigned

func NormalizeSigned[T ~int | ~int16 | ~int32](sample T, bits int) float32

func ResampledFrameCount

func ResampledFrameCount(sourceFrames int64, sourceRate int) int64

func Resume

func Resume() error

func Suspend

func Suspend() error

Types

type Clip

type Clip struct {
	// contains filtered or unexported fields
}

func DecodeClip

func DecodeClip(format Format, source Source, decode func([]byte) (DecodedAudio, error)) (*Clip, error)

DecodeClip decodes a static source and releases it before returning.

func NewClip

func NewClip(format Format, decoded DecodedAudio) (*Clip, error)

NewClip prepares decoded samples at the engine's fixed stereo sample rate.

func NewStreamingClip

func NewStreamingClip(format Format, source Source, sampleRate int, sourceFrames int64, open func(Source) (io.ReadSeekCloser, error)) (*Clip, error)

NewStreamingClip creates a clip whose format implementation supplies its stream reader. The callback is installed once while loading the resource and is not a runtime registry.

func (*Clip) Close

func (c *Clip) Close() error

func (*Clip) Duration

func (c *Clip) Duration() time.Duration

func (*Clip) Format

func (c *Clip) Format() Format

func (*Clip) NewPlayer

func (c *Clip) NewPlayer() (*Player, error)

func (*Clip) Streaming

func (c *Clip) Streaming() bool

type DecodedAudio

type DecodedAudio struct {
	Samples    []float32
	SampleRate int
	Channels   int
}

DecodedAudio is the PCM data supplied by an audio format decoder.

type Decoder

type Decoder interface {
	DecodeAudio(Source, Format, bool) (*Clip, error)
}

Decoder decodes one statically selected collection of audio formats. Implementations are passed to project resource features as type arguments.

type DecoderSet

type DecoderSet[A, B, C, D FormatDecoder] struct{}

DecoderSet is a compile-time collection of audio format decoders. It does not register formats or allocate while choosing a decoder.

func (DecoderSet[A, B, C, D]) DecodeAudio

func (DecoderSet[A, B, C, D]) DecodeAudio(source Source, format Format, stream bool) (*Clip, error)

type Format

type Format string
const (
	FormatFLAC Format = "flac"
	FormatMP3  Format = "mp3"
	FormatOGG  Format = "ogg"
	FormatWAV  Format = "wav"
)

func FormatFromPath

func FormatFromPath(path string) (Format, error)

type FormatDecoder

type FormatDecoder interface {
	SupportsAudioFormat(Format) bool
	DecodeAudio(Source, Format, bool) (*Clip, error)
}

FormatDecoder handles one audio format in DecoderSet.

type MemorySource

type MemorySource struct {
	// contains filtered or unexported fields
}

MemorySource owns one immutable encoded audio byte slice.

func NewMemorySource

func NewMemorySource(data []byte) *MemorySource

NewMemorySource takes ownership of data. It must not be mutated afterward.

func (*MemorySource) Bytes

func (s *MemorySource) Bytes() ([]byte, error)

func (*MemorySource) Close

func (s *MemorySource) Close() error

func (*MemorySource) Open

func (s *MemorySource) Open() (io.ReadSeekCloser, error)

func (*MemorySource) Size

func (s *MemorySource) Size() int64

type NoDecoder

type NoDecoder struct{}

NoDecoder fills an unused DecoderSet slot.

func (NoDecoder) DecodeAudio

func (NoDecoder) DecodeAudio(source Source, format Format, _ bool) (*Clip, error)

func (NoDecoder) SupportsAudioFormat

func (NoDecoder) SupportsAudioFormat(Format) bool

type Player

type Player struct {
	// contains filtered or unexported fields
}

func (*Player) Close

func (p *Player) Close() error

func (*Player) Duration

func (p *Player) Duration() time.Duration

func (*Player) Err

func (p *Player) Err() error

func (*Player) IsPlaying

func (p *Player) IsPlaying() bool

func (*Player) Pause

func (p *Player) Pause() error

func (*Player) Play

func (p *Player) Play() error

func (*Player) Position

func (p *Player) Position() time.Duration

func (*Player) Seek

func (p *Player) Seek(position time.Duration) error

func (*Player) SetVolume

func (p *Player) SetVolume(volume float64) error

func (*Player) Stop

func (p *Player) Stop() error

func (*Player) Volume

func (p *Player) Volume() float64

type Source

type Source interface {
	Bytes() ([]byte, error)
	Open() (io.ReadSeekCloser, error)
	Size() int64
	Close() error
}

Source is an immutable encoded audio resource. DecodeAudio takes ownership of the source whether decoding succeeds or fails.

Directories

Path Synopsis
Package codec provides the full built-in audio decoder collection.
Package codec provides the full built-in audio decoder collection.
mp3
wav

Jump to

Keyboard shortcuts

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