audio

package
v3.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package audio provides audio playing utilities.

Index

Constants

This section is empty.

Variables

View Source
var DefaultCache = NewCache()

DefaultCache is the receiver for package level loading operations.

View Source
var DefaultFont = font.New()

DefaultFont 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.

Functions

func BatchLoad

func BatchLoad(baseFolder string) error

BatchLoad attempts to load all files within a given directory depending on their file ending

func BlankBatchLoad

func BlankBatchLoad(baseFolder string) error

BlankBatchLoad acts like BatchLoad, but replaces all loaded assets with empty audio constructs. This is intended to reduce start-up times in development.

func DefaultPlay

func DefaultPlay(filename string) error

DefaultPlay is shorthand for Play(DefaultFont, filename)

func Play

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

Play is shorthand for Get followed by Play on the DefaultCache.

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() (klang.Audio, error)

Copy returns a copy of the audio

func (*Audio) Filter

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

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

func (*Audio) MustCopy

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

MustCopy acts like Copy, but panics on an error.

func (*Audio) MustFilter

func (a *Audio) MustFilter(fs ...klang.Filter) klang.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) SetVolume

func (a *Audio) SetVolume(v int32) error

SetVolume attempts to set the volume of the underlying OS audio.

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 Cache

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

Cache is a simple audio data cache

func NewCache

func NewCache() *Cache

NewCache returns an empty Cache

func (*Cache) Clear

func (c *Cache) Clear(key string)

Clear will remove elements matching the given key from the Cache.

func (*Cache) ClearAll

func (c *Cache) ClearAll()

ClearAll will remove all elements from a Cache

func (*Cache) Get

func (c *Cache) Get(file string) (Data, error)

Get will read cached audio data from Load, or error if the given file is not in the cache.

func (*Cache) Load

func (c *Cache) Load(file string) (Data, error)

Load loads the given file and caches it by two keys: the full file name given and the final element of the file's path. If the file cannot be found or if its extension is not supported an error will be returned.

type Data

type Data audio.FullAudio

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

func Get

func Get(file string) (Data, error)

Get calls Get on the Default Cache.

func Load

func Load(file string) (Data, error)

Load calls Load on the Default Cache.

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 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 klang.Audio) (klang.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 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 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.

Directories

Path Synopsis
Package flac provides functionality to handle .flac files and .flac encoded data.
Package flac provides functionality to handle .flac files and .flac encoded data.
Package font provides utilities to package together audio manipulations as a 'font'.
Package font provides utilities to package together audio manipulations as a 'font'.
ceol
Package ceol provides functionality to handle .ceol files and .ceol encoded data (Bosca Ceoil files).
Package ceol provides functionality to handle .ceol files and .ceol encoded data (Bosca Ceoil files).
dls
Package dls contains data structures for DLS (.dls) file types.
Package dls contains data structures for DLS (.dls) file types.
riff
Package riff reads and umarshalls RIFF files.
Package riff reads and umarshalls RIFF files.
Package klang provides audio playing and encoding support
Package klang provides audio playing and encoding support
filter
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.
filter/supports
Package supports holds interface types for filter supports.
Package supports holds interface types for filter supports.
Package mp3 provides functionality to handle .mp3 files and .mp3 encoded data.
Package mp3 provides functionality to handle .mp3 files and .mp3 encoded data.
Package sequence provides generators and options for creating audio sequences.
Package sequence provides generators and options for creating audio sequences.
Package synth provides functions and types to support waveform synthesis.
Package synth provides functions and types to support waveform synthesis.
Package wav provides functionality to handle .wav files and .wav encoded data.
Package wav provides functionality to handle .wav files and .wav encoded data.
Package wininternal defines common initialization steps for audio on windows.
Package wininternal defines common initialization steps for audio on windows.

Jump to

Keyboard shortcuts

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