alsa

package module
v0.0.0-...-85bb7ee Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: MIT Imports: 12 Imported by: 27

README

Synopsis

This is a golang ALSA client implementation, without cgo! Unfortunately, doing it without cgo means throwing away many years of compatibility work that has been put into libalsa. So be warned, this library is not likely to work with a lot of the more colorful audio cards out there, and is not likely to work on platforms other than x86_64. (Though, someone has nicely done some work on ARM. Thanks!)

But fear not! Go is fun, and I tried to keep the library on the simple side, so adding in support for what your audio card needs might actually be just a nice afternoon of programming. The hardest part for me was just trying to understand all of the alsa terminology.

For a simple example of synthesized playback, the beep command will produce a sine wave for a few seconds on each detected ALSA output:

go get github.com/yobert/alsa/cmd/beep
$GOPATH/beep

And for recording from a microphone into a WAV file:

go get github.com/yobert/alsa/cmd/record
$GOPATH/record

This example does recording and playback, but it's got a really buggy ring buffer going on:

go get github.com/yobert/alsa/cmd/echoback
$GOPATH/echoback

Disclaimer

This module makes syscalls with pointers to memory buffers that are in garbage collectable memory. I have a feeling this isn't safe, but it hasn't crashed on me yet.

Contributors

Thanks so much for the help! Thanks! See AUTHORS for a list. Pull requests welcome from anybody, regardless of skill level.

See Also

You may be interested in https://github.com/jfreymuth/pulse which is a lot less likely to crash and will probably work with your sound card.

Documentation

Index

Constants

View Source
const (
	StandardSubformat  SubformatType = iota
	SubformatTypeFirst               = StandardSubformat
	SubformatTypeLast                = StandardSubformat
)

Variables

This section is empty.

Functions

func CloseCards

func CloseCards(cards []*Card)

Types

type AccessType

type AccessType int
const (
	MmapInterleaved AccessType = iota
	MmapNonInterleaved
	MmapComplex
	RWInterleaved
	RWNonInterleaved
	AccessTypeLast  = RWNonInterleaved
	AccessTypeFirst = MmapInterleaved
)

func (AccessType) String

func (a AccessType) String() string

type Buffer

type Buffer struct {
	Format BufferFormat
	Data   []byte
}

type BufferFormat

type BufferFormat struct {
	SampleFormat FormatType
	Rate         int
	Channels     int
}

func (BufferFormat) String

func (bp BufferFormat) String() string

type Card

type Card struct {
	Path   string
	Title  string
	Number int
	// contains filtered or unexported fields
}

func OpenCards

func OpenCards() ([]*Card, error)

func (*Card) Devices

func (card *Card) Devices() ([]*Device, error)

func (Card) String

func (card Card) String() string

type Device

type Device struct {
	Type         DeviceType
	Number       int
	Play, Record bool

	Path  string
	Title string
	// contains filtered or unexported fields
}

func (*Device) BufferFormat

func (device *Device) BufferFormat() BufferFormat

BufferFormat() is not valid until after Prepare() is called

func (*Device) BytesPerFrame

func (device *Device) BytesPerFrame() int

func (*Device) Close

func (device *Device) Close()

func (*Device) Debug

func (device *Device) Debug(v bool)

func (*Device) NegotiateBufferSize

func (device *Device) NegotiateBufferSize(buffer_sizes ...int) (int, error)

func (*Device) NegotiateChannels

func (device *Device) NegotiateChannels(channels ...int) (int, error)

func (*Device) NegotiateFormat

func (device *Device) NegotiateFormat(formats ...FormatType) (FormatType, error)

func (*Device) NegotiatePeriodSize

func (device *Device) NegotiatePeriodSize(period_sizes ...int) (int, error)

func (*Device) NegotiateRate

func (device *Device) NegotiateRate(rates ...int) (int, error)

func (*Device) NewBufferDuration

func (device *Device) NewBufferDuration(d time.Duration) Buffer

func (*Device) NewBufferSeconds

func (device *Device) NewBufferSeconds(seconds int) Buffer

This function is deprecated and will be removed at some point. Please use NewBufferDuration

func (*Device) Open

func (device *Device) Open() error

func (*Device) Prepare

func (device *Device) Prepare() error

func (*Device) Read

func (device *Device) Read(buf []byte) error

func (Device) String

func (device Device) String() string

func (*Device) Write

func (device *Device) Write(buf []byte, frames int) error

type DeviceType

type DeviceType int
const (
	UnknownDeviceType DeviceType = iota
	PCM
)

func (DeviceType) String

func (t DeviceType) String() string

type Flags

type Flags uint32
const (
	OpenMin Flags = 1 << iota
	OpenMax
	Integer
	Empty
)

func (Flags) String

func (f Flags) String() string

type FormatType

type FormatType int
const (
	S8 FormatType = iota
	U8
	S16_LE
	S16_BE
	U16_LE
	U16_BE
	S24_LE
	S24_BE
	U24_LE
	U24_BE
	S32_LE
	S32_BE
	U32_LE
	U32_BE
	FLOAT_LE
	FLOAT_BE
	FLOAT64_LE
	FLOAT64_BE
	// There are so many more...
	FormatTypeLast  = FLOAT64_BE
	FormatTypeFirst = S8
)
const (
	Unknown FormatType = -1
)

func (FormatType) String

func (f FormatType) String() string

type SubformatType

type SubformatType int

func (SubformatType) String

func (f SubformatType) String() string

Directories

Path Synopsis
cmd
record
record some audio and save it as a WAV file
record some audio and save it as a WAV file
Package color is a very basic ANSI escape sequence colorer.
Package color is a very basic ANSI escape sequence colorer.
pcm

Jump to

Keyboard shortcuts

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