Documentation
¶
Overview ¶
Package pcmoutput drives pull-based PCM playback over a frame-oriented audio device such as Linux ALSA.
Index ¶
Constants ¶
const ( MinLatencyMicros = 4_000 DefaultLatencyMicros = 40_000 FallbackLatencyMicros = 100_000 MaxLatencyMicros = 500_000 )
DefaultLatencyMicros and fallback bounds used when negotiating a device buffer duration in microseconds from an optional latency hint.
Variables ¶
var ( // ErrAgain reports that the device buffer is full or a call was // interrupted by a signal and should be retried after waiting. ErrAgain = errors.New("nsgo: audio: PCM device temporarily busy") // ErrXRun reports a hardware or server underrun (such as ALSA -EPIPE) // that requires Prepare before writing resumes. ErrXRun = errors.New("nsgo: audio: PCM buffer underrun") // ErrSuspended reports that the audio device was suspended (such as // ALSA -ESTRPIPE). ErrSuspended = errors.New("nsgo: audio: PCM device suspended") // ErrDisconnected reports that the audio device was disconnected or // became unusable (such as ALSA -ENODEV). ErrDisconnected = errors.New("nsgo: audio: PCM device disconnected") )
Functions ¶
func LatencyCandidates ¶
LatencyCandidates returns ordered ALSA-style buffer latencies in microseconds to try for hint, falling back to safe defaults if the device rejects a tight hint.
Types ¶
type Device ¶
type Device interface {
// BufferFrames and PeriodFrames return the negotiated ring buffer and
// per-callback period lengths in frames.
BufferFrames() int
PeriodFrames() int
// Prepare transitions the device into a ready-to-write state.
Prepare() error
// AvailDelay returns the frames currently available to write and the
// frames still queued ahead of playback. delayOK is false if the device
// cannot report delay.
AvailDelay() (avail int, delay int64, delayOK bool, err error)
// Wait blocks up to timeout until the device can accept more frames,
// reporting whether space became available.
Wait(timeout time.Duration) (ready bool, err error)
// Write writes interleaved Float32 samples and returns the frames accepted.
Write(samples []float32) (frames int, err error)
// Drop immediately stops playback and discards queued frames.
Drop()
// Close releases the underlying device handle.
Close()
}
Device is the low-level PCM sink owned by one Stream. After New, Device methods are called only under the stream's control lock while stopped or exclusively from the pull goroutine while running.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream implements driver.AudioOutput by pulling PCM periods on a dedicated goroutine and feeding them to a Device.
func New ¶
func New(dev Device, conf driver.AudioOutputConfig) *Stream
New constructs a paused Stream over dev. Call Start to begin pulling samples.
func (*Stream) Close ¶
func (s *Stream) Close()
Close stops rendering and releases the device. Calling it again has no effect.
func (*Stream) Flush ¶
Flush stops rendering, discards queued frames not yet played, reports the number of discarded client-rendered frames and restarts if active.
func (*Stream) Latency ¶
Latency returns the most recent device buffer latency, or zero before the first render.
func (*Stream) Pause ¶
func (s *Stream) Pause()
Pause stops rendering, discards queued frames and freezes Position.
func (*Stream) Position ¶
Position returns the monotonic count of frames that reached the device and the host timestamp of the most recent advance.