Documentation
¶
Overview ¶
Package audio is the playback engine: it streams, decrypts and decodes Deezer audio (MP3 + FLAC) into a PCM ring that an output device drains. Supports seek, per-track ReplayGain, gapless transitions and (experimental) crossfade. In-memory only — nothing is written to disk.
The output device is abstracted behind the `output` interface so the backend is build-tag-selected: malgo/miniaudio by default (adds output-device selection), or oto under the `otosink` tag — used for the macOS GUI, where malgo's CoreAudio callback runs unreliably inside the c-archive.
Index ¶
- Variables
- type Device
- type Player
- func (p *Player) AddVolume(delta float64) float64
- func (p *Player) CancelSleepTimer()
- func (p *Player) ClearPreload()
- func (p *Player) Close()
- func (p *Player) CrossfadeMS() int
- func (p *Player) CurrentDevice() string
- func (p *Player) Devices() ([]Device, error)
- func (p *Player) DurationMS() int64
- func (p *Player) EQBands() []float64
- func (p *Player) EQEnabled() bool
- func (p *Player) EQGains() []float64
- func (p *Player) EQPreampDB() float64
- func (p *Player) EQPreset() string
- func (p *Player) Format() string
- func (p *Player) Gapless() bool
- func (p *Player) LastError() string
- func (p *Player) MonoDownmix() bool
- func (p *Player) Pause()
- func (p *Player) Play(plan *deezer.StreamPlan, durationMS int64) error
- func (p *Player) PositionMS() int64
- func (p *Player) Preload(plan *deezer.StreamPlan, durationMS int64)
- func (p *Player) ReplayGain() bool
- func (p *Player) Resume()
- func (p *Player) SeekMS(ms int64)
- func (p *Player) SetCrossfadeMS(ms int)
- func (p *Player) SetDevice(id string) error
- func (p *Player) SetEQEnabled(on bool)
- func (p *Player) SetEQGain(band int, db float64) error
- func (p *Player) SetEQGains(db []float64) error
- func (p *Player) SetEQPreamp(db float64)
- func (p *Player) SetEQPreset(name string) error
- func (p *Player) SetGapless(on bool)
- func (p *Player) SetMonoDownmix(on bool)
- func (p *Player) SetOnFinish(fn func())
- func (p *Player) SetOutputSuspended(on bool) error
- func (p *Player) SetReplayGain(on bool)
- func (p *Player) SetSleepTimer(d time.Duration, endOfTrack bool)
- func (p *Player) SetVolume(v float64)
- func (p *Player) SleepActive() bool
- func (p *Player) SleepEndOfTrack() bool
- func (p *Player) SleepRemainingMS() int64
- func (p *Player) State() State
- func (p *Player) Stop()
- func (p *Player) TogglePause()
- func (p *Player) Volume() float64
- type State
Constants ¶
This section is empty.
Variables ¶
var EQPresetNames = []string{
"flat", "bass-boost", "bass-reducer", "treble-boost", "vocal",
"rock", "pop", "jazz", "classical", "electronic",
}
EQPresetNames is the preset order every client shows (core-owned so the UIs stay identical). "custom" is implicit: any manual band edit switches to it.
Functions ¶
This section is empty.
Types ¶
type Device ¶ added in v0.4.0
Device is an output device the user can pick (empty ID = system default).
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player owns the malgo context + one output device and plays a current source, optionally with a preloaded next source for gapless/crossfade.
func (*Player) CancelSleepTimer ¶ added in v1.6.0
func (p *Player) CancelSleepTimer()
CancelSleepTimer disarms the sleep timer and restores full volume.
func (*Player) ClearPreload ¶ added in v1.6.0
func (p *Player) ClearPreload()
ClearPreload discards any preloaded next source. Call when the upcoming track is no longer determined (e.g. shuffle/repeat was toggled after a linear-next was preloaded) so a stale preload can't be gaplessly swapped in.
func (*Player) Close ¶ added in v0.4.0
func (p *Player) Close()
Close tears down sources and the output device.
func (*Player) CrossfadeMS ¶ added in v0.4.0
func (*Player) CurrentDevice ¶ added in v0.4.0
CurrentDevice returns the selected device id ("" = default).
func (*Player) DurationMS ¶
func (*Player) EQPreampDB ¶ added in v1.7.0
EQPreampDB returns the preamp in dB.
func (*Player) EQPreset ¶ added in v1.7.0
EQPreset returns the current preset name ("custom" after manual edits).
func (*Player) MonoDownmix ¶ added in v1.7.0
MonoDownmix reports whether mono downmix is on.
func (*Player) Play ¶
func (p *Player) Play(plan *deezer.StreamPlan, durationMS int64) error
Play starts a track immediately, replacing anything current.
func (*Player) PositionMS ¶
func (*Player) Preload ¶ added in v0.4.0
func (p *Player) Preload(plan *deezer.StreamPlan, durationMS int64)
Preload prepares the next track so the transition is gapless/crossfaded. It is a no-op if gapless is disabled.
func (*Player) ReplayGain ¶ added in v0.3.0
func (*Player) SetCrossfadeMS ¶ added in v0.4.0
func (*Player) SetDevice ¶ added in v0.4.0
SetDevice switches output to the given device id ("" = system default).
func (*Player) SetEQEnabled ¶ added in v1.7.0
SetEQEnabled turns the equalizer on/off (mono downmix is independent).
func (*Player) SetEQGain ¶ added in v1.7.0
SetEQGain sets one band's gain in dB (clamped to ±12). Preset becomes "custom".
func (*Player) SetEQGains ¶ added in v1.7.0
SetEQGains sets all band gains in dB (clamped). Preset becomes "custom".
func (*Player) SetEQPreamp ¶ added in v1.7.0
SetEQPreamp sets the output preamp in dB (clamped to ±12), for taming clipping when several bands are boosted.
func (*Player) SetEQPreset ¶ added in v1.7.0
SetEQPreset applies a named preset's band gains.
func (*Player) SetGapless ¶ added in v0.4.0
SetGapless enables/disables gapless transitions between tracks.
func (*Player) SetMonoDownmix ¶ added in v1.7.0
SetMonoDownmix folds stereo to mono (accessibility / single-speaker setups).
func (*Player) SetOnFinish ¶
func (p *Player) SetOnFinish(fn func())
func (*Player) SetOutputSuspended ¶ added in v1.7.0
SetOutputSuspended releases (on=true) or restores (on=false) the OS audio output without tearing down playback state (decoder, ring, position). Use it on audio-focus loss/interruption (e.g. iOS): playback resumes where it left off. Safe to call from any goroutine.
func (*Player) SetReplayGain ¶ added in v0.3.0
func (*Player) SetSleepTimer ¶ added in v1.6.0
SetSleepTimer arms the sleep timer. When endOfTrack is true the player pauses once the current track finishes (d is ignored); otherwise it fades out over the last few seconds and pauses after d elapses. d <= 0 with endOfTrack false cancels any armed timer.
func (*Player) SleepActive ¶ added in v1.6.0
SleepActive reports whether a sleep timer is armed.
func (*Player) SleepEndOfTrack ¶ added in v1.6.0
SleepEndOfTrack reports whether the armed timer is in end-of-track mode.
func (*Player) SleepRemainingMS ¶ added in v1.6.0
SleepRemainingMS returns the milliseconds until the timer fires: for duration mode the wall-clock remainder, for end-of-track mode the current track's remaining time. Returns 0 when no timer is armed.
func (*Player) TogglePause ¶
func (p *Player) TogglePause()