WebAudio

clay.base.BaseAudioclay.web.WebAudio (Class)

Static Members

MAX_WORKLET_PARAMS: Int

Instance Members


active: Bool

init(): Void

tick(delta: Float): Void
Name Type
delta Float

shutdown(): Void

createBus(index: Int, ?name: String = "", ?volume: Float = 1.0): Void
Name Type Default
index Int
name String ""
volume Float 1.0

destroyBus(index: Int): Void
Name Type
index Int

setBusVolume(busIndex: Int, volume: Float): Void
Name Type
busIndex Int
volume Float

getBusVolume(busIndex: Int): Float
Name Type
busIndex Int
Returns
Float

setBusActive(busIndex: Int, active: Bool): Void
Name Type
busIndex Int
active Bool

loadWorkletModule(name: String, url: String, ?callback: Function): Void
Name Type Default
name String
url String
callback Function (optional)

attachWorkletToBus(busIndex: Int, workletName: String, ?options: Dynamic, ?onReady: Function): Bool
Name Type Default
busIndex Int
workletName String
options Dynamic (optional)
onReady Function (optional)
Returns
Bool

detachWorkletFromBus(busIndex: Int): Void
Name Type
busIndex Int

sendMessageToWorklet(busIndex: Int, message: Dynamic): Void
Name Type
busIndex Int
message Dynamic

scheduleWhenBusWorkletReady(busIndex: Int, ready: Function): Void
Name Type
busIndex Int
ready Function

setWorkletParameterWhenReady(busIndex: Int, paramName: String, value: Float): Void
Name Type
busIndex Int
paramName String
value Float

setWorkletParameter(busIndex: Int, paramName: String, value: Float): Void
Name Type
busIndex Int
paramName String
value Float

setWorkletParameterByIndexWhenReady(busIndex: Int, paramIndex: Int, value: Float): Void
Name Type
busIndex Int
paramIndex Int
value Float

setWorkletParameterByIndex(busIndex: Int, paramIndex: Int, value: Float): Void
Name Type
busIndex Int
paramIndex Int
value Float

getWorkletParameterByIndex(busIndex: Int, paramIndex: Int): Float
Name Type
busIndex Int
paramIndex Int
Returns
Float

play(source: clay.audio.AudioSource, volume: Float, paused: Bool, ?busIndex: Int = DEFAULT_BUS): clay.audio.AudioHandle
Name Type Default
source clay.audio.AudioSource
volume Float
paused Bool
busIndex Int DEFAULT_BUS
Returns
clay.audio.AudioHandle

loop(source: clay.audio.AudioSource, volume: Float, paused: Bool, ?busIndex: Int = DEFAULT_BUS): clay.audio.AudioHandle
Name Type Default
source clay.audio.AudioSource
volume Float
paused Bool
busIndex Int DEFAULT_BUS
Returns
clay.audio.AudioHandle

Name Type
handle clay.audio.AudioHandle

unPause(handle: clay.audio.AudioHandle): Void
Name Type
handle clay.audio.AudioHandle

Name Type
handle clay.audio.AudioHandle

volume(handle: clay.audio.AudioHandle, volume: Float): Void
Name Type
handle clay.audio.AudioHandle
volume Float

pan(handle: clay.audio.AudioHandle, pan: Float): Void
Name Type
handle clay.audio.AudioHandle
pan Float

pitch(handle: clay.audio.AudioHandle, pitch: Float): Void
Name Type
handle clay.audio.AudioHandle
pitch Float

position(handle: clay.audio.AudioHandle, time: Float): Void
Name Type
handle clay.audio.AudioHandle
time Float

volumeOf(handle: clay.audio.AudioHandle): Float
Name Type
handle clay.audio.AudioHandle
Returns
Float

Name Type
handle clay.audio.AudioHandle
Returns
Float

pitchOf(handle: clay.audio.AudioHandle): Float
Name Type
handle clay.audio.AudioHandle
Returns
Float

positionOf(handle: clay.audio.AudioHandle): Float
Name Type
handle clay.audio.AudioHandle
Returns
Float

Name Type
handle clay.audio.AudioHandle
Returns
clay.audio.AudioState

loopOf(handle: clay.audio.AudioHandle): Bool
Name Type
handle clay.audio.AudioHandle
Returns
Bool

Name Type
handle clay.audio.AudioHandle
Returns
clay.audio.AudioInstance

suspend(): Void

resume(): Void

getSoundBus(handle: clay.audio.AudioHandle): Int
Name Type
handle clay.audio.AudioHandle
Returns
Int

moveSoundToBus(handle: clay.audio.AudioHandle, newBusIndex: Int): Bool
Name Type
handle clay.audio.AudioHandle
newBusIndex Int
Returns
Bool

listBusses(): Array<Int>
Returns
Array<Int>

getBusName(busIndex: Int): String
Name Type
busIndex Int
Returns
String

createBusFilter(uri: String, busIndex: Int, createFunc: Function, destroyFunc: Function): Void
Name Type
uri String
busIndex Int
createFunc Function
destroyFunc Function

addBusFilterWorklet(busIndex: Int, filterId: Int, workletClass: Class<Any>, workletReady: Function): Void
Name Type
busIndex Int
filterId Int
workletClass Class<Any>
workletReady Function

destroyBusFilterWorklet(busIndex: Int, filterId: Int): Void
Name Type
busIndex Int
filterId Int

loadData(path: String, isStream: Bool, format: clay.audio.AudioFormat, ?async: Bool = false, ?callback: Function): clay.audio.AudioData
Name Type Default
path String
isStream Bool
format clay.audio.AudioFormat
async Bool false
callback Function (optional)
Returns
clay.audio.AudioData

dataFromBytes(id: String, bytes: clay.buffers.Uint8Array, ?format: clay.audio.AudioFormat, ?callback: Function): Void
Name Type Default
id String
bytes clay.buffers.Uint8Array
format clay.audio.AudioFormat (optional)
callback Function (optional)

dataFromPCM(id: String, pcmData: clay.buffers.Float32Array, sampleFrames: Int, channels: Int, sampleRate: Float, ?interleaved: Bool = true, ?format: clay.audio.AudioFormat, ?callback: Function): clay.audio.AudioData

Creates AudioData from raw PCM Float32 samples.

Name Type Default Description
id String Unique identifier for this audio data
pcmData clay.buffers.Float32Array Float32Array containing the raw PCM samples
sampleFrames Int Number of sample frames (samples per channel)
channels Int Number of audio channels (1 = mono, 2 = stereo, etc.)
sampleRate Float Sample rate in Hz (e.g., 44100)
interleaved Bool true Whether the PCM data is interleaved (LRLRLR...) or planar (LLL...RRR...)
format clay.audio.AudioFormat (optional) Optional audio format information
callback Function (optional) Optional callback when AudioData is ready
Returns
clay.audio.AudioData

Private Members

HALF_PI: Float

DEFAULT_BUS: Int

suspended: Bool

handleSeq: Int

instances: Map

buffers: Map

busses: Map

workletModules: Map

ignoreEndedSoundsTick0: Array<clay.web._WebAudio.WebSound>

ignoreEndedSoundsTick1: Array<clay.web._WebAudio.WebSound>

pendingBusWorkletCallbacks: Array<Array<Function>>

workletMessageCallbacks: Array<Dynamic>

initWebAudio(?sampleRate: Int = 44100): Void
Name Type Default
sampleRate Int 44100

createDefaultBus(): Void

flushBusWorkletReadyCallbacks(busIndex: Int): Void
Name Type
busIndex Int

Name Type
handle clay.audio.AudioHandle
Returns
clay.web._WebAudio.WebSound

getBusGainNode(busIndex: Int): js.html.audio.GainNode
Name Type
busIndex Int
Returns
js.html.audio.GainNode

Name Type
data clay.web._WebAudio.WebAudioData
Returns
js.html.audio.AudioBufferSourceNode

playBufferAgain(handle: clay.audio.AudioHandle, sound: clay.web._WebAudio.WebSound, startTime: Float): Void
Name Type
handle clay.audio.AudioHandle
sound clay.web._WebAudio.WebSound
startTime Float

playInstance(handle: clay.audio.AudioHandle, source: clay.audio.AudioSource, inst: clay.audio.AudioInstance, data: clay.web._WebAudio.WebAudioData, bufferNode: js.html.audio.AudioBufferSourceNode, volume: Float, loop: Bool, ?busIndex: Int = DEFAULT_BUS): Void
Name Type Default
handle clay.audio.AudioHandle
source clay.audio.AudioSource
inst clay.audio.AudioInstance
data clay.web._WebAudio.WebAudioData
bufferNode js.html.audio.AudioBufferSourceNode
volume Float
loop Bool
busIndex Int DEFAULT_BUS

Name Type
sound clay.web._WebAudio.WebSound

Name Type
sound clay.web._WebAudio.WebSound

destroySound(sound: clay.web._WebAudio.WebSound): Void
Name Type
sound clay.web._WebAudio.WebSound

ensureBusExists(busIndex: Int): Bool
Name Type
busIndex Int
Returns
Bool

handleSourceDestroyed(source: clay.audio.AudioSource): Void
Name Type
source clay.audio.AudioSource

handleInstanceDestroyed(handle: clay.audio.AudioHandle): Void
Name Type
handle clay.audio.AudioHandle

loadDataFromSound(path: String, format: clay.audio.AudioFormat, ?callback: Function): Void
Name Type Default
path String
format clay.audio.AudioFormat
callback Function (optional)

loadDataFromStream(path: String, format: clay.audio.AudioFormat, ?callback: Function): Void
Name Type Default
path String
format clay.audio.AudioFormat
callback Function (optional)

new(app: clay.Clay): Void
Name Type
app clay.Clay

Metadata

Name Parameters
:allow clay.audio.AudioInstance
:allow clay.audio.AudioSource