pulseaudio

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: MIT Imports: 3 Imported by: 1

README

hz.tools/pulseaudio

The pulseaudio package contains a cgo wrapper to allow playing to pulseaudio.

Go Reference Go Report Card

Documentation

Overview

Package pulseaudio allows clients to read audio from, or send audio to a pulseaudio server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Format denoes the Audio format type. Currently only "NE" or
	// "Native Endian" is supported, since we're providing a way to write
	// things like `[]float` into the audio stream, and it's unlikely this
	// will be used to play back flat files on the system without processing
	// them.
	Format SampleFormat

	// Rate is the numbers of samples per second.
	Rate uint

	// Channels is the number of channels in the audio stream.
	Channels uint

	// AppName is the name of the Application doing the streaming.
	AppName string

	// StreamName is the name of the audio stream from the Application.
	StreamName string

	// SinkName is the name of the PulseAudio sink to write to.
	SinkName string
}

Config will allow you to set the parameters that pulseaudio will be initialized with at creation time.

type Reader

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

Reader is a handle to the underlying pulseaudio stream to allow for reading from the microphone on the system.

func NewReader

func NewReader(cfg Config) (*Reader, error)

NewReader will create a new Reader with the provided configuration.

func (Reader) Close

func (r Reader) Close()

Close will free the underlying handle.

func (Reader) Flush

func (r Reader) Flush() error

Flush will empty the buffer held by pulseaudio.

func (Reader) Read

func (r Reader) Read(in interface{}) error

Read will read the audio samples into the provided object.

func (Reader) UnsafeRead

func (r Reader) UnsafeRead(ptr unsafe.Pointer, size int) error

UnsafeRead will perform a very unsafe read into the target location in memory. Please avoid using this.

type SampleFormat

type SampleFormat int

SampleFormat denotes the audio format to be used by the pulse streamer.

var (
	// SampleFormatFloat32NE is used when the provided data is comprised of
	// 32 bit floating point numbers in the native endian format. This means
	// the data can be passed to `Write` as either []float32 or [][2]float32,
	// depending on the channels provided.
	SampleFormatFloat32NE SampleFormat = C.PA_SAMPLE_FLOAT32NE
)

type Writer

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

Writer is an encapsulation of the underlying pulseaudio stream, allowing for an idiomatic Go library interface to that stream.

func NewWriter

func NewWriter(cfg Config) (*Writer, error)

NewWriter creates a new pulseaudio.Writer object, allowing audio to be written into Pulse.

func (Writer) Close

func (w Writer) Close()

Close will close the stream, and perform all cleanup required.

func (Writer) Write

func (w Writer) Write(samples interface{}) error

Write will write the provided data to the pulseaudio stream. This function accepts any type, but will return an error if th type is not something that this library understands, the number of channels and the stream format.

Currently accepted types:

  • []float32 (Format: SampleFormatFloat32NE, Channels: 1)
  • [][2]float32 (Format: SampleFormatFloat32NE, Channels: 2)

Directories

Path Synopsis
cmd
pa-raw command

Jump to

Keyboard shortcuts

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