asoundlib

package
v0.0.0-...-bf6d460 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: GPL-3.0 Imports: 3 Imported by: 2

Documentation

Overview

asoundlib package is the simple wrapper for C alsa binding library.

Index

Constants

View Source
const (
	// Playback stream
	StreamTypePlayback = C.SND_PCM_STREAM_PLAYBACK
	// Capture stream
	StreamTypeCapture = C.SND_PCM_STREAM_CAPTURE
)

Stream type constants.

View Source
const (
	// Unknown
	SampleFormatUnknown = C.SND_PCM_FORMAT_UNKNOWN
	// Signed 8 bit
	SampleFormatS8 = C.SND_PCM_FORMAT_S8
	// Unsigned 8 bit
	SampleFormatU8 = C.SND_PCM_FORMAT_U8
	// Signed 16 bit Little Endian
	SampleFormatS16LE = C.SND_PCM_FORMAT_S16_LE
	// Signed 16 bit Big Endian
	SampleFormatS16BE = C.SND_PCM_FORMAT_S16_BE
	// Unsigned 16 bit Little Endian
	SampleFormatU16LE = C.SND_PCM_FORMAT_U16_LE
	// Unsigned 16 bit Big Endian
	SampleFormatU16BE = C.SND_PCM_FORMAT_U16_BE
	// SND_PCM_FORMAT_S24_LE 	Signed 24 bit Little Endian using low three bytes in 32-bit word
	// SND_PCM_FORMAT_S24_BE 	Signed 24 bit Big Endian using low three bytes in 32-bit word
	// SND_PCM_FORMAT_U24_LE 	Unsigned 24 bit Little Endian using low three bytes in 32-bit word
	// SND_PCM_FORMAT_U24_BE 	Unsigned 24 bit Big Endian using low three bytes in 32-bit word
	// SND_PCM_FORMAT_S32_LE 	Signed 32 bit Little Endian
	// SND_PCM_FORMAT_S32_BE 	Signed 32 bit Big Endian
	// SND_PCM_FORMAT_U32_LE 	Unsigned 32 bit Little Endian
	// SND_PCM_FORMAT_U32_BE 	Unsigned 32 bit Big Endian
	// SND_PCM_FORMAT_FLOAT_LE 	Float 32 bit Little Endian, Range -1.0 to 1.0
	// SND_PCM_FORMAT_FLOAT_BE 	Float 32 bit Big Endian, Range -1.0 to 1.0
	// SND_PCM_FORMAT_FLOAT64_LE 	Float 64 bit Little Endian, Range -1.0 to 1.0
	// SND_PCM_FORMAT_FLOAT64_BE 	Float 64 bit Big Endian, Range -1.0 to 1.0
	// SND_PCM_FORMAT_IEC958_SUBFRAME_LE 	IEC-958 Little Endian
	// SND_PCM_FORMAT_IEC958_SUBFRAME_BE 	IEC-958 Big Endian
	// SND_PCM_FORMAT_MU_LAW 	Mu-Law
	// SND_PCM_FORMAT_A_LAW 	A-Law
	// SND_PCM_FORMAT_IMA_ADPCM 	Ima-ADPCM
	// SND_PCM_FORMAT_MPEG 	MPEG
	// SND_PCM_FORMAT_GSM 	GSM
	// SND_PCM_FORMAT_SPECIAL 	Special
	// SND_PCM_FORMAT_S24_3LE 	Signed 24bit Little Endian in 3bytes format
	// SND_PCM_FORMAT_S24_3BE 	Signed 24bit Big Endian in 3bytes format
	// SND_PCM_FORMAT_U24_3LE 	Unsigned 24bit Little Endian in 3bytes format
	// SND_PCM_FORMAT_U24_3BE 	Unsigned 24bit Big Endian in 3bytes format
	// SND_PCM_FORMAT_S20_3LE 	Signed 20bit Little Endian in 3bytes format
	// SND_PCM_FORMAT_S20_3BE 	Signed 20bit Big Endian in 3bytes format
	// SND_PCM_FORMAT_U20_3LE 	Unsigned 20bit Little Endian in 3bytes format
	// SND_PCM_FORMAT_U20_3BE 	Unsigned 20bit Big Endian in 3bytes format
	// SND_PCM_FORMAT_S18_3LE 	Signed 18bit Little Endian in 3bytes format
	// SND_PCM_FORMAT_S18_3BE 	Signed 18bit Big Endian in 3bytes format
	// SND_PCM_FORMAT_U18_3LE 	Unsigned 18bit Little Endian in 3bytes format
	// SND_PCM_FORMAT_U18_3BE 	Unsigned 18bit Big Endian in 3bytes format
	// Signed 16 bit CPU endian
	SampleFormatS16 = C.SND_PCM_FORMAT_S16
)
View Source
const (
	ModeBlock    = 0
	ModeNonblock = C.SND_PCM_NONBLOCK
	ModeAsync    = C.SND_PCM_ASYNC
)

Open mode constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handle

type Handle struct {

	// Used samples format (size, endianness, signed).
	SampleFormat SampleFormat
	// Sample rate in Hz. Usual 44100.
	SampleRate int
	// Channels in the stream. 2 for stereo.
	Channels int
	// contains filtered or unexported fields
}

Handle represents ALSA stream handler.

func New

func New() *Handle

New returns newly initialized ALSA handler.

func (*Handle) ApplyHwParams

func (handle *Handle) ApplyHwParams() error

ApplyHwParams changes ALSA hardware parameters for the current stream.

func (*Handle) AvailUpdate

func (handle *Handle) AvailUpdate() (freeBytes int, err error)

AvailUpdate returns number of bytes ready to be read/written.

func (*Handle) Close

func (handle *Handle) Close() error

Close closes stream and release the handler.

func (*Handle) FrameSize

func (handle *Handle) FrameSize() int

FrameSize returns size of one frame in bytes.

func (*Handle) Open

func (handle *Handle) Open(device string, streamType StreamType, mode int) error

Open opens a stream.

func (*Handle) Pause

func (handle *Handle) Pause() error

Pause PCM.

func (*Handle) Paused

func (handle *Handle) Paused() bool

Check if we are in the paused state right now.

func (*Handle) Reset

func (handle *Handle) Reset()

func (*Handle) SampleSize

func (handle *Handle) SampleSize() int

SampleSize returns one sample size in bytes.

func (*Handle) Wait

func (handle *Handle) Wait(maxDelay int) (ok bool, err error)

Wait waits till buffer will be free for some new portion of data or delay time is runs out. true ok value means that PCM stream is ready for I/O, false -- timeout occured.

func (*Handle) Write

func (handle *Handle) Write(buf []byte) (wrote int, err error)

Write writes given PCM data. Returns wrote value is total bytes was written.

type SampleFormat

type SampleFormat C.snd_pcm_format_t

Sample type.

type StreamType

type StreamType C.snd_pcm_stream_t

Alsa stream type. Playback or capture.

Jump to

Keyboard shortcuts

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