portaudio

package
v0.0.0-...-33d3053 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2021 License: MIT Imports: 8 Imported by: 0

README

Vendored to apply go1.6 patch

#portaudio

This package provides an interface to the PortAudio audio I/O library. See the package documentation for details.

To build this package you must first have the PortAudio development headers and libraries installed. Some systems provide a package for this; e.g., on Ubuntu you would want to run apt-get install portaudio19-dev. On other systems you might have to install from source.

Thanks to sqweek for motivating and contributing to host API and device enumeration.

Documentation

Overview

For the most part, these bindings parallel the underlying PortAudio API; please refer to http://www.portaudio.com/docs.html for details. Differences introduced by the bindings are documented here:

Instead of passing a flag to OpenStream, audio sample formats are inferred from the signature of the stream callback or, for a blocking stream, from the types of the buffers. See the StreamCallback and Buffer types for details.

Blocking I/O: Read and Write do not accept buffer arguments; instead they use the buffers (or pointers to buffers) provided to OpenStream. The number of samples to read or write is determined by the size of the buffers.

The StreamParameters struct combines parameters for both the input and the output device as well as the sample rate, buffer size, and flags.

Index

Constants

View Source
const FramesPerBufferUnspecified = C.paFramesPerBufferUnspecified

Variables

This section is empty.

Functions

func Initialize

func Initialize() error

func IsFormatSupported

func IsFormatSupported(p StreamParameters, args ...interface{}) error

Returns nil if the format is supported, otherwise an error. The args parameter has the same meaning as in OpenStream.

func Terminate

func Terminate() error

func Version

func Version() int

func VersionText

func VersionText() string

Types

type Buffer

type Buffer interface{}

This type exists for documentation purposes only.

A Buffer is of the form [][]SampleType or []SampleType where SampleType is float32, int32, Int24, int16, int8, or uint8.

In the first form, channels are non-interleaved: len(buf) == numChannels and len(buf[i]) == framesPerBuffer

In the second form, channels are interleaved: len(buf) == numChannels * framesPerBuffer

type DeviceInfo

type DeviceInfo struct {
	Name                     string
	MaxInputChannels         int
	MaxOutputChannels        int
	DefaultLowInputLatency   time.Duration
	DefaultLowOutputLatency  time.Duration
	DefaultHighInputLatency  time.Duration
	DefaultHighOutputLatency time.Duration
	DefaultSampleRate        float64
	HostApi                  *HostApiInfo
	// contains filtered or unexported fields
}

func DefaultInputDevice

func DefaultInputDevice() (*DeviceInfo, error)

func DefaultOutputDevice

func DefaultOutputDevice() (*DeviceInfo, error)

func Devices

func Devices() ([]*DeviceInfo, error)

type Error

type Error C.PaError
const (
	NotInitialized                        Error = C.paNotInitialized
	InvalidChannelCount                   Error = C.paInvalidChannelCount
	InvalidSampleRate                     Error = C.paInvalidSampleRate
	InvalidDevice                         Error = C.paInvalidDevice
	InvalidFlag                           Error = C.paInvalidFlag
	SampleFormatNotSupported              Error = C.paSampleFormatNotSupported
	BadIODeviceCombination                Error = C.paBadIODeviceCombination
	InsufficientMemory                    Error = C.paInsufficientMemory
	BufferTooBig                          Error = C.paBufferTooBig
	BufferTooSmall                        Error = C.paBufferTooSmall
	NullCallback                          Error = C.paNullCallback
	BadStreamPtr                          Error = C.paBadStreamPtr
	TimedOut                              Error = C.paTimedOut
	InternalError                         Error = C.paInternalError
	DeviceUnavailable                     Error = C.paDeviceUnavailable
	IncompatibleHostApiSpecificStreamInfo Error = C.paIncompatibleHostApiSpecificStreamInfo
	StreamIsStopped                       Error = C.paStreamIsStopped
	StreamIsNotStopped                    Error = C.paStreamIsNotStopped
	InputOverflowed                       Error = C.paInputOverflowed
	OutputUnderflowed                     Error = C.paOutputUnderflowed
	HostApiNotFound                       Error = C.paHostApiNotFound
	InvalidHostApi                        Error = C.paInvalidHostApi
	CanNotReadFromACallbackStream         Error = C.paCanNotReadFromACallbackStream
	CanNotWriteToACallbackStream          Error = C.paCanNotWriteToACallbackStream
	CanNotReadFromAnOutputOnlyStream      Error = C.paCanNotReadFromAnOutputOnlyStream
	CanNotWriteToAnInputOnlyStream        Error = C.paCanNotWriteToAnInputOnlyStream
	IncompatibleStreamHostApi             Error = C.paIncompatibleStreamHostApi
	BadBufferPtr                          Error = C.paBadBufferPtr
)

func (Error) Error

func (err Error) Error() string

type HostApiInfo

type HostApiInfo struct {
	Type                HostApiType
	Name                string
	DefaultInputDevice  *DeviceInfo
	DefaultOutputDevice *DeviceInfo
	Devices             []*DeviceInfo
}

func DefaultHostApi

func DefaultHostApi() (*HostApiInfo, error)

func HostApi

func HostApi(apiType HostApiType) (*HostApiInfo, error)

func HostApis

func HostApis() ([]*HostApiInfo, error)

type HostApiType

type HostApiType int

func (HostApiType) String

func (t HostApiType) String() string

type Int24

type Int24 [3]byte

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

func OpenDefaultStream

func OpenDefaultStream(numInputChannels, numOutputChannels int, sampleRate float64, framesPerBuffer int, args ...interface{}) (*Stream, error)

The args parameter has the same meaning as in OpenStream.

func OpenStream

func OpenStream(p StreamParameters, args ...interface{}) (*Stream, error)

For an input- or output-only stream, p.Output.Device or p.Input.Device must be nil, respectively.

The args may consist of either a single StreamCallback or, for a blocking stream, two Buffers or pointers to Buffers. For an input- or output-only stream, one of the Buffer args may be omitted.

func (*Stream) Abort

func (s *Stream) Abort() error

func (*Stream) AvailableToRead

func (s *Stream) AvailableToRead() (int, error)

func (*Stream) AvailableToWrite

func (s *Stream) AvailableToWrite() (int, error)

func (*Stream) Close

func (s *Stream) Close() error

func (*Stream) CpuLoad

func (s *Stream) CpuLoad() float64

func (*Stream) Info

func (s *Stream) Info() *StreamInfo

func (*Stream) Read

func (s *Stream) Read() error

Read uses the buffer provided to OpenStream. The number of samples to read is determined by the size of the buffer.

func (*Stream) Start

func (s *Stream) Start() error

func (*Stream) Stop

func (s *Stream) Stop() error

func (*Stream) Time

func (s *Stream) Time() time.Duration

func (*Stream) Write

func (s *Stream) Write() error

Write uses the buffer provided to OpenStream. The number of samples to write is determined by the size of the buffer.

type StreamCMap

type StreamCMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

StreamCMap tracks the pointers of the Streams between Go and CGO and was required as of the release of Go 1.6 "panic: runtime error: cgo argument has Go pointer to Go pointer"

func (*StreamCMap) Get

func (scm *StreamCMap) Get(id uintptr) *Stream

func (*StreamCMap) Track

func (scm *StreamCMap) Track(s *Stream) uintptr

func (*StreamCMap) Untrack

func (scm *StreamCMap) Untrack(id uintptr)

type StreamCallback

type StreamCallback interface{}

This type exists for documentation purposes only.

A StreamCallback is a func whose signature resembles

func(in Buffer, out Buffer, timeInfo StreamCallbackTimeInfo, flags StreamCallbackFlags)

where the final one or two parameters may be omitted. For an input- or output-only stream, one of the Buffer parameters may also be omitted. The two Buffer types may be different.

type StreamCallbackTimeInfo

type StreamCallbackTimeInfo struct {
	InputBufferAdcTime, CurrentTime, OutputBufferDacTime time.Duration
}

type StreamDeviceParameters

type StreamDeviceParameters struct {
	Device   *DeviceInfo
	Channels int
	Latency  time.Duration
}

StreamDeviceParameters specifies parameters for one device (either input or output) in a stream. A nil Device indicates that no device is to be used -- i.e., for an input- or output-only stream.

type StreamFlags

type StreamFlags C.PaStreamFlags
const (
	NoFlag                                StreamFlags = C.paNoFlag
	ClipOff                               StreamFlags = C.paClipOff
	DitherOff                             StreamFlags = C.paDitherOff
	NeverDropInput                        StreamFlags = C.paNeverDropInput
	PrimeOutputBuffersUsingStreamCallback StreamFlags = C.paPrimeOutputBuffersUsingStreamCallback
	PlatformSpecificFlags                 StreamFlags = C.paPlatformSpecificFlags
)

type StreamInfo

type StreamInfo struct {
	InputLatency, OutputLatency time.Duration
	SampleRate                  float64
}

type StreamParameters

type StreamParameters struct {
	Input, Output   StreamDeviceParameters
	SampleRate      float64
	FramesPerBuffer int
	Flags           StreamFlags
}

StreamParameters includes all parameters required to open a stream except for the callback or buffers.

func HighLatencyParameters

func HighLatencyParameters(in, out *DeviceInfo) (p StreamParameters)

High latency parameters are mono in, stereo out (if supported), high latency, the smaller of the default sample rates of the two devices, andFramesPerBufferUnspecified. One of the devices may be nil.

func LowLatencyParameters

func LowLatencyParameters(in, out *DeviceInfo) (p StreamParameters)

Low latency parameters are mono in, stereo out (if supported), low latency, the larger of the default sample rates of the two devices, and FramesPerBufferUnspecified. One of the devices may be nil.

type UnanticipatedHostError

type UnanticipatedHostError struct {
	HostApiType HostApiType
	Code        int
	Text        string
}

func (UnanticipatedHostError) Error

func (err UnanticipatedHostError) Error() string

Jump to

Keyboard shortcuts

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