scWriter

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Options)

Option is the type for a function option

func Channels

func Channels(chs int) Option

Channels is a functional option to set the amount of channels to be used with the audio device. Typically this is either Mono (1) or Stereo (2). Make sure that your audio device supports the specified amount of channels.

func DeviceName

func DeviceName(name string) Option

DeviceName is a functional option to specify the name of the Audio device

func FramesPerBuffer

func FramesPerBuffer(s int) Option

FramesPerBuffer is a functional option which sets the amount of sample frames our audio device will request / provide when executing the callback. Example: A buffer with 960 frames at 48000kHz / stereo contains 1920 samples and results in 20ms Audio.

func HostAPI

func HostAPI(hostAPI string) Option

HostAPI is a functional option to enforce the usage of a particular audio host API

func Latency

func Latency(t time.Duration) Option

Latency is a functional option to set the latency of the audio device.

func RingBufferSize

func RingBufferSize(size int) Option

RingBufferSize is a functional option to set the size of the ring buffer of Output audio devices. When enqueing samples, they are stored in the ring buffer from where the callback will retrieve them for playing them on the speaker.

func Samplerate

func Samplerate(s float64) Option

Samplerate is a functional option to set the sampling rate of the audio device. Make sure your audio device supports the specified sampling rate.

type Options

type Options struct {
	HostAPI         string
	DeviceName      string
	Channels        int
	Samplerate      float64
	FramesPerBuffer int
	Latency         time.Duration
	RingBufferSize  int
}

Options contains the parameters for initializing a sound card writer.

type ScWriter

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

ScWriter implements the audio.Sink interface and is used to write (play) audio on a local audio output device (e.g. speakers).

func NewScWriter

func NewScWriter(opts ...Option) (*ScWriter, error)

NewScWriter returns a new soundcard writer for a specific audio output device. This is typically a speaker or a pair of headphones.

func (*ScWriter) Close

func (p *ScWriter) Close() error

Close shutsdown properly the soundcard audio device.

func (*ScWriter) Flush

func (p *ScWriter) Flush()

Flush clears all internal buffers

func (*ScWriter) SetVolume

func (p *ScWriter) SetVolume(v float32)

SetVolume sets the volume for all upcoming audio frames.

func (*ScWriter) Start

func (p *ScWriter) Start() error

Start starts streaming audio to the Soundcard output device (e.g. Speaker).

func (*ScWriter) Stop

func (p *ScWriter) Stop() error

Stop stops streaming audio.

func (*ScWriter) Volume

func (p *ScWriter) Volume() float32

Volume returns the current volume.

func (*ScWriter) Write

func (p *ScWriter) Write(msg audio.Msg) error

Write converts the frames in the audio buffer into the right format and queues them into a ring buffer for playing on the speaker.

Jump to

Keyboard shortcuts

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