howler

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: MIT Imports: 4 Imported by: 0

README

go-howler.js

A Go wrapping of Howler.js using the syscall/js package.

Example

//go:build js && wasm

package main

import (
	"github.com/medievalsoftware/go-howler.js"
)

func main() {
	howler.New(howler.HowlOptions{
		Source:   []any{"cheeky-buggers.mp3"},
		Volume:   0.5,
		Autoplay: true,
		Loop:     true,
		OnEnd: func() {
			println("finished!")
		},
	})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoSuspend

func AutoSuspend() bool

AutoSuspend suspends the Web Audio AudioContext after 30 seconds of inactivity to decrease processing and energy usage. Automatically resumes upon new playback. Set this property to false to disable this behavior.

func AutoUnlock

func AutoUnlock() bool

AutoUnlock attempts to enable audio on mobile (iOS, Android, etc) devices and desktop Chrome/Safari.

func Codecs

func Codecs(extension string) bool

Codecs checks supported audio codecs. Returns true if the codec is supported in the current browser.

func HTML5PoolSize

func HTML5PoolSize() int

HTML5PoolSize gets the pool size. Each HTML5 Audio object must be unlocked individually, so we keep a global pool of unlocked nodes to share between all Howl instances. This pool gets created on the first user interaction and is set to the size of this property.

func Mute

func Mute(mute bool)

Mute or unmute all sounds.

func NoAudio

func NoAudio() bool

NoAudio returns true if no audio is available.

func Orientation

func Orientation() (orientation []float64)

Orientation gets the direction the listener is pointing in the 3D cartesian space. A front and up vector must be provided. The front is the direction the face of the listener is pointing, and up is the direction the top of the listener is pointing. Thus, these values are expected to be at right angles from each other. [x, y, z, xUp, yUp, zUp]

func Pos

func Pos() (x, y, z float64)

Pos gets the position of the listener in 3D cartesian space.

func SetAutoSuspend

func SetAutoSuspend(auto bool)

SetAutoSuspend sets the AutoSuspend property.

func SetAutoUnlock

func SetAutoUnlock(autoUnlock bool)

SetAutoUnlock sets the AutoUnlock property.

func SetHTML5PoolSize

func SetHTML5PoolSize(size int)

SetHTML5PoolSize sets the HTML5PoolSize property.

func SetOrientation

func SetOrientation(x, y, z, upX, upY, upZ float64)

SetOrientation sets the orientation.

func SetPos

func SetPos(x, y, z float32)

SetPos sets the position of the listener in 3D cartesian space. Sounds using 3D position will be relative to the listener's position.

func SetStereo

func SetStereo(stereo float64)

SetStereo is a helper method to update the stereo panning position of all current Howls. Future Howls will not use this value unless explicitly set.

func SetVolume

func SetVolume(volume float64)

SetVolume sets the global volume for all sounds, relative to their own volume.

func Stop

func Stop()

Stop all sounds and reset their seek position to the beginning.

func Unload

func Unload()

Unload and destroy all currently loaded Howl objects. This will immediately stop all sounds and remove them from cache.

func UsingWebAudio

func UsingWebAudio() bool

UsingWebAudio returns true if the Web Audio API is available.

func Volume

func Volume() float64

Volume gets the global volume for all sounds.

Types

type CallbackErrorFunc

type CallbackErrorFunc func(error)

type CallbackFunc

type CallbackFunc func()

type DistanceModel

type DistanceModel int
const (
	DistanceModelUndefined DistanceModel = iota
	DistanceModelLinear
	DistanceModelInverse
	DistanceModelExponential
)

type OptionalBool

type OptionalBool = any

type OptionalFloat

type OptionalFloat = any

type OptionalInt

type OptionalInt = any

type OptionalString

type OptionalString = any

type PannerAttr

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

func (PannerAttr) ConeInnerAngle

func (a PannerAttr) ConeInnerAngle() float64

func (PannerAttr) ConeOuterAngle

func (a PannerAttr) ConeOuterAngle() float64

func (PannerAttr) ConeOuterGain

func (a PannerAttr) ConeOuterGain() float64

func (PannerAttr) DistanceModel

func (a PannerAttr) DistanceModel() DistanceModel

func (PannerAttr) MaxDistance

func (a PannerAttr) MaxDistance() float64

func (PannerAttr) PanningModel

func (a PannerAttr) PanningModel() PanningModel

func (PannerAttr) RefDistance

func (a PannerAttr) RefDistance() float64

func (PannerAttr) RolloffFactor

func (a PannerAttr) RolloffFactor() float64

func (PannerAttr) SetConeInnerAngle

func (a PannerAttr) SetConeInnerAngle(angle float64)

func (PannerAttr) SetConeOuterAngle

func (a PannerAttr) SetConeOuterAngle(angle float64)

func (PannerAttr) SetConeOuterGain

func (a PannerAttr) SetConeOuterGain(gain float64)

func (PannerAttr) SetDistanceModel

func (a PannerAttr) SetDistanceModel(model DistanceModel)

func (PannerAttr) SetMaxDistance

func (a PannerAttr) SetMaxDistance(distance float64)

func (PannerAttr) SetPanningModel

func (a PannerAttr) SetPanningModel(model PanningModel)

func (PannerAttr) SetRefDistance

func (a PannerAttr) SetRefDistance(distance float64)

func (PannerAttr) SetRolloffFactor

func (a PannerAttr) SetRolloffFactor(factor float64)

type PannerOptions

type PannerOptions struct {
	// ConeInnerAngle is a parameter for directional audio sources, this is an angle, in
	// degrees, inside of which there will be no volume reduction. default: 360
	ConeInnerAngle OptionalFloat `json:"cone_inner_angle,omitempty"`

	// ConeOuterAngle is a parameter for directional audio sources, this is an angle, in
	// degrees, outside of which the volume will be reduced to a constant value of
	// ConeOuterGain. default: 360
	ConeOuterAngle OptionalFloat `json:"cone_outer_angle,omitempty"`

	// ConeOuterGain is a parameter for directional audio sources, this is the gain
	// outside of the coneOuterAngle. It is a linear value in the range [0, 1].
	ConeOuterGain OptionalFloat `json:"cone_outer_gain,omitempty"`

	// DistanceModel determines algorithm used to reduce volume as audio moves away
	// from listener. Can be DistanceModelLinear, DistanceModelInverse or DistanceModelExponential.
	DistanceModel DistanceModel `json:"distance_model,omitempty"`

	// The maximum distance between source and listener, after which the volume will
	// not be reduced any further. default: 10000
	MaxDistance OptionalFloat `json:"max_distance,omitempty"`

	// A reference distance for reducing volume as source moves further from the
	// listener. This is simply a variable of the distance model and has a different
	// effect depending on which model is used and the scale of your coordinates.
	// Generally, volume will be equal to 1 at this distance. default: 1
	RefDistance OptionalFloat `json:"ref_distance,omitempty"`

	// How quickly the volume reduces as source moves from listener. This is simply a
	// variable of the distance model and can be in the range of [0, 1] with linear
	// and [0, ∞] with inverse and exponential.
	RolloffFactor OptionalFloat `json:"rolloff_factor,omitempty"`

	// Determines which spatialization algorithm is used to position audio. Can be
	// PanningModelHRTF or PanningModelEqualPower.
	PanningModel PanningModel `json:"panning_model,omitempty"`
}

type PanningModel

type PanningModel int
const (
	PanningModelUndefined PanningModel = iota
	PanningModelHRTF
	PanningModelEqualPower
)

type Sound

type Sound interface {
	ID() int
	State() State
	Playing() bool
	Duration() time.Duration
	Play() Sound
	Pause()
	Stop()
	Mute()
	Unmute()
	Fade(from float64, to float64, duration time.Duration)
	Volume() float64
	SetVolume(volume float64)
	Rate() float64
	SetRate(float64)
	Seek() time.Duration
	SetSeek(duration time.Duration)
	Loop() bool
	SetLoop(loop bool)
	Stereo() float64
	SetStereo(stereo float64)
	Pos() (x, y, z float64)
	SetPos(x, y, z float64)
	Orientation() (x, y, z float64)
	SetOrientation(x, y, z float64)
	PannerAttr() PannerAttr
	SetPannerAttr(attr PannerAttr)
}

type State

type State int

State describes the load status of a given Howl.

const (
	StateUnloaded State = iota
	StateLoading
	StateLoaded
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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