Documentation
¶
Overview ¶
Package alsa provides a Go interface to the Linux ALSA subsystem, modeled after the tinyalsa library.
Index ¶
- Constants
- Variables
- func PcmBytesToFrames(p *PCM, bytes uint32) uint32
- func PcmFormatToBits(f PcmFormat) uint32
- func PcmFramesToBytes(p *PCM, frames uint32) uint32
- type Config
- type CtlAccessFlag
- type Mixer
- func (m *Mixer) AddNewCtls() error
- func (m *Mixer) Close() error
- func (m *Mixer) ConsumeEvent() error
- func (m *Mixer) Ctl(id uint32) (*MixerCtl, error)
- func (m *Mixer) CtlByIndex(index uint) (*MixerCtl, error)
- func (m *Mixer) CtlByName(name string) (*MixerCtl, error)
- func (m *Mixer) CtlByNameAndDevice(name string, device uint32) (*MixerCtl, error)
- func (m *Mixer) CtlByNameAndIndex(name string, index uint) (*MixerCtl, error)
- func (m *Mixer) CtlByNameAndSubdevice(name string, subdevice uint32) (*MixerCtl, error)
- func (m *Mixer) Fd() uintptr
- func (m *Mixer) Name() string
- func (m *Mixer) NumCtls() int
- func (m *Mixer) NumCtlsByName(name string) int
- func (m *Mixer) ReadEvent() (*MixerEvent, error)
- func (m *Mixer) SubscribeEvents(enable bool) error
- func (m *Mixer) WaitEvent(timeoutMs int) (bool, error)
- type MixerCtl
- func (ctl *MixerCtl) Access() uint32
- func (ctl *MixerCtl) AllEnumStrings() ([]string, error)
- func (ctl *MixerCtl) Array(array any) error
- func (ctl *MixerCtl) Device() uint32
- func (ctl *MixerCtl) EnumString(enumID uint) (string, error)
- func (ctl *MixerCtl) EnumValueString(index uint) (string, error)
- func (ctl *MixerCtl) ID() uint32
- func (ctl *MixerCtl) IsAccessTLVRw() bool
- func (ctl *MixerCtl) Name() string
- func (ctl *MixerCtl) NumEnums() (uint32, error)
- func (ctl *MixerCtl) NumValues() uint32
- func (ctl *MixerCtl) Percent(index uint) (int, error)
- func (ctl *MixerCtl) RangeMax() (int, error)
- func (ctl *MixerCtl) RangeMax64() (int64, error)
- func (ctl *MixerCtl) RangeMin() (int, error)
- func (ctl *MixerCtl) RangeMin64() (int64, error)
- func (ctl *MixerCtl) SetArray(array any) error
- func (ctl *MixerCtl) SetEnumByString(value string) error
- func (ctl *MixerCtl) SetPercent(index uint, percent int) error
- func (ctl *MixerCtl) SetValue(index uint, value int) error
- func (ctl *MixerCtl) SetValue64(index uint, value int64) error
- func (ctl *MixerCtl) String() string
- func (ctl *MixerCtl) Subdevice() uint32
- func (ctl *MixerCtl) Type() MixerCtlType
- func (ctl *MixerCtl) TypeString() string
- func (ctl *MixerCtl) Update() error
- func (ctl *MixerCtl) Value(index uint) (int, error)
- func (ctl *MixerCtl) Value64(index uint) (int64, error)
- type MixerCtlType
- type MixerEvent
- type MixerEventType
- type PCM
- func (p *PCM) AvailMax() (int, error)
- func (p *PCM) AvailUpdate() (int, error)
- func (p *PCM) BufferSize() uint32
- func (p *PCM) Channels() uint32
- func (p *PCM) Close() error
- func (p *PCM) Config() Config
- func (p *PCM) Delay() (int, error)
- func (p *PCM) Drain() error
- func (p *PCM) Error() string
- func (p *PCM) Fd() uintptr
- func (p *PCM) Flags() PcmFlag
- func (p *PCM) Format() PcmFormat
- func (p *PCM) FrameSize() uint32
- func (p *PCM) HWPtr() (hwPtr SndPcmUframesT, tstamp time.Time, err error)
- func (p *PCM) IsReady() bool
- func (p *PCM) KernelState() PcmState
- func (p *PCM) Link(other *PCM) error
- func (p *PCM) MmapBegin(wantFrames uint32) (buffer []byte, offsetFrames, actualFrames uint32, err error)
- func (p *PCM) MmapCommit(frames uint32) error
- func (p *PCM) MmapRead(data any) (int, error)
- func (p *PCM) MmapWrite(data any) (int, error)
- func (p *PCM) Pause(enable bool) error
- func (p *PCM) PeriodCount() uint32
- func (p *PCM) PeriodSize() uint32
- func (p *PCM) PeriodTime() time.Duration
- func (p *PCM) Prepare() error
- func (p *PCM) Rate() uint32
- func (p *PCM) Read(data any) error
- func (p *PCM) ReadI(buffer any, frames uint32) (int, error)
- func (p *PCM) ReadN(buffers [][]byte, frames uint32) (int, error)
- func (p *PCM) Resume() error
- func (p *PCM) SetConfig(config *Config) error
- func (p *PCM) Start() error
- func (p *PCM) State() (PcmState, error)
- func (p *PCM) Stop() error
- func (p *PCM) Subdevice() uint32
- func (p *PCM) Timestamp() (availFrames uint32, t time.Time, err error)
- func (p *PCM) Unlink() error
- func (p *PCM) Wait(timeoutMs int) (bool, error)
- func (p *PCM) Write(data any) error
- func (p *PCM) WriteI(data any, frames uint32) (int, error)
- func (p *PCM) WriteN(data [][]byte, frames uint32) (int, error)
- func (p *PCM) Xruns() int
- type PcmFlag
- type PcmFormat
- type PcmParam
- type PcmParamMask
- type PcmParams
- func (pp *PcmParams) FormatIsSupported(format PcmFormat) bool
- func (pp *PcmParams) Free()
- func (pp *PcmParams) Mask(param PcmParam) (*PcmParamMask, error)
- func (pp *PcmParams) RangeMax(param PcmParam) (uint32, error)
- func (pp *PcmParams) RangeMin(param PcmParam) (uint32, error)
- func (pp *PcmParams) String() string
- type PcmState
- type SndAesEbu
- type SndPcmSframesT
- type SndPcmUframesT
Constants ¶
const ( SNDRV_PCM_INTERVAL_OPENMIN = 1 << 0 SNDRV_PCM_INTERVAL_OPENMAX = 1 << 1 SNDRV_PCM_INTERVAL_INTEGER = 1 << 2 SNDRV_PCM_INTERVAL_EMPTY = 1 << 3 )
Constants for the bitfields within snd_interval.flags to match C enum.
const ( SNDRV_PCM_MMAP_OFFSET_STATUS = 0x80000000 SNDRV_PCM_MMAP_OFFSET_CONTROL = 0x81000000 )
ALSA MMAP offsets for status and control pages.
const ( SNDRV_PCM_SYNC_PTR_APPL = 1 << 0 SNDRV_PCM_SYNC_PTR_AVAIL_MIN = 1 << 2 SNDRV_PCM_SYNC_PTR_HWSYNC = 1 << 1 )
Variables ¶
var ( // PCM IOCTLs SNDRV_PCM_IOCTL_HW_REFINE uintptr SNDRV_PCM_IOCTL_HW_PARAMS uintptr SNDRV_PCM_IOCTL_SW_PARAMS uintptr SNDRV_PCM_IOCTL_INFO uintptr SNDRV_PCM_IOCTL_PAUSE uintptr SNDRV_PCM_IOCTL_RESUME uintptr SNDRV_PCM_IOCTL_PREPARE uintptr SNDRV_PCM_IOCTL_START uintptr SNDRV_PCM_IOCTL_DROP uintptr SNDRV_PCM_IOCTL_DRAIN uintptr SNDRV_PCM_IOCTL_DELAY uintptr SNDRV_PCM_IOCTL_LINK uintptr SNDRV_PCM_IOCTL_UNLINK uintptr SNDRV_PCM_IOCTL_HWSYNC uintptr SNDRV_PCM_IOCTL_SYNC_PTR uintptr SNDRV_PCM_IOCTL_TTSTAMP uintptr SNDRV_PCM_IOCTL_WRITEI_FRAMES uintptr SNDRV_PCM_IOCTL_READI_FRAMES uintptr SNDRV_PCM_IOCTL_WRITEN_FRAMES uintptr SNDRV_PCM_IOCTL_READN_FRAMES uintptr SNDRV_PCM_IOCTL_STATUS uintptr // Control IOCTLs SNDRV_CTL_IOCTL_CARD_INFO uintptr SNDRV_CTL_IOCTL_ELEM_LIST uintptr SNDRV_CTL_IOCTL_ELEM_INFO uintptr SNDRV_CTL_IOCTL_ELEM_READ uintptr SNDRV_CTL_IOCTL_ELEM_WRITE uintptr SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS uintptr SNDRV_CTL_IOCTL_TLV_READ uintptr SNDRV_CTL_IOCTL_TLV_WRITE uintptr )
var PcmParamAccessNames = []string{
"MMAP_INTERLEAVED",
"MMAP_NONINTERLEAVED",
"MMAP_COMPLEX",
"RW_INTERLEAVED",
"RW_NONINTERLEAVED",
}
PcmParamAccessNames provides human-readable names for PCM access types. The index corresponds to the SNDRV_PCM_ACCESS_* value.
var PcmParamFormatNames = map[PcmFormat]string{ PCM_FORMAT_S8: "S8", PCM_FORMAT_U8: "U8", PCM_FORMAT_S16_LE: "S16_LE", PCM_FORMAT_S16_BE: "S16_BE", PCM_FORMAT_U16_LE: "U16_LE", PCM_FORMAT_U16_BE: "U16_BE", PCM_FORMAT_S24_LE: "S24_LE", PCM_FORMAT_S24_BE: "S24_BE", PCM_FORMAT_U24_LE: "U24_LE", PCM_FORMAT_U24_BE: "U24_BE", PCM_FORMAT_S32_LE: "S32_LE", PCM_FORMAT_S32_BE: "S32_BE", PCM_FORMAT_U32_LE: "U32_LE", PCM_FORMAT_U32_BE: "U32_BE", PCM_FORMAT_FLOAT_LE: "FLOAT_LE", PCM_FORMAT_FLOAT_BE: "FLOAT_BE", PCM_FORMAT_FLOAT64_LE: "FLOAT64_LE", PCM_FORMAT_FLOAT64_BE: "FLOAT64_BE", PCM_FORMAT_IEC958_SUBFRAME_LE: "IEC958_SUBFRAME_LE", PCM_FORMAT_IEC958_SUBFRAME_BE: "IEC958_SUBFRAME_BE", PCM_FORMAT_MU_LAW: "MU_LAW", PCM_FORMAT_A_LAW: "A_LAW", PCM_FORMAT_IMA_ADPCM: "IMA_ADPCM", PCM_FORMAT_MPEG: "MPEG", PCM_FORMAT_GSM: "GSM", PCM_FORMAT_SPECIAL: "SPECIAL", PCM_FORMAT_S24_3LE: "S24_3LE", PCM_FORMAT_S24_3BE: "S24_3BE", PCM_FORMAT_U24_3LE: "U24_3LE", PCM_FORMAT_U24_3BE: "U24_3BE", PCM_FORMAT_S20_3LE: "S20_3LE", PCM_FORMAT_S20_3BE: "S20_3BE", PCM_FORMAT_U20_3LE: "U20_3LE", PCM_FORMAT_U20_3BE: "U20_3BE", PCM_FORMAT_S18_3LE: "S18_3LE", PCM_FORMAT_S18_3BE: "S18_3BE", PCM_FORMAT_U18_3LE: "U18_3LE", PCM_FORMAT_U18_3BE: "U18_3BE", }
PcmParamFormatNames provides human-readable names for PCM formats. The index corresponds to the PcmFormat (SNDRV_PCM_FORMAT_*) value.
var PcmParamSubformatNames = []string{
"STD",
}
PcmParamSubformatNames provides human-readable names for PCM subformats. The index corresponds to the SNDRV_PCM_SUBFORMAT_* value.
Functions ¶
func PcmBytesToFrames ¶
PcmBytesToFrames converts a number of bytes to the corresponding number of frames.
func PcmFormatToBits ¶
PcmFormatToBits returns the number of bits per sample for a given format. This reflects the space occupied in memory, so 24-bit formats in 32-bit containers return 32.
func PcmFramesToBytes ¶
PcmFramesToBytes converts a number of frames to the corresponding number of bytes.
Types ¶
type Config ¶
type Config struct {
Channels uint32
Rate uint32
PeriodSize uint32
PeriodCount uint32
Format PcmFormat
StartThreshold uint32
StopThreshold uint32
SilenceThreshold SndPcmUframesT
SilenceSize SndPcmUframesT
AvailMin uint32
}
Config encapsulates the hardware and software parameters of a PCM stream.
type CtlAccessFlag ¶
type CtlAccessFlag uint32
CtlAccessFlag defines the access permissions for a mixer control.
const ( // If set, the control is readable. SNDRV_CTL_ELEM_ACCESS_READ CtlAccessFlag = 1 << 0 // If set, the control is writable. SNDRV_CTL_ELEM_ACCESS_WRITE CtlAccessFlag = 1 << 1 // If set, the control uses the TLV mechanism for custom data structures. SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE CtlAccessFlag = 1 << 13 )
type Mixer ¶
type Mixer struct {
Ctls []*MixerCtl
// contains filtered or unexported fields
}
Mixer represents an open ALSA mixer device handle.
func MixerOpen ¶
MixerOpen opens the ALSA mixer for a given sound card and enumerates its controls. Note: This implementation does not support the ALSA plugin architecture and will only open direct hardware control devices (e.g., /dev/snd/controlC0).
func (*Mixer) AddNewCtls ¶
AddNewCtls scans for and adds any new controls that have appeared since the mixer was opened.
func (*Mixer) ConsumeEvent ¶
ConsumeEvent reads and discards a single pending mixer event.
func (*Mixer) CtlByIndex ¶
CtlByIndex returns a mixer control by its 0-based index in the enumerated list. The index is valid from 0 to NumCtls() - 1.
func (*Mixer) CtlByNameAndDevice ¶
CtlByNameAndDevice returns a mixer control handle by name and device number.
func (*Mixer) CtlByNameAndIndex ¶
CtlByNameAndIndex returns a specific mixer control handle by name and index.
func (*Mixer) CtlByNameAndSubdevice ¶
CtlByNameAndSubdevice returns a mixer control handle by name and subdevice number.
func (*Mixer) NumCtlsByName ¶
NumCtlsByName returns the number of controls that match the given name.
func (*Mixer) ReadEvent ¶
func (m *Mixer) ReadEvent() (*MixerEvent, error)
ReadEvent reads a pending mixer event from the device.
func (*Mixer) SubscribeEvents ¶
SubscribeEvents enables or disables event generation for this mixer handle.
type MixerCtl ¶
type MixerCtl struct {
// contains filtered or unexported fields
}
MixerCtl represents an individual mixer control handle.
func (*MixerCtl) AllEnumStrings ¶
AllEnumStrings returns a slice containing all possible string values for an enumerated control.
func (*MixerCtl) Array ¶
Array reads the entire multi-value array of a control. `array` must be a pointer to a slice of a type compatible with the control's type:
- MIXER_CTL_TYPE_BOOL, _INT, _ENUM: *[]int32
- MIXER_CTL_TYPE_BYTE: *[]byte
- MIXER_CTL_TYPE_INT64: *[]int64
- MIXER_CTL_TYPE_IEC958: *[]SndAesEbu (typically only one value)
func (*MixerCtl) EnumString ¶
EnumString returns the string associated with an enumerated value.
func (*MixerCtl) EnumValueString ¶
EnumValueString gets the string representation of the currently selected enumerated value. This is a convenience function that combines Value and EnumString.
func (*MixerCtl) IsAccessTLVRw ¶
IsAccessTLVRw checks if the control uses the TLV mechanism for custom data.
func (*MixerCtl) NumValues ¶
NumValues returns the number of values for the control (e.g., 2 for stereo volume).
func (*MixerCtl) RangeMax64 ¶
RangeMax64 returns the maximum value for an int64 control.
func (*MixerCtl) RangeMin64 ¶
RangeMin64 returns the minimum value for an int64 control.
func (*MixerCtl) SetArray ¶
SetArray writes an entire multi-value array to a control. `array` must be a slice of a type compatible with the control's type:
- MIXER_CTL_TYPE_BOOL, _INT, _ENUM: []int32
- MIXER_CTL_TYPE_BYTE: []byte
- MIXER_CTL_TYPE_INT64: []int64
- MIXER_CTL_TYPE_IEC958: []SndAesEbu
func (*MixerCtl) SetEnumByString ¶
SetEnumByString sets the value of an enumerated control by its string name.
func (*MixerCtl) SetPercent ¶
SetPercent sets the control's value as a percentage (0-100).
func (*MixerCtl) SetValue64 ¶
SetValue64 writes a single 64-bit integer value to a control at a given index.
func (*MixerCtl) String ¶
String returns a human-readable representation of the mixer control's properties and current state.
func (*MixerCtl) Type ¶
func (ctl *MixerCtl) Type() MixerCtlType
Type returns the data type of the control's value.
func (*MixerCtl) TypeString ¶
TypeString returns a string representation of the control's data type.
func (*MixerCtl) Update ¶
Update refreshes the control's information from the kernel. This is useful for checking for changes to a control's properties (like value ranges) after a mixer event of type SNDRV_CTL_EVENT_MASK_INFO.
type MixerCtlType ¶
type MixerCtlType int32
MixerCtlType defines the value type of mixer control.
const ( MIXER_CTL_TYPE_BOOL MixerCtlType = 0 MIXER_CTL_TYPE_INT MixerCtlType = 1 MIXER_CTL_TYPE_ENUM MixerCtlType = 2 MIXER_CTL_TYPE_BYTE MixerCtlType = 3 MIXER_CTL_TYPE_IEC958 MixerCtlType = 4 MIXER_CTL_TYPE_INT64 MixerCtlType = 5 MIXER_CTL_TYPE_UNKNOWN MixerCtlType = -1 )
type MixerEvent ¶
type MixerEvent struct {
Type MixerEventType
ControlID uint32 // The numid of the control that changed.
}
MixerEvent represents a notification from the ALSA control interface.
type MixerEventType ¶
type MixerEventType uint32
MixerEventType defines the type of event generated by the mixer.
const ( SNDRV_CTL_EVENT_ELEM = 0 // Indicates that a control element's value has changed. SNDRV_CTL_EVENT_MASK_VALUE MixerEventType = 1 << 0 // Indicates that a control element's metadata (e.g., range) has changed. SNDRV_CTL_EVENT_MASK_INFO MixerEventType = 1 << 1 // Indicates that a control element has been added. SNDRV_CTL_EVENT_MASK_ADD MixerEventType = 1 << 2 // Indicates a control element has been removed. SNDRV_CTL_EVENT_MASK_REMOVE MixerEventType = 1 << 3 )
type PCM ¶
type PCM struct {
// contains filtered or unexported fields
}
PCM represents an open ALSA PCM device handle.
func PcmOpen ¶
PcmOpen opens an ALSA PCM device and configures it according to the provided parameters. Note: This implementation does not support the ALSA plugin architecture and will only open direct hardware PCM devices (e.g., /dev/snd/pcmC0D0p).
func PcmOpenByName ¶
PcmOpenByName opens a PCM by its name, in the format "hw:C,D".
func (*PCM) AvailMax ¶
AvailMax returns the maximum number of frames that can be written to a playback stream or read from a capture stream. This function is only available for MMAP streams.
func (*PCM) AvailUpdate ¶
AvailUpdate synchronizes the PCM state with the kernel and returns the number of available frames. For playback streams, this is the number of frames that can be written. For capture streams, this is the number of frames that can be read. This function is only available for MMAP streams.
func (*PCM) BufferSize ¶
BufferSize returns the PCM's total buffer size in frames.
func (*PCM) Drain ¶
Drain waits for all pending frames in the buffer to be played. This is a blocking call and only applies to playback streams.
func (*PCM) Error ¶
Error returns the last error message as a string. This is useful for debugging setup or I/O failures. It is the Go equivalent of pcm_get_error().
func (*PCM) FrameSize ¶
FrameSize returns the size of a single frame in bytes. A frame contains one sample for each channel.
func (*PCM) HWPtr ¶
func (p *PCM) HWPtr() (hwPtr SndPcmUframesT, tstamp time.Time, err error)
HWPtr returns the current hardware pointer position and the corresponding timestamp. This function is only available for MMAP streams.
func (*PCM) KernelState ¶
KernelState returns the current state of the PCM stream by querying the kernel.
func (*PCM) Link ¶
Link establishes a start/stop synchronization between two PCMs. After this function is called, the two PCMs will prepare, start and stop in sync.
func (*PCM) MmapBegin ¶
func (p *PCM) MmapBegin(wantFrames uint32) (buffer []byte, offsetFrames, actualFrames uint32, err error)
MmapBegin prepares for a memory-mapped transfer. It returns a slice of the main buffer corresponding to the available contiguous space for writing or reading, the offset in frames from the start of the buffer, and the number of frames available in that slice.
func (*PCM) MmapCommit ¶
MmapCommit commits the number of frames transferred after a MmapBegin call.
func (*PCM) MmapRead ¶
MmapRead reads interleaved audio data from a capture MMAP PCM device. data must be a slice of a supported numeric type (e.g., []int16, []float32) that will receive the data. It automatically handles waiting for data and starting the stream on the first read.
func (*PCM) MmapWrite ¶
MmapWrite writes interleaved audio data to a playback MMAP PCM device. data must be a slice of a supported numeric type (e.g., []int16, []float32). It automatically handles waiting for buffer space and starting the stream once the 'StartThreshold' is met.
func (*PCM) Pause ¶
Pause pauses or resumes the PCM stream. Calling Pause(true) on a running stream will pause it. Calling Pause(false) on a paused stream will resume it.
func (*PCM) PeriodCount ¶
PeriodCount returns the number of periods in the buffer.
func (*PCM) PeriodSize ¶
PeriodSize returns the number of frames per period.
func (*PCM) PeriodTime ¶
PeriodTime returns the duration of a single period.
func (*PCM) Prepare ¶
Prepare readies the PCM device for I/O operations. This is typically used to recover from an XRUN.
func (*PCM) Read ¶
Read reads audio samples from a PCM device. This function is for compatibility with tinyalsa's deprecated pcm_read. It calculates the number of frames based on the buffer slice size and calls ReadI. data must be a slice of a supported numeric type (e.g., []int16, []float32). Returns nil on success or an error on failure.
func (*PCM) ReadI ¶
ReadI reads interleaved audio data from a capture PCM device using an ioctl call. buffer must be a slice of a supported numeric type (e.g., []int16, []float32). This is the idiomatic way to perform blocking I/O with ALSA. It automatically starts the stream, recovers from overruns (EPIPE), and loops until the buffer is filled with the requested number of frames or an unrecoverable error occurs. Returns the number of frames actually read.
func (*PCM) ReadN ¶
ReadN reads non-interleaved audio data from a capture PCM device. This function is for non-MMAP, non-interleaved access. The provided `buffers` slice must contain one slice per channel (e.g., `[][]byte`), each large enough to hold 'frames' of audio data. It uses the `SNDRV_PCM_IOCTL_READN_FRAMES` ioctl. Like ReadI, it handles overruns by preparing and retrying the read. Returns the number of frames actually read.
func (*PCM) SetConfig ¶
SetConfig sets the hardware and software parameters for the PCM device. This function should be called before the stream is started. If called on an already configured stream, it will attempt to reconfigure it, which may only succeed if the stream is stopped.
func (*PCM) Start ¶
Start explicitly starts the PCM stream. It ensures the stream is prepared before starting.
func (*PCM) Timestamp ¶
Timestamp returns available frames and the corresponding timestamp. The clock source is CLOCK_MONOTONIC if the PCM_MONOTONIC flag was used, otherwise it is CLOCK_REALTIME. This function is only available for MMAP streams.
func (*PCM) Wait ¶
Wait waits for the PCM to become ready for I/O or until a timeout occurs. Returns true if the device is ready, false on timeout. On error, it may return a specific error code like EPIPE, ESTRPIPE, ENODEV, or EIO.
func (*PCM) Write ¶
Write writes audio samples to a PCM device. This function is for compatibility with tinyalsa's deprecated pcm_write. It calculates the number of frames based on the input slice size and calls WriteI. data must be a slice of a supported numeric type (e.g., []int16, []float32). Returns nil on success or an error on failure.
func (*PCM) WriteI ¶
WriteI writes interleaved audio data to a playback PCM device using an ioctl call. data must be a slice of a supported numeric type (e.g., []int16, []float32). This is the idiomatic way to perform blocking I/O with ALSA. It automatically prepares and starts the stream, recovers from underruns (EPIPE), and loops until all requested frames have been written or an unrecoverable error occurs. Returns the number of frames actually written.
func (*PCM) WriteN ¶
WriteN writes non-interleaved audio data to a playback PCM device. This function is for non-MMAP, non-interleaved access. It is less common than interleaved I/O. The `data` slice should contain one slice per channel (e.g., `[][]byte`), each containing 'frames' worth of sample data. It uses the `SNDRV_PCM_IOCTL_WRITEN_FRAMES` ioctl. Like WriteI, it handles underruns by preparing and retrying the write. Returns the number of frames actually written.
type PcmFlag ¶
type PcmFlag uint32
PcmFlag defines flags for opening a PCM stream.
const ( // PCM_OUT specifies a playback stream. PCM_OUT PcmFlag = 0 // PCM_IN specifies a capture stream. PCM_IN PcmFlag = 0x10000000 // PCM_MMAP specifies that the stream will use memory-mapped I/O. PCM_MMAP PcmFlag = 0x00000001 // PCM_NONBLOCK specifies that I/O operations should not block. PCM_NONBLOCK PcmFlag = 0x00000010 // PCM_NORESTART specifies that the driver should not automatically restart the stream on underrun. PCM_NORESTART PcmFlag = 0x00000002 // PCM_MONOTONIC requests monotonic timestamps instead of wall clock time. PCM_MONOTONIC PcmFlag = 0x00000004 // PCM_NOIRQ specifies that the driver should not generate IRQs for every period. // This is an optimization for MMAP streams that can reduce CPU usage. // When used, Wait() will use a calculated timeout instead of blocking indefinitely. PCM_NOIRQ PcmFlag = 0x00000008 )
type PcmFormat ¶
type PcmFormat int32
PcmFormat defines the sample format for a PCM stream. These values correspond to the SNDRV_PCM_FORMAT_* constants in the ALSA kernel headers.
const ( PCM_FORMAT_INVALID PcmFormat = -1 PCM_FORMAT_S8 PcmFormat = 0 PCM_FORMAT_U8 PcmFormat = 1 PCM_FORMAT_S16_LE PcmFormat = 2 PCM_FORMAT_S16_BE PcmFormat = 3 PCM_FORMAT_U16_LE PcmFormat = 4 PCM_FORMAT_U16_BE PcmFormat = 5 PCM_FORMAT_S24_LE PcmFormat = 6 PCM_FORMAT_S24_BE PcmFormat = 7 PCM_FORMAT_U24_LE PcmFormat = 8 PCM_FORMAT_U24_BE PcmFormat = 9 PCM_FORMAT_S32_LE PcmFormat = 10 PCM_FORMAT_S32_BE PcmFormat = 11 PCM_FORMAT_U32_LE PcmFormat = 12 PCM_FORMAT_U32_BE PcmFormat = 13 PCM_FORMAT_FLOAT_LE PcmFormat = 14 PCM_FORMAT_FLOAT_BE PcmFormat = 15 PCM_FORMAT_FLOAT64_LE PcmFormat = 16 PCM_FORMAT_FLOAT64_BE PcmFormat = 17 PCM_FORMAT_IEC958_SUBFRAME_LE PcmFormat = 18 PCM_FORMAT_IEC958_SUBFRAME_BE PcmFormat = 19 PCM_FORMAT_MU_LAW PcmFormat = 20 PCM_FORMAT_A_LAW PcmFormat = 21 PCM_FORMAT_IMA_ADPCM PcmFormat = 22 PCM_FORMAT_MPEG PcmFormat = 23 PCM_FORMAT_GSM PcmFormat = 24 PCM_FORMAT_SPECIAL PcmFormat = 31 PCM_FORMAT_S24_3LE PcmFormat = 32 PCM_FORMAT_S24_3BE PcmFormat = 33 PCM_FORMAT_U24_3LE PcmFormat = 34 PCM_FORMAT_U24_3BE PcmFormat = 35 PCM_FORMAT_S20_3LE PcmFormat = 36 PCM_FORMAT_S20_3BE PcmFormat = 37 PCM_FORMAT_U20_3LE PcmFormat = 38 PCM_FORMAT_U20_3BE PcmFormat = 39 PCM_FORMAT_S18_3LE PcmFormat = 40 PCM_FORMAT_S18_3BE PcmFormat = 41 PCM_FORMAT_U18_3LE PcmFormat = 42 PCM_FORMAT_U18_3BE PcmFormat = 43 )
type PcmParam ¶
type PcmParam int
PcmParam identifies a hardware parameter for a PCM device. These values correspond to the SNDRV_PCM_HW_PARAM_* constants.
const ( PCM_PARAM_ACCESS PcmParam = 0 PCM_PARAM_FORMAT PcmParam = 1 PCM_PARAM_SUBFORMAT PcmParam = 2 PCM_PARAM_SAMPLE_BITS PcmParam = 8 PCM_PARAM_FRAME_BITS PcmParam = 9 PCM_PARAM_CHANNELS PcmParam = 10 PCM_PARAM_RATE PcmParam = 11 PCM_PARAM_PERIOD_TIME PcmParam = 12 PCM_PARAM_PERIOD_SIZE PcmParam = 13 PCM_PARAM_PERIOD_BYTES PcmParam = 14 PCM_PARAM_PERIODS PcmParam = 15 PCM_PARAM_BUFFER_TIME PcmParam = 16 PCM_PARAM_BUFFER_SIZE PcmParam = 17 PCM_PARAM_BUFFER_BYTES PcmParam = 18 PCM_PARAM_TICK_TIME PcmParam = 19 )
type PcmParamMask ¶
type PcmParamMask struct {
// contains filtered or unexported fields
}
PcmParamMask represents a bitmask for a PCM hardware parameter. It allows checking which specific capabilities (e.g., formats) are supported.
func (*PcmParamMask) Test ¶
func (m *PcmParamMask) Test(bit uint) bool
Test checks if a specific bit in the mask is set.
type PcmParams ¶
type PcmParams struct {
// contains filtered or unexported fields
}
PcmParams represents the hardware capabilities of a PCM device.
func PcmParamsGet ¶
PcmParamsGet queries the hardware parameters for a given PCM device without fully opening it. This is useful for discovering device capabilities.
func (*PcmParams) FormatIsSupported ¶
FormatIsSupported checks if a given PCM format is supported.
func (*PcmParams) Free ¶
func (pp *PcmParams) Free()
Free releases the resources associated with PcmParams.
func (*PcmParams) Mask ¶
func (pp *PcmParams) Mask(param PcmParam) (*PcmParamMask, error)
Mask returns the bitmask for a mask-type parameter.
type PcmState ¶
type PcmState int32
PcmState defines the current state of a PCM stream. These values correspond to the SNDRV_PCM_STATE_* constants.
const ( PCM_STATE_OPEN PcmState = 0 // Stream is open. PCM_STATE_SETUP PcmState = 1 // Stream has a setup. PCM_STATE_PREPARED PcmState = 2 // Stream is ready to start. PCM_STATE_RUNNING PcmState = 3 // Stream is running. PCM_STATE_XRUN PcmState = 4 // Stream reached an underrun or overrun. PCM_STATE_DRAINING PcmState = 5 // Stream is draining. PCM_STATE_PAUSED PcmState = 6 // Stream is paused. PCM_STATE_SUSPENDED PcmState = 7 // Hardware is suspended. PCM_STATE_DISCONNECTED PcmState = 8 // Hardware is disconnected. )
type SndAesEbu ¶
SndAesEbu is the Go representation of the C struct for IEC958 (S/PDIF) data. It is part of the sndCtlElemValue union.
type SndPcmSframesT ¶ added in v0.2.1
type SndPcmSframesT = int64
SndPcmSframesT is a signed long in the ALSA headers. On 64-bit architectures, this is a 64-bit signed integer.
type SndPcmUframesT ¶
type SndPcmUframesT = uint64
SndPcmUframesT is an unsigned long in the ALSA headers. On 64-bit architectures, this is a 64-bit unsigned integer.