audio

package
v2.16.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: GPL-3.0 Imports: 20 Imported by: 1 module, 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

Overview

Package audio provides cross-platform audio playback using malgo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LongformPlaybackManager added in v2.15.0

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

LongformPlaybackManager manages primary and background long-form audio slots. Each slot streams audio through the shared global output device via a ring-buffer prefetch goroutine — no full-file decode into RAM.

func NewLongformPlaybackManager added in v2.15.0

func NewLongformPlaybackManager() *LongformPlaybackManager

NewLongformPlaybackManager creates a new LongformPlaybackManager.

func (*LongformPlaybackManager) Pause added in v2.15.0

func (m *LongformPlaybackManager) Pause(slot string) error

func (*LongformPlaybackManager) Play added in v2.15.0

func (m *LongformPlaybackManager) Play(slot, path string, opts PlaybackOptions) error

func (*LongformPlaybackManager) Resume added in v2.15.0

func (m *LongformPlaybackManager) Resume(slot string) error

func (*LongformPlaybackManager) Seek added in v2.15.0

func (m *LongformPlaybackManager) Seek(slot string, offset time.Duration) error

func (*LongformPlaybackManager) SetDrainCallback added in v2.15.0

func (m *LongformPlaybackManager) SetDrainCallback(slot string, fn func(natural bool))

SetDrainCallback registers fn to be called when a slot drains. natural is true when the track reached EOF on its own; false when stopped or replaced. This is not part of the PlaybackManager interface and is called at service startup.

func (*LongformPlaybackManager) State added in v2.15.0

func (*LongformPlaybackManager) Stop added in v2.15.0

func (m *LongformPlaybackManager) Stop(slot string) error

func (*LongformPlaybackManager) TogglePause added in v2.15.0

func (m *LongformPlaybackManager) TogglePause(slot string) error

type MalgoPlayer added in v2.9.1

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

MalgoPlayer plays short audio via the shared malgo output device. Decoded and resampled PCM samples are cached per file path so repeated playback (e.g. scan feedback sounds) does not re-decode or re-resample; the realtime audio callback only sums already-prepared samples into the mix buffer.

A new Play call cancels the previous one-shot; only one scan sound plays at a time.

func NewMalgoPlayer added in v2.9.1

func NewMalgoPlayer() *MalgoPlayer

NewMalgoPlayer creates a new MalgoPlayer instance.

func (*MalgoPlayer) ClearFileCache added in v2.9.1

func (p *MalgoPlayer) ClearFileCache()

ClearFileCache clears the in-memory PCM cache, forcing subsequent PlayFile calls to re-read and re-decode from disk. Called after settings reload to pick up new files.

func (*MalgoPlayer) PlayBytes added in v2.11.0

func (p *MalgoPlayer) PlayBytes(data []byte) error

PlayBytes plays audio from a byte slice asynchronously, detecting format from magic bytes. Supports WAV, OGG (Vorbis), MP3, and FLAC.

func (*MalgoPlayer) PlayFile added in v2.9.1

func (p *MalgoPlayer) PlayFile(path string) error

PlayFile plays an audio file asynchronously, detecting format by extension. Supports WAV, MP3, OGG (Vorbis), and FLAC. Cancels any currently playing sound. Decoded+resampled PCM is cached per path so repeat plays skip the decode work.

func (*MalgoPlayer) SetVolume added in v2.11.0

func (p *MalgoPlayer) SetVolume(volume float64)

SetVolume sets the playback volume (0.0–2.0). Applies to subsequent playback calls.

type PlaybackManager added in v2.15.0

type PlaybackManager interface {
	Play(slot, path string, opts PlaybackOptions) error
	Stop(slot string) error
	Pause(slot string) error
	Resume(slot string) error
	TogglePause(slot string) error
	Seek(slot string, offset time.Duration) error
	State(slot string) PlaybackState
}

PlaybackManager is the interface for managing long-form audio slots.

type PlaybackOptions added in v2.15.0

type PlaybackOptions struct {
	// Volume is the playback gain (0.0–2.0); 0 defaults to 1.0.
	Volume float64
}

PlaybackOptions configures a long-form Play call.

type PlaybackState added in v2.15.0

type PlaybackState struct {
	Path     string
	Position time.Duration
	Duration time.Duration
	Playing  bool
	Paused   bool
}

PlaybackState describes the current state of a slot.

type Player added in v2.9.1

type Player interface {
	PlayBytes(data []byte) error
	PlayFile(path string) error
	ClearFileCache()
	SetVolume(volume float64)
}

Player is the interface for audio playback, allowing tests to mock sound output.

Jump to

Keyboard shortcuts

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