wasmal

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 3 Imported by: 0

README

Go WASM Web Audio API

This project aims to expose the Web Audio API as Go API that can be used in wasm projects.

Warning: The project is in early development and the API is likely to change in backward incompatible ways!

Getting Started

You need to add the project as a dependency.

go get github.com/mokiat/wasmal@latest

The implementation uses syscall/js calls and as such requires that client applications are compiled with the GOOS=js and GOARCH=wasm options.

If you are unfamiliar with how Go and WASM works, then you should have a look at the official WebAssembly with Go documentation.

Documentation

Overview

Package wasmal exposes the Web Audio API through Go code.

Index

Constants

View Source
const DefaultSampleRate = 44100

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioBuffer

type AudioBuffer interface {
	SampleRate() float64
	Length() uint
	Duration() float64
	NumberOfChannels() uint
	// contains filtered or unexported methods
}

AudioBuffer as described here: https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer

type AudioBufferSourceNode

type AudioBufferSourceNode interface {
	AudioScheduledSourceNode

	Buffer() AudioBuffer
	SetBuffer(buffer AudioBuffer)
	Detune() AudioParam
	Loop() bool
	SetLoop(loop bool)
	LoopStart() float64
	SetLoopStart(start float64)
	LoopEnd() float64
	SetLoopEnd(end float64)
	PlaybackRate() AudioParam

	StartDetailed(when, offset float64, duration opt.T[float64])
}

AudioBufferSourceNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode

type AudioContext

type AudioContext interface {
	BaseAudioContext

	BaseLatency() float64
	OutputLatency() float64

	Close() Promise[struct{}]
	Resume() Promise[struct{}]
	Suspend() Promise[struct{}]
}

AudioContext as described here: https://developer.mozilla.org/en-US/docs/Web/API/AudioContext

func NewAudioContext

func NewAudioContext() AudioContext

type AudioContextState

type AudioContextState string

AudioContextState as described here: https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/state

const (
	AudioContextStateSuspended AudioContextState = "suspended"
	AudioContextStateRunning   AudioContextState = "running"
	AudioContextStateClosed    AudioContextState = "closed"
)

type AudioDestinationNode

type AudioDestinationNode interface {
	AudioNode

	MaxChannelCount() uint32
}

AudioDestinationNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/AudioDestinationNode

type AudioListener

type AudioListener interface {
	PositionX() AudioParam
	PositionY() AudioParam
	PositionZ() AudioParam
	ForwardX() AudioParam
	ForwardY() AudioParam
	ForwardZ() AudioParam
	UpX() AudioParam
	UpY() AudioParam
	UpZ() AudioParam
	// contains filtered or unexported methods
}

type AudioNode

type AudioNode interface {
	Context() BaseAudioContext
	NumberOfInputs() uint
	NumberOfOutputs() uint

	ConnectNode(destination AudioNode)
	ConnectParam(destination AudioParam)
	Disconnect()
	DisconnectNode(destination AudioNode)
	DisconnectParam(destination AudioParam)
	// contains filtered or unexported methods
}

AudioNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/AudioNode

type AudioParam

type AudioParam interface {
	DefaultValue() float64
	MaxValue() float64
	MinValue() float64
	Value() float64
	SetValue(value float64)

	SetValueAtTime(value, startTime float64)
	LinearRampToValueAtTime(value, endTime float64)
	ExponentialRampToValueAtTime(value, endTime float64)
	SetTargetAtTime(target, startTime, timeConstant float64)
	SetValueCurveAtTime(values []float64, startTime, duration float64)
	CancelScheduledValues(startTime float64)
	CancelAndHoldAtTime(cancelTime float64)
	// contains filtered or unexported methods
}

AudioParam as described here: https://developer.mozilla.org/en-US/docs/Web/API/AudioParam

type AudioScheduledSourceNode

type AudioScheduledSourceNode interface {
	AudioNode

	Start(when float64)
	Stop(when float64)
}

AudioScheduledSourceNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/AudioScheduledSourceNode

type BaseAudioContext

type BaseAudioContext interface {
	CurrentTime() float64
	Destination() AudioDestinationNode
	Listener() AudioListener
	SampleRate() float64
	State() AudioContextState

	CreateBuffer(numChannels, length, sampleRate uint) AudioBuffer
	CreateBufferSource() AudioBufferSourceNode
	CreateConvolver() ConvolverNode
	CreateDelay() DelayNode
	CreateDynamicsCompressor() DynamicsCompressorNode
	CreateGain() GainNode
	CreateOscillator() OscillatorNode
	CreatePanner() PannerNode
	CreateStereoPanner() StereoPannerNode
	DecodeAudioData(data []byte) Promise[AudioBuffer]
	// contains filtered or unexported methods
}

BaseAudioContext as described here: https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext

type ConvolverNode

type ConvolverNode interface {
	AudioNode

	Buffer() AudioBuffer
	SetBuffer(buffer AudioBuffer)
	Normalize() bool
	SetNormalize(normalize bool)
}

ConvolverNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/ConvolverNode

type DelayNode

type DelayNode interface {
	AudioNode

	DelayTime() AudioParam
}

DelayNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/DelayNode

type DynamicsCompressorNode

type DynamicsCompressorNode interface {
	AudioNode

	Threshold() AudioParam
	Knee() AudioParam
	Ratio() AudioParam
	Reduction() float64
	Attack() AudioParam
	Release() AudioParam
}

DynamicsCompressorNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/DynamicsCompressorNode

type GainNode

type GainNode interface {
	AudioNode

	Gain() AudioParam
}

GainNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/GainNode

type OscillatorNode

type OscillatorNode interface {
	AudioScheduledSourceNode

	Frequency() AudioParam
	Detune() AudioParam
	Type() OscillatorType
	SetType(oType OscillatorType)
}

OscillatorNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode

type OscillatorType

type OscillatorType string

OscillatorType as described here: https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode/type

const (
	OscillatorTypeSine     OscillatorType = "sine"
	OscillatorTypeSquare   OscillatorType = "square"
	OscillatorTypeSawTooth OscillatorType = "sawtooth"
	OscillatorTypeTriangle OscillatorType = "triangle"
	OscillatorTypeCustom   OscillatorType = "custom"
)

type PannerDistanceModel

type PannerDistanceModel string
const (
	PannerDistanceModelLinear      PannerDistanceModel = "linear"
	PannerDistanceModelInverse     PannerDistanceModel = "inverse"
	PannerDistanceModelExponential PannerDistanceModel = "exponential"
)

type PannerNode

type PannerNode interface {
	AudioNode

	ConeInnerAngle() float64
	SetConeInnerAngle(angle float64)
	ConeOuterAngle() float64
	SetConeOuterAngle(angle float64)
	DistanceModel() PannerDistanceModel
	SetDistanceModel(model PannerDistanceModel)
	MaxDistance() float64
	SetMaxDistance(distance float64)
	OrientationX() AudioParam
	OrientationY() AudioParam
	OrientationZ() AudioParam
	PanningModel() PannerPanningModel
	SetPanningModel(model PannerPanningModel)
	PositionX() AudioParam
	PositionY() AudioParam
	PositionZ() AudioParam
	RefDistance() float64
	SetRefDistance(distance float64)
	RolloffFactor() float64
	SetRolloffFactor(factor float64)
}

PannerNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/PannerNode

type PannerPanningModel

type PannerPanningModel string
const (
	PannerPanningModelEqualPower PannerPanningModel = "equalpower"
	PannerPanningModelHRTF       PannerPanningModel = "HRTF"
)

type Promise

type Promise[T any] interface {
	Then(cb func(value T)) Promise[T]
	Catch(cb func(err error)) Promise[T]
}

type StereoPannerNode

type StereoPannerNode interface {
	AudioNode
	Pan() AudioParam
}

StereoPannerNode as described here: https://developer.mozilla.org/en-US/docs/Web/API/StereoPannerNode

Jump to

Keyboard shortcuts

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