Documentation
¶
Overview ¶
Package alsa captures PCM audio by driving the /dev/snd ioctl interface directly.
This exists instead of binding tinyalsa through cgo. The kernel ioctl ABI is stable and the subset a capture-only client needs is small, so the whole thing is a few hundred lines of Go and echod stays a static, cgo-free binary — no NDK image, no C toolchain.
Several of these structures embed the kernel's unsigned long, so their size — and with it the ioctl number, which encodes that size — depends on the word size. The layouts below derive from it rather than assuming one, because a mismatch is not a subtle bug: the kernel rejects the call outright, or worse, reads the wrong bytes.
Index ¶
- Constants
- Variables
- type Capture
- type Config
- type Control
- type Mixer
- func (m *Mixer) Close() error
- func (m *Mixer) Controls() ([]Control, error)
- func (m *Mixer) Find(name string) (Control, error)
- func (m *Mixer) Get(c Control) ([]uint32, error)
- func (m *Mixer) GetEnum(name string) (string, error)
- func (m *Mixer) Set(c Control, v uint32) error
- func (m *Mixer) SetAll(c Control, values []uint32) error
- func (m *Mixer) SetBytes(name string, data []byte) error
- func (m *Mixer) SetEnum(name, item string) error
- func (m *Mixer) SetInt(name string, v uint32) error
- type Playback
Constants ¶
const ( TypeBoolean = 1 TypeInteger = 2 TypeEnumerated = 3 TypeBytes = 4 TypeInteger64 = 5 )
Control types.
const FormatS16_LE = 2
FormatS16_LE is 16-bit little endian, the only format the playback codec accepts.
const ( // FormatS24_3LE is 24 bits packed into 3 bytes — the only format the Echo Dot's // capture codec accepts. FormatS24_3LE = 32 )
Variables ¶
var ErrBusy = errors.New("alsa: device busy")
ErrBusy means another process holds the device.
var ErrOverrun = fmt.Errorf("alsa: capture overrun")
ErrOverrun means the hardware ring wrapped before we read it; audio was lost.
var ErrUnderrun = fmt.Errorf("alsa: playback underrun")
ErrUnderrun means the hardware ran out of samples; playback gapped.
Functions ¶
This section is empty.
Types ¶
type Capture ¶
type Capture struct {
// contains filtered or unexported fields
}
Capture is an open PCM capture stream.
func Open ¶
Open configures and starts a capture stream. The open is non-blocking so a device someone else holds returns ErrBusy instead of waiting; reads block normally once it is ours.
func (*Capture) FrameBytes ¶
FrameBytes is the size of one interleaved frame across all channels.
type Control ¶
type Control struct {
Numid uint32
Name string
Type uint32
Count uint32
Items []string
// The range of an integer control, zero for any other type.
Min, Max, Step int64
}
Control is one mixer control.
type Mixer ¶
type Mixer struct {
// contains filtered or unexported fields
}
Mixer is an open control device.
func OpenMixer ¶
OpenMixer opens a card's control device. Enumeration happens on first use and is cached: it costs over a second, so callers should not do it on a path where something is waiting.
func (*Mixer) Controls ¶
Controls lists the card's controls. There is no cheap way to ask how many there are, so this walks numids until the kernel stops recognising them.
The walk costs one ioctl per control plus one per item name of every enumerated control, which is over a second on this card, so the result is kept: the set does not change while the card is open.
func (*Mixer) SetAll ¶
SetAll writes one value per channel, for controls that carry a different value in each: a coefficient blob rather than a level.
type Playback ¶
type Playback struct {
// contains filtered or unexported fields
}
Playback is an open PCM playback stream.
func OpenPlayback ¶
OpenPlayback configures a playback stream. The hardware starts itself once the buffer is full.
The open is non-blocking: mediaserver holds this device, and a blocking open waits forever. A held device returns ErrBusy. Writes block normally once the device is ours.
func (*Playback) FrameBytes ¶
FrameBytes is the size of one interleaved frame across all channels.