audio

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: Apache-2.0 Imports: 7 Imported by: 16

Documentation

Overview

Package audio provides audio playing and encoding support

Index

Constants

This section is empty.

Variables

View Source
var SkipDevicesContaining = "HDMI"

SkipDevicesContaining is a environment variable controlled value which will cause audio devices containing the given string to be skipped when finding an audio device to play audio through. Currently only supported on linux. Todo: find a more elegant fix for bad audio devices being chosen

Functions

This section is empty.

Types

type Audio

type Audio interface {
	// Play returns a channel that will signal when it finishes playing.
	// Looping audio will never send on this channel!
	// The value sent will always be true.
	Play() <-chan error
	// Filter will return an audio with some desired filters applied
	Filter(...Filter) (Audio, error)
	MustFilter(...Filter) Audio
	// Stop will stop an ongoing audio
	Stop() error

	// Implementing struct-- encoding
	Copy() (Audio, error)
	MustCopy() Audio
	PlayLength() time.Duration
}

Audio represents playable, filterable audio data.

func EncodeBytes

func EncodeBytes(enc Encoding) (Audio, error)

type CanLoop

type CanLoop struct {
	Loop bool
}

CanLoop offers composable looping

func (*CanLoop) GetLoop

func (cl *CanLoop) GetLoop() *bool

GetLoop allows CanLoop to satisfy the SupportsLoop interface

type Encoding

type Encoding struct {
	// Consider: non []byte data?
	// Consider: should Data be a type just like Format and CanLoop?
	Data []byte
	Format
	CanLoop
}

Encoding contains all information required to convert raw data (currently assumed PCM data but that may/will change) into playable Audio

func (*Encoding) Copy

func (enc *Encoding) Copy() (Audio, error)

Copy returns an audio encoded from this encoding. Consider: Copy might be tied to HasEncoding

func (*Encoding) GetData

func (enc *Encoding) GetData() *[]byte

GetData satisfies filter.SupportsData

func (*Encoding) MustCopy

func (enc *Encoding) MustCopy() Audio

MustCopy acts like Copy, but will panic if err != nil

func (*Encoding) PlayLength

func (enc *Encoding) PlayLength() time.Duration

PlayLength returns how long this encoding will play its data for

type Filter

type Filter interface {
	Apply(Audio) (Audio, error)
}

A Filter takes an input audio and returns some new Audio from them. This usage implies that Audios can be copied, and that Audios have available information to be generically modified by a Filter. The functions for these capabilities are yet fleshed out. It's worth considering whether a Filter modifies in place. The answer is probably yes: a.Filter(fs) would modify a in place a.Copy().Filter(fs) would return a new audio Specific audio implementations could not follow this, however.

type Format

type Format struct {
	SampleRate uint32
	Channels   uint16
	Bits       uint16
}

Format stores the variables which are presumably constant for any given type of audio (wav / mp3 / flac ...)

func (*Format) GetBitDepth

func (f *Format) GetBitDepth() *uint16

GetBitDepth satisfied supports.BitDepth

func (*Format) GetChannels

func (f *Format) GetChannels() *uint16

GetChannels satisfies supports.Channels

func (*Format) GetSampleRate

func (f *Format) GetSampleRate() *uint32

GetSampleRate satisfies supports.SampleRate

func (*Format) Wave

func (f *Format) Wave(b []byte) (Audio, error)

Wave takes in raw bytes and encodes them according to this format

type FullAudio

type FullAudio interface {
	Audio
	supports.Encoding
	supports.Loop
}

FullAudio supports all the built in filters

type Multi

type Multi struct {
	Audios []Audio
}

A Multi lets lists of audios be used simultaneously

func NewMulti

func NewMulti(as ...Audio) *Multi

NewMulti returns a new multi

func (*Multi) Copy

func (m *Multi) Copy() (Audio, error)

Copy returns a copy of this Multi

func (*Multi) Filter

func (m *Multi) Filter(fs ...Filter) (Audio, error)

Filter applies all the given filters on everything in the Multi

func (*Multi) MustCopy

func (m *Multi) MustCopy() Audio

MustCopy acts like Copy but panics if error != nil

func (*Multi) MustFilter

func (m *Multi) MustFilter(fs ...Filter) Audio

MustFilter acts like filter but ignores errors.

func (*Multi) Play

func (m *Multi) Play() <-chan error

Play plays all audios in the Multi ASAP

func (*Multi) PlayLength

func (m *Multi) PlayLength() time.Duration

PlayLength returns how long this audio will play for

func (*Multi) Stop

func (m *Multi) Stop() error

Stop stops all audios in the Multi. Any that fail will report an error.

Directories

Path Synopsis
Package filter provides various audio filters to be applied to audios through the Filter() function
Package filter provides various audio filters to be applied to audios through the Filter() function
supports
Package supports holds interface types for filter supports
Package supports holds interface types for filter supports

Jump to

Keyboard shortcuts

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