audio

package
Version: v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: Apache-2.0 Imports: 16 Imported by: 9

Documentation

Overview

Package audio provides audio types, font types for filtering audio reactively, and channels to allow constant audio play signals to be restricted to play at variable frequencies.

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefFont is the font used for default functions. It can be publicly
	// modified to apply a default font to generated audios through def
	// methods. If it is not modified, it is a font of zero filters.
	DefFont = font.New()
)

Functions

func BatchLoad

func BatchLoad(baseFolder string) error

BatchLoad attempts to load all files within a given directory depending on their file ending (currently supporting .wav and .mp3)

func DefActiveChannel

func DefActiveChannel(freq intrange.Range, fileNames ...string) (chan ChannelSignal, error)

DefActiveChannel acts like GetActiveChannel when fed DefFont

func DefChannel

func DefChannel(freq intrange.Range, fileNames ...string) (chan ChannelSignal, error)

DefChannel acts like GetChannel when given DefFont

func DefPlay

func DefPlay(filename string) error

DefPlay acts like play when given DefFont

func GetActiveChannel

func GetActiveChannel(f *font.Font, freq intrange.Range, fileNames ...string) (chan ChannelSignal, error)

GetActiveChannel returns a channel that will block until its frequency rotates around. This means that continually sending on ChannelSignal will probably cause the game to freeze or substantially slow down. For this reason ActiveWavChannels are meant to be used for cases where the user knows they will not be sending on the ActiveWavChannel more often than the frequency they send in. Audio channels serve one purpose: handling audio effects which come in at very high or unpredictable frequencies while limiting the number of concurrent ongoing audio effects from any one source. All channels will only play once per a given frequency range.

func GetChannel

func GetChannel(f *font.Font, freq intrange.Range, fileNames ...string) (chan ChannelSignal, error)

GetChannel channels will attempt to steal most sends sent to the output audio channel. This will allow a game to constantly send on a channel and obtain an output rate of near the sent in frequency instead of locking or requiring buffered channel usage.

An important example case-- walking around When a character walks, they have some frequency step speed and some set of potential fileName sounds that play, and the usage of a channel here will let the EnterFrame code which detects the walking status to send on the walking audio channel constantly without worrying about triggering too many sounds.

func IsLoaded

func IsLoaded(filename string) bool

IsLoaded is shorthand for (if _, ok := loaded[filename]; ok)

func Play

func Play(f *font.Font, filename string) error

Play is shorthand for Get followed by Play.

func Unload

func Unload(filename string)

Unload removes an element from the loaded map. If the element does not exist, it does nothing.

Types

type Audio

type Audio struct {
	*font.Audio

	X, Y *float64
	// contains filtered or unexported fields
}

Audio is a struct of some audio data and the variables required to filter it through a sound font.

func New

func New(f *font.Font, d Data, coords ...*float64) *Audio

New returns an audio from a font, some audio data, and optional positional coordinates

func (*Audio) Copy

func (a *Audio) Copy() (audio.Audio, error)

Copy returns a copy of the audio

func (*Audio) Filter

func (a *Audio) Filter(fs ...audio.Filter) (audio.Audio, error)

Filter returns the audio with some set of filters applied to it.

func (*Audio) MustCopy

func (a *Audio) MustCopy() audio.Audio

MustCopy acts like Copy, but panics on an error.

func (*Audio) MustFilter

func (a *Audio) MustFilter(fs ...audio.Filter) audio.Audio

MustFilter acts like Filter but ignores errors.

func (*Audio) Play

func (a *Audio) Play() <-chan error

Play begin's an audio's playback

func (*Audio) Stop

func (a *Audio) Stop() error

Stop stops an audio's playback

func (*Audio) Xp

func (a *Audio) Xp() *float64

Xp returns a pointer to the x position of this audio, if it has one. It has no position, this returns nil.

func (*Audio) Yp

func (a *Audio) Yp() *float64

Yp returns a pointer to the y position of this audio, if it has one. It has no position, this returns nil. If This is not nil, Xp will not be nil.

type ChannelManager added in v1.4.0

type ChannelManager struct {
	Font *font.Font
	// contains filtered or unexported fields
}

A ChannelManager can create audio channels that won't be stopped at scene end, but can be stopped at any time by calling Close on the manager.

func NewChannelManager added in v1.4.0

func NewChannelManager(f *font.Font) *ChannelManager

NewChannelManager creates a channel manager whose Def functions will use the given font.

func (*ChannelManager) Close added in v1.4.0

func (cm *ChannelManager) Close()

Close closes the manager's internal channel handling audio channels. This will prevent further audio from being played via any of those channels, and their spawned routines will return. As Close does close a channel, it should not be called multiple times.

func (*ChannelManager) DefActiveChannel added in v1.4.0

func (cm *ChannelManager) DefActiveChannel(freq intrange.Range, fileNames ...string) (chan ChannelSignal, error)

DefActiveChannel creates an active channel using the manager's font.

func (*ChannelManager) DefChannel added in v1.4.0

func (cm *ChannelManager) DefChannel(freq intrange.Range, fileNames ...string) (chan ChannelSignal, error)

DefChannel creates an audio channel using the manager's Font.

func (*ChannelManager) GetActiveChannel added in v1.4.0

func (cm *ChannelManager) GetActiveChannel(f *font.Font, freq intrange.Range, fileNames ...string) (chan ChannelSignal, error)

GetActiveChannel creates an active channel using the given font.

func (*ChannelManager) GetChannel added in v1.4.0

func (cm *ChannelManager) GetChannel(f *font.Font, freq intrange.Range, fileNames ...string) (chan ChannelSignal, error)

GetChannel creates a channel using the given font.

type ChannelSignal

type ChannelSignal interface {
	GetIndex() int
	GetPos() (bool, float64, float64)
}

A ChannelSignal is sent to an AudioChannel to indicate when they should attempt to play an audio sound

type Data

type Data audio.FullAudio

Data is an alias for an interface supporting the built in filters in our external audio playing library

func Get

func Get(filename string) (Data, error)

Get without a font will just return the raw audio data

func GetSounds

func GetSounds(fileNames ...string) ([]Data, error)

GetSounds returns a set of Data for a set of input filenames

func Load

func Load(directory, filename string) (Data, error)

Load joins the directory and filename, attempts to find the input file, and stores it as filename in the set of loaded files. This can cause a conflict when multiple files have the same name but different directories-- the first file loaded wil be the one stored in the loeaded map.

type Ears

type Ears struct {
	X             *float64
	Y             *float64
	PanWidth      float64
	SilenceRadius float64
	// VolumeScale and PanScale are currently ignored because there is only
	// one scale type
	VolumeScale ScaleType
	PanScale    ScaleType
}

Ears are assisting variables and some position in the game world where audio should be 'heard' from, like the player character. Passing in that position's x and y as pointers then will allow for sounds further away from that point to be quieter and sounds to the left / right of that point to be panned left and right.

func NewEars

func NewEars(x, y *float64, panWidth float64, silentRadius float64) *Ears

NewEars returns a new set of ears to hear pan/volume modified audio from

func (*Ears) CalculatePan

func (e *Ears) CalculatePan(x2 float64) float64

CalculatePan converts PanWidth and two x positions into a left / right pan value.

func (*Ears) CalculateVolume

func (e *Ears) CalculateVolume(v physics.Vector) float64

CalculateVolume converts two vector positions and SilenceRadius into a volume scale

type FontManager

type FontManager map[string]*font.Font

A FontManager is a map of names to Fonts that has a built in default font at name 'def'.

func NewFontManager

func NewFontManager() *FontManager

NewFontManager returns a manager with a single 'def' font

func (*FontManager) Get

func (fm *FontManager) Get(name string) *font.Font

Get returns whatever is at name in font

func (*FontManager) NewFont

func (fm *FontManager) NewFont(name string, f *font.Font) error

NewFont adds a font to a manger with the given keyed name. NewFont can return an error indicating if the name assigned was already in use.

type Pos

type Pos func(SupportsPos)

Pos functions are filters that require a SupportsPos interface

func PosFilter

func PosFilter(e *Ears) Pos

PosFilter is the only Pos generating function right now. It takes in ears to listen from and changes incoming audio to be quiter and panned based on positional relation to those ears.

func (Pos) Apply

func (xp Pos) Apply(a audio.Audio) (audio.Audio, error)

Apply is a function allowing Pos to satisfy the audio.Filter interface. Pos applies itself to any audio it is given that supports it.

type PosSignal

type PosSignal struct {
	Signal
	X, Y float64
}

PosSignal is a ChannelSignal compatible with Ears

func NewPosSignal

func NewPosSignal(index int, x, y float64) PosSignal

NewPosSignal constructs a PosSignal

func (PosSignal) GetPos

func (ps PosSignal) GetPos() (bool, float64, float64)

GetPos returns the floating points passed into a PosSignal as the origin of a sound to be heard

type ScaleType

type ScaleType int

ScaleType should be moved to a different package that handles global scale varieties

const (
	// LINEAR is the only ScaleType right now.
	LINEAR ScaleType = iota
)

type Signal

type Signal struct {
	Index int
}

Signal is a default ChannelSignal that just indicates what audio from a set of audio data should be played by int index

func (Signal) GetIndex

func (s Signal) GetIndex() int

GetIndex returns Signal.Index

func (Signal) GetPos

func (s Signal) GetPos() (bool, float64, float64)

GetPos returns that a Signal is not positional

type SupportsPos

type SupportsPos interface {
	supports.Encoding
	Xp() *float64
	Yp() *float64
}

SupportsPos is a type used by filters to check that the audio they are given has a position.

Jump to

Keyboard shortcuts

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