track

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: Zlib Imports: 4 Imported by: 0

README

track

Go Reference

Package track provides a github.com/faiface/beep Streamer with continuous playback and real-time stream insertion.

A Track defaults to an active streamer, filling in gaps with a silence streamer. Goroutines can set new active streamers concurrently with calls to Stream.

Documentation

Overview

Package track provides a beep.Streamer with real-time stream insertion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SilenceError added in v1.1.0

type SilenceError struct {

	// Silence is the track's silence streamer.
	Silence beep.Streamer
	// contains filtered or unexported fields
}

SilenceError is the error returned by Track.Err if the track's silence streamer fails to provide enough samples. It wraps the silence streamer's error if there is one.

func (*SilenceError) Error added in v1.1.0

func (err *SilenceError) Error() string

func (*SilenceError) Unwrap added in v1.3.0

func (err *SilenceError) Unwrap() error

Unwrap returns the wrapped error which was returned by the track's silence streamer after it closed.

type Track

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

Track is a beep.StreamCloser which synchronously switches between a default streamer and a settable active streamer to provide a constantly playing stream.

The zero value of Track defaults to beep.Silence as its silence streamer.

func New

func New(silence, start beep.Streamer) *Track

New creates a track defaulting to silence and beginning with start as its active streamer. If silence is nil, a default silent stream is used. If start is nil, streaming begins with silence. silence must always fill any number of samples.

func (*Track) Close

func (t *Track) Close() error

Close stops streamer playback. If there is an active streamer and it implements beep.StreamCloser, this additionally closes it. It is safe to call this concurrently with Stream, but the caller must ensure that there is no concurrent call to Set.

func (*Track) Err

func (t *Track) Err() error

Err returns an error if the silence streamer failed to provide enough samples. The returned error is of type *SilenceError, and it wraps the silence streamer's error, if any. It does not propagate errors from any active streamers.

func (*Track) Interrupt added in v1.2.0

func (t *Track) Interrupt() error

Interrupt stops the currently playing active streamer, if any. If the active streamer implements beep.StreamCloser, this additionally closes it. It is safe to call this concurrently with Stream and Set. The returned error is the error from closing the active streamer, if any.

func (*Track) Set

func (t *Track) Set(stream beep.Streamer)

Set sets the track's playing streamer. If the track is currently playing another streamer, this blocks until that streamer has finished. Panics if t is closed.

If stream is nil, Set performs all its normal blocking, but does not actually set a streamer. This allows callers to join on the completion of the current active streamer.

It is safe for any number of goroutines to call Set and for there to be at most one goroutine calling Stream concurrently.

func (*Track) Stream

func (t *Track) Stream(samples [][2]float64) (int, bool)

Stream returns samples from the track's active streamer, or from its default silence track if there is no active streamer. If all samples are streamed from the active streamer and the active streamer is a beep.StreamCloser, this additionally closes it. Panics if the silence streamer fails to stream all required samples.

It is not safe for multiple goroutines to call Stream concurrently, but any number of goroutines may call Set.

Jump to

Keyboard shortcuts

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