portaudioutil

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChannelMismatch = errors.New("audio data does not match the stream's channel count")

Error for audio data that does not match the channel count of its stream

View Source
var ErrClosed = errors.New("portaudio stream is closed")

Error for any call on a stream once Close has begun, a second Close included

View Source
var ErrNoPlayback = errors.New("no portaudio playback started")

Error for Playback asked before any Play

View Source
var ErrUnsupported = fmt.Errorf("load portaudio: %w", dlutil.ErrUnsupported)

Error for a build that has no dynamic library loader for its platform and so cannot load PortAudio

Functions

func Load

func Load() error

Loads and binds the PortAudio library without initializing its host APIs, the check for whether PortAudio is installed

Types

type Audio

type Audio interface {
	Devices() ([]Device, error)
	Device(selector any, dir Direction) (Device, error)
	HostAPI(index int) (HostAPI, error)
	Play(data []int16, sampleRate float64, blockSize int) error
	Stop()
	Playback() (Stream, error)
	OpenInput(p StreamParams, callback InputCallback) (InputStream, error)
	OpenOutput(p StreamParams) (OutputStream, error)
}

PortAudio loaded and initialized: device and host API queries, streams, and one playback of a buffer at a time

func Open

func Open() (Audio, error)

PortAudio loaded and initialized once per process, what it and the host libraries print while probing devices routed into the debug log

type CallbackFlags

type CallbackFlags uint32

Status bits PortAudio passes a stream callback

func (CallbackFlags) String

func (f CallbackFlags) String() string

Names of the set flags joined by commas, empty when none is set

type CallbackResult

type CallbackResult int32

What a stream callback asks of its stream

const (
	// Keep the stream running
	Continue CallbackResult = 0
	// Finish once the blocks already handed over have played
	Complete CallbackResult = 1
	// Stop at once, dropping what is still queued
	Abort CallbackResult = 2
)

type Device

type Device struct {
	Name                     string
	Index                    int
	HostAPI                  int
	MaxInputChannels         int
	MaxOutputChannels        int
	DefaultLowInputLatency   time.Duration
	DefaultLowOutputLatency  time.Duration
	DefaultHighInputLatency  time.Duration
	DefaultHighOutputLatency time.Duration
	DefaultSampleRate        float64
}

One audio device as PortAudio reports it, the latencies being the defaults PortAudio suggests for it

type DeviceError

type DeviceError struct {
	Selector  any
	Direction Direction
	Matches   []string
}

Device selector that names no device with channels in a direction, or a name query that matches several

func (*DeviceError) Error

func (e *DeviceError) Error() string

Which selector failed and, for an ambiguous query, the "[index] name, host API" line of each match

type Direction

type Direction uint8

Way audio flows through a device or a stream

const (
	// Audio captured from a device
	Input Direction = iota + 1
	// Audio played to a device
	Output
)

func (Direction) String

func (d Direction) String() string

"input" or "output"

type Error

type Error struct {
	Op       string
	Code     int
	Text     string
	HostAPI  string
	HostCode int
	HostText string
}

Failed PortAudio call: the operation, PortAudio's error code and text, and the host API's own error when PortAudio reports one

func (*Error) Error

func (e *Error) Error() string

Operation, PortAudio's text and code, then the host API's error

type HostAPI

type HostAPI struct {
	Name                string
	Devices             []int
	DefaultInputDevice  int
	DefaultOutputDevice int
}

One host API such as ALSA, Core Audio or WASAPI, with the indexes of its devices and of its default devices, -1 for none

type InputCallback

type InputCallback func(indata []int16, frames int, status CallbackFlags) CallbackResult

Callback that receives each captured block of interleaved int16 samples with its frame count and the status flags, the slice being the callback's own to keep

type InputStream

type InputStream interface {
	Stream
	Read(frames int) ([]int16, bool, error)
	ReadAvailable() (int, error)
}

Stream that captures interleaved int16 frames through its callback or through blocking reads

type LibraryError

type LibraryError struct{ Err error }

PortAudio library that could not be found, opened or bound

func (*LibraryError) Error

func (e *LibraryError) Error() string

What kept the library from loading

func (*LibraryError) Unwrap

func (e *LibraryError) Unwrap() error

The loader's or binder's own error

type OutputStream

type OutputStream interface {
	Stream
	Write(data []int16) (bool, error)
}

Stream that plays interleaved int16 frames through blocking writes

type Stream

type Stream interface {
	Active() (bool, error)
	Start() error
	Stop() error
	Abort() error
	Close() error
}

Surface every stream shares

type StreamParams

type StreamParams struct {
	Device     any
	SampleRate float64
	BlockSize  int
	Channels   int
}

Settings of a stream to open: Device as Audio.Device takes it, and a zero SampleRate or Channels taking the device's own, a zero BlockSize letting PortAudio choose

Jump to

Keyboard shortcuts

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