audio

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentContext

func CurrentContext() *audio.Context

func GetStereoSampleAsF32s

func GetStereoSampleAsF32s(buffer []byte) (float32, float32)

func GetStereoSampleAsI16s

func GetStereoSampleAsI16s(buffer []byte) (int16, int16)

func Initialize

func Initialize(sampleRate int)

Can only be called once.

func IsContextReady

func IsContextReady() bool

func NaNsToZero

func NaNsToZero[T Float](buffer []T)

func NormalizeF32

func NormalizeF32(value float32) float32

func SampleRate

func SampleRate() int

func StoreL16Sample

func StoreL16Sample(buffer []byte, left int16, right int16)

func StoreNormF32StereoSampleAsL16

func StoreNormF32StereoSampleAsL16(buffer []byte, left, right float32)

func TimeDurationToOffset

func TimeDurationToOffset(duration time.Duration) int64

func TimeDurationToSamples

func TimeDurationToSamples(duration time.Duration) int64

Types

type Adder

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

func NewAdder

func NewAdder(sources ...StereoProcessor) *Adder

func (*Adder) GetPosition

func (self *Adder) GetPosition() int64

func (*Adder) SeekSample

func (self *Adder) SeekSample(n int) error

func (*Adder) WriteStereo

func (self *Adder) WriteStereo(buffer []float32) (int, error)

type AutomationPanel

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

Most loosely typed mess ever. Very practical.

func NewAutomationPanel

func NewAutomationPanel() *AutomationPanel

func (*AutomationPanel) GetResource

func (self *AutomationPanel) GetResource(key ResourceKey) any

func (*AutomationPanel) RegisterTrigger

func (self *AutomationPanel) RegisterTrigger(trigger func() error) TriggerKey

func (*AutomationPanel) StoreResource

func (self *AutomationPanel) StoreResource(resource any) ResourceKey

func (*AutomationPanel) Trigger

func (self *AutomationPanel) Trigger(key TriggerKey) error

type BGM

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

func NewBgmFromFader

func NewBgmFromFader(fader *Fader) *BGM

func NewBgmFromLooper

func NewBgmFromLooper(loop *edau.Looper) *BGM

func (*BGM) DeletePlayer

func (self *BGM) DeletePlayer() error

func (*BGM) FadeIn

func (self *BGM) FadeIn(startWait, fadeDuration time.Duration)

func (*BGM) FadeOut

func (self *BGM) FadeOut(fadeDuration time.Duration)

func (*BGM) FullyFadedOut

func (self *BGM) FullyFadedOut() bool

func (*BGM) Pause

func (self *BGM) Pause()

func (*BGM) Play

func (self *BGM) Play() error

func (*BGM) Rewind

func (self *BGM) Rewind() error

func (*BGM) SetMasterVolume added in v0.0.3

func (self *BGM) SetMasterVolume(factor float32)

func (*BGM) SetMuted added in v0.0.3

func (self *BGM) SetMuted(muted bool)

func (*BGM) SetPosition

func (self *BGM) SetPosition(position time.Duration) error

func (*BGM) SetUserVolume

func (self *BGM) SetUserVolume(volume float32)

func (*BGM) SetVolumeCorrectorFactor

func (self *BGM) SetVolumeCorrectorFactor(factor float32)

type BgmKey

type BgmKey uint8

type FadeType

type FadeType uint8
const (
	FadeNone FadeType = 0
	FadeIn   FadeType = 1
	FadeOut  FadeType = 2
	FadeWait FadeType = 3
)

type Fader

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

func NewFader

func NewFader(source StereoProcessor) *Fader

func (*Fader) ForceVolume

func (self *Fader) ForceVolume(targetVolume float32)

Only advisable to use during setup if you want some fader to start at 1 instead of 0. Forcing volume changes while playing or similar is almost always wrong.

func (*Fader) FullyFadedOut

func (self *Fader) FullyFadedOut() bool

Typically used to know if we can pause the player. If audio.Player provided direct access to the source or had special error return values to pause it, life could be a bit easier.

func (*Fader) GetPosition

func (self *Fader) GetPosition() int64

func (*Fader) SeekSample

func (self *Fader) SeekSample(n int) error

func (*Fader) Transition

func (self *Fader) Transition(targetVolume float32, waitSamples, fadeSamples int64)

Target volume should be in [0, 1]. Values below 0 will panic, but values slightly above 1 may be useful in some scenarios, so they aren't checked. You should be extremely careful with that, though.

func (*Fader) WriteStereo

func (self *Fader) WriteStereo(buffer []float32) (int, error)

type Float

type Float interface{ ~float32 | ~float64 }

type ProcessorInAdapterL16

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

func NewProcessorInAdapterL16

func NewProcessorInAdapterL16(source io.ReadSeeker) *ProcessorInAdapterL16

func (*ProcessorInAdapterL16) GetPosition

func (self *ProcessorInAdapterL16) GetPosition() int64

func (*ProcessorInAdapterL16) Read

func (self *ProcessorInAdapterL16) Read(buffer []byte) (int, error)

func (*ProcessorInAdapterL16) Seek

func (self *ProcessorInAdapterL16) Seek(offset int64, whence int) (int64, error)

func (*ProcessorInAdapterL16) SeekSample

func (self *ProcessorInAdapterL16) SeekSample(sample int) error

func (*ProcessorInAdapterL16) WriteStereo

func (self *ProcessorInAdapterL16) WriteStereo(buffer []float32) (int, error)

type ProcessorOutAdapterL16

type ProcessorOutAdapterL16[Source StereoProcessor] struct {
	// contains filtered or unexported fields
}

func NewProcessorOutAdapterL16

func NewProcessorOutAdapterL16[T StereoProcessor](source T) *ProcessorOutAdapterL16[T]

func (*ProcessorOutAdapterL16[T]) Read

func (self *ProcessorOutAdapterL16[T]) Read(buffer []byte) (int, error)

func (*ProcessorOutAdapterL16[T]) Seek

func (self *ProcessorOutAdapterL16[T]) Seek(offset int64, whence int) (int64, error)

func (*ProcessorOutAdapterL16[T]) SetMasterVolume added in v0.0.3

func (self *ProcessorOutAdapterL16[T]) SetMasterVolume(volume float32)

func (*ProcessorOutAdapterL16[T]) SetMuted added in v0.0.3

func (self *ProcessorOutAdapterL16[T]) SetMuted(muted bool)

func (*ProcessorOutAdapterL16[T]) SetUserVolume

func (self *ProcessorOutAdapterL16[T]) SetUserVolume(volume float32)

func (*ProcessorOutAdapterL16[T]) SetVolumeCorrectorFactor

func (self *ProcessorOutAdapterL16[T]) SetVolumeCorrectorFactor(factor float32)

type ResourceKey

type ResourceKey uint8

type SfxKey

type SfxKey uint8

type SfxPlayer

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

func NewSfxPlayer

func NewSfxPlayer(bytes ...[]byte) *SfxPlayer

func (*SfxPlayer) Play

func (self *SfxPlayer) Play()

func (*SfxPlayer) PlayWithVolume added in v0.0.3

func (self *SfxPlayer) PlayWithVolume(volume float32)

Typically the volume is masterVolume*sfxVolume.

func (*SfxPlayer) SetBackoff

func (self *SfxPlayer) SetBackoff(duration time.Duration)

func (*SfxPlayer) SetVolumeCorrectorFactor

func (self *SfxPlayer) SetVolumeCorrectorFactor(factor float32)

type Soundscape

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

func NewSoundscape

func NewSoundscape() *Soundscape

func (*Soundscape) AutomationPanel

func (self *Soundscape) AutomationPanel() *AutomationPanel

func (*Soundscape) Crossfade

func (self *Soundscape) Crossfade(key BgmKey, fadeOut, inWait, fadeIn time.Duration)

func (*Soundscape) FadeIn

func (self *Soundscape) FadeIn(key BgmKey, fadeOut, wait, fadeIn time.Duration)

func (*Soundscape) FadeOut

func (self *Soundscape) FadeOut(fadeOut time.Duration)

func (*Soundscape) GetBGMMuted added in v0.0.3

func (self *Soundscape) GetBGMMuted() bool

func (*Soundscape) GetMasterMuted added in v0.0.3

func (self *Soundscape) GetMasterMuted() bool

func (*Soundscape) GetMasterVolume added in v0.0.3

func (self *Soundscape) GetMasterVolume() float32

func (*Soundscape) GetSFXMuted added in v0.0.3

func (self *Soundscape) GetSFXMuted() bool

func (*Soundscape) GetUserBGMVolume

func (self *Soundscape) GetUserBGMVolume() float32

func (*Soundscape) GetUserSFXVolume

func (self *Soundscape) GetUserSFXVolume() float32

func (*Soundscape) IsActive

func (self *Soundscape) IsActive(key BgmKey) bool

func (*Soundscape) PlaySFX

func (self *Soundscape) PlaySFX(key SfxKey)

func (*Soundscape) RegisterBGM

func (self *Soundscape) RegisterBGM(bgm *BGM) BgmKey

func (*Soundscape) RegisterSFX

func (self *Soundscape) RegisterSFX(sfx *SfxPlayer) SfxKey

func (*Soundscape) SetBGMMuted added in v0.0.3

func (self *Soundscape) SetBGMMuted(muted bool)

func (*Soundscape) SetMasterMuted added in v0.0.3

func (self *Soundscape) SetMasterMuted(muted bool)

func (*Soundscape) SetMasterVolume added in v0.0.3

func (self *Soundscape) SetMasterVolume(volume float32)

Notice: SFXs volume will not change until next play if already playing.

func (*Soundscape) SetSFXMuted added in v0.0.3

func (self *Soundscape) SetSFXMuted(muted bool)

func (*Soundscape) SetUserBGMVolume

func (self *Soundscape) SetUserBGMVolume(volume float32)

func (*Soundscape) SetUserSFXVolume

func (self *Soundscape) SetUserSFXVolume(volume float32)

func (*Soundscape) Update

func (self *Soundscape) Update() error

type StereoProcessor

type StereoProcessor interface {
	// Returns the number of samples written. This can be at most len(buffer)/2,
	// as the buffer stores interleaved channel values.
	WriteStereo(buffer []float32) (int, error)

	// Seek the given sample.
	SeekSample(n int) error

	// Get the current position in samples.
	GetPosition() int64
}

type TriggerKey

type TriggerKey uint8

Jump to

Keyboard shortcuts

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