import { Chuck } from 'webchuck'
const chuck = await Chuck.init([]);
chuck.runCode(`
SinOsc sin => dac;
220 => sin.freq;
1::week => now;
`);
Note that many browsers do not let audio run without a user interaction. You can check for a suspended audio context and resume like this:
if (chuck.context.state === "suspended") {
chuck.context.resume();
}
-
AudioWorkletNode↳
Chuck
- channelCount
- channelCountMode
- channelInterpretation
- chuckID
- context
- deferredPromiseCounter
- deferredPromises
- eventCallbackCounter
- eventCallbacks
- isReady
- numberOfInputs
- numberOfOutputs
- onprocessorerror
- parameters
- port
- addEventListener
- broadcastEvent
- clearChuckInstance
- clearGlobals
- connect
- createFile
- disconnect
- dispatchEvent
- getAssociativeFloatArrayValue
- getAssociativeIntArrayValue
- getFloat
- getFloatArray
- getFloatArrayValue
- getInt
- getIntArray
- getIntArrayValue
- getString
- isShredActive
- listenForEventOnce
- nextDeferID
- receiveMessage
- removeEventListener
- removeLastCode
- removeShred
- replaceCode
- replaceCodeWithReplacementDac
- replaceFile
- replaceFileWithArgs
- replaceFileWithArgsWithReplacementDac
- replaceFileWithReplacementDac
- runCode
- runCodeWithReplacementDac
- runFile
- runFileWithArgs
- runFileWithArgsWithReplacementDac
- runFileWithReplacementDac
- sendMessage
- setAssociativeFloatArrayValue
- setAssociativeIntArrayValue
- setFloat
- setFloatArray
- setFloatArrayValue
- setInt
- setIntArray
- setIntArrayValue
- setString
- signalEvent
- startListeningForEvent
- stopListeningForEvent
- init
• new Chuck(preloadedFiles, audioContext, wasm)
| Name | Type |
|---|---|
preloadedFiles |
File[] |
audioContext |
AudioContext |
wasm |
ArrayBuffer |
window.AudioWorkletNode.constructor
• channelCount: number
window.AudioWorkletNode.channelCount
• channelCountMode: ChannelCountMode
window.AudioWorkletNode.channelCountMode
• channelInterpretation: ChannelInterpretation
window.AudioWorkletNode.channelInterpretation
• Private chuckID: number
• Readonly context: BaseAudioContext
window.AudioWorkletNode.context
• Private deferredPromiseCounter: number = 0
• Private deferredPromises: Object = {}
▪ [key: number]: any
• Private eventCallbackCounter: number = 0
• Private eventCallbacks: Object = {}
▪ [key: number]: any
• Private isReady: DeferredPromise
• Readonly numberOfInputs: number
window.AudioWorkletNode.numberOfInputs
• Readonly numberOfOutputs: number
window.AudioWorkletNode.numberOfOutputs
• onprocessorerror: null | (this: AudioWorkletNode, ev: Event) => any
window.AudioWorkletNode.onprocessorerror
• Readonly parameters: AudioParamMap
window.AudioWorkletNode.parameters
• Readonly port: MessagePort
window.AudioWorkletNode.port
▸ addEventListener<K>(type, listener, options?): void
| Name | Type |
|---|---|
K |
extends "processorerror" |
| Name | Type |
|---|---|
type |
K |
listener |
(this: AudioWorkletNode, ev: AudioWorkletNodeEventMap[K]) => any |
options? |
boolean | AddEventListenerOptions |
void
window.AudioWorkletNode.addEventListener
▸ addEventListener(type, listener, options?): void
| Name | Type |
|---|---|
type |
string |
listener |
EventListenerOrEventListenerObject |
options? |
boolean | AddEventListenerOptions |
void
window.AudioWorkletNode.addEventListener
▸ broadcastEvent(variable): void
| Name | Type |
|---|---|
variable |
string |
void
▸ clearChuckInstance(): void
void
▸ clearGlobals(): void
void
▸ connect(destinationNode, output?, input?): AudioNode
| Name | Type |
|---|---|
destinationNode |
AudioNode |
output? |
number |
input? |
number |
AudioNode
window.AudioWorkletNode.connect
▸ connect(destinationParam, output?): void
| Name | Type |
|---|---|
destinationParam |
AudioParam |
output? |
number |
void
window.AudioWorkletNode.connect
▸ createFile(directory, filename, data): void
| Name | Type |
|---|---|
directory |
string |
filename |
string |
data |
string |
void
▸ disconnect(): void
void
window.AudioWorkletNode.disconnect
▸ disconnect(output): void
| Name | Type |
|---|---|
output |
number |
void
window.AudioWorkletNode.disconnect
▸ disconnect(destinationNode): void
| Name | Type |
|---|---|
destinationNode |
AudioNode |
void
window.AudioWorkletNode.disconnect
▸ disconnect(destinationNode, output): void
| Name | Type |
|---|---|
destinationNode |
AudioNode |
output |
number |
void
window.AudioWorkletNode.disconnect
▸ disconnect(destinationNode, output, input): void
| Name | Type |
|---|---|
destinationNode |
AudioNode |
output |
number |
input |
number |
void
window.AudioWorkletNode.disconnect
▸ disconnect(destinationParam): void
| Name | Type |
|---|---|
destinationParam |
AudioParam |
void
window.AudioWorkletNode.disconnect
▸ disconnect(destinationParam, output): void
| Name | Type |
|---|---|
destinationParam |
AudioParam |
output |
number |
void
window.AudioWorkletNode.disconnect
▸ dispatchEvent(event): boolean
Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
| Name | Type |
|---|---|
event |
Event |
boolean
window.AudioWorkletNode.dispatchEvent
▸ getAssociativeFloatArrayValue(variable, key): any
| Name | Type |
|---|---|
variable |
string |
key |
string |
any
▸ getAssociativeIntArrayValue(variable, key): any
| Name | Type |
|---|---|
variable |
string |
key |
string |
any
▸ getFloat(variable): any
| Name | Type |
|---|---|
variable |
string |
any
▸ getFloatArray(variable): any
| Name | Type |
|---|---|
variable |
string |
any
▸ getFloatArrayValue(variable, index): any
| Name | Type |
|---|---|
variable |
string |
index |
number |
any
▸ getInt(variable): any
| Name | Type |
|---|---|
variable |
string |
any
▸ getIntArray(variable): any
| Name | Type |
|---|---|
variable |
string |
any
▸ getIntArrayValue(variable, index): any
| Name | Type |
|---|---|
variable |
string |
index |
number |
any
▸ getString(variable): any
| Name | Type |
|---|---|
variable |
string |
any
▸ isShredActive(shred): any
| Name | Type |
|---|---|
shred |
string |
any
▸ listenForEventOnce(variable, callback): void
| Name | Type |
|---|---|
variable |
string |
callback |
Promise<any> |
void
▸ Private nextDeferID(): number
number
▸ Private receiveMessage(event): void
| Name | Type |
|---|---|
event |
MessageEvent<any> |
void
▸ removeEventListener<K>(type, listener, options?): void
| Name | Type |
|---|---|
K |
extends "processorerror" |
| Name | Type |
|---|---|
type |
K |
listener |
(this: AudioWorkletNode, ev: AudioWorkletNodeEventMap[K]) => any |
options? |
boolean | EventListenerOptions |
void
window.AudioWorkletNode.removeEventListener
▸ removeEventListener(type, listener, options?): void
| Name | Type |
|---|---|
type |
string |
listener |
EventListenerOrEventListenerObject |
options? |
boolean | EventListenerOptions |
void
window.AudioWorkletNode.removeEventListener
▸ removeLastCode(): any
any
▸ removeShred(shred): any
| Name | Type |
|---|---|
shred |
string |
any
▸ replaceCode(code): any
| Name | Type |
|---|---|
code |
string |
any
▸ replaceCodeWithReplacementDac(code, dacName): any
| Name | Type |
|---|---|
code |
string |
dacName |
string |
any
▸ replaceFile(filename): any
| Name | Type |
|---|---|
filename |
string |
any
▸ replaceFileWithArgs(filename, colonSeparatedArgs): any
| Name | Type |
|---|---|
filename |
string |
colonSeparatedArgs |
string |
any
▸ replaceFileWithArgsWithReplacementDac(filename, colonSeparatedArgs, dacName): any
| Name | Type |
|---|---|
filename |
string |
colonSeparatedArgs |
string |
dacName |
string |
any
▸ replaceFileWithReplacementDac(filename, dacName): any
| Name | Type |
|---|---|
filename |
string |
dacName |
string |
any
▸ runCode(code): any
| Name | Type |
|---|---|
code |
string |
any
▸ runCodeWithReplacementDac(code, dacName): any
| Name | Type |
|---|---|
code |
string |
dacName |
string |
any
▸ runFile(filename): any
| Name | Type |
|---|---|
filename |
string |
any
▸ runFileWithArgs(filename, colonSeparatedArgs): any
| Name | Type |
|---|---|
filename |
string |
colonSeparatedArgs |
string |
any
▸ runFileWithArgsWithReplacementDac(filename, colonSeparatedArgs, dacName): any
| Name | Type |
|---|---|
filename |
string |
colonSeparatedArgs |
string |
dacName |
string |
any
▸ runFileWithReplacementDac(filename, dacName): any
| Name | Type |
|---|---|
filename |
string |
dacName |
string |
any
▸ Private sendMessage(type, body?): void
| Name | Type |
|---|---|
type |
OutMessage |
body? |
Object |
void
▸ setAssociativeFloatArrayValue(variable, key, value): void
| Name | Type |
|---|---|
variable |
string |
key |
string |
value |
number |
void
▸ setAssociativeIntArrayValue(variable, key, value): void
| Name | Type |
|---|---|
variable |
string |
key |
string |
value |
string |
void
▸ setFloat(variable, value): void
| Name | Type |
|---|---|
variable |
string |
value |
number |
void
▸ setFloatArray(variable, values): void
| Name | Type |
|---|---|
variable |
string |
values |
number[] |
void
▸ setFloatArrayValue(variable, index, value): void
| Name | Type |
|---|---|
variable |
string |
index |
number |
value |
number |
void
▸ setInt(variable, value): void
| Name | Type |
|---|---|
variable |
string |
value |
number |
void
▸ setIntArray(variable, values): void
| Name | Type |
|---|---|
variable |
string |
values |
number[] |
void
▸ setIntArrayValue(variable, index, value): void
| Name | Type |
|---|---|
variable |
string |
index |
number |
value |
number[] |
void
▸ setString(variable, value): void
| Name | Type |
|---|---|
variable |
string |
value |
string |
void
▸ signalEvent(variable): void
| Name | Type |
|---|---|
variable |
string |
void
▸ startListeningForEvent(variable, callback): number
| Name | Type |
|---|---|
variable |
string |
callback |
Promise<any> |
number
▸ stopListeningForEvent(variable, callbackID): void
| Name | Type |
|---|---|
variable |
string |
callbackID |
number |
void
▸ Static init(filenamesToPreload): Promise<Chuck>
| Name | Type |
|---|---|
filenamesToPreload |
Filename[] |
Promise<Chuck>
• new DeferredPromise()
• Readonly promise: Promise<any>
• reject: undefined | () => void
• resolve: undefined | (value?: any) => void