Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## v1.0.8 - 2026-02-14

- Fix: AudioRenderCapacity.stop cf. #167
- Fix: More robust debug build loading
- Docs: Faust WASM examples

## v1.0.7 - 2025-11-18
## v1.0.6 - 2025-11-18

- Fix `mjs` exports
Expand Down
33 changes: 33 additions & 0 deletions examples/offline-worklet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {
AudioContext,
AudioBufferSourceNode,
AudioWorkletNode,
OfflineAudioContext,
} from '../index.mjs';

import { sleep } from '@ircam/sc-utils';

console.log('> Process 1 sec sine piped into "pass-through" worklet');

const offline = new OfflineAudioContext(2, 48000, 48000);
await offline.audioWorklet.addModule('./worklets/pass-through.js');

const osc = offline.createOscillator();
const passThrough = new AudioWorkletNode(offline, 'pass-through');

osc.connect(passThrough).connect(offline.destination);
osc.start(0);
osc.stop(1);

const buffer = await offline.startRendering();

console.log(`> Playback resulting buffer (duration: ${buffer.duration}sec)`);

const online = new AudioContext({ sampleRate: 48000 });
const src = new AudioBufferSourceNode(online, { buffer });
src.connect(online.destination);
src.start();

await sleep(1);

await online.close();
29 changes: 29 additions & 0 deletions examples/worklets/pass-through.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class PassThrough extends AudioWorkletProcessor {
// this parameter is not used, by allows to ensure that the params buffers
// recycling logic works as expected in `examples/offline-worklet.js`
// cf. https://github.com/ircam-ismm/node-web-audio-api/issues/170
static get parameterDescriptors() {
return [
{
name: "dummy",
defaultValue: 1,
minValue: 0,
maxValue: 1,
automationRate: "a-rate",
},
];
}

process(inputs, outputs) {
if (inputs[0] && inputs[0][0] && outputs[0] && outputs[0][0]) {
for (let ch = 0; ch < outputs[0].length; ch++) {
if (inputs[0][ch]) {
outputs[0][ch].set(inputs[0][ch]);
}
}
}
return true;
}
}

registerProcessor('pass-through', PassThrough);
2 changes: 1 addition & 1 deletion js/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports.propagateEvent = function propagateEvent(eventTarget, event) {
if (isFunction(eventTarget[`on${event.type}`])) {
eventTarget[`on${event.type}`](event);
}
// then distach to add event listeners
// then dispatch to `addEventListener` callbacks
eventTarget.dispatchEvent(event);
}
18 changes: 14 additions & 4 deletions src/audio_worklet_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,21 @@ fn recycle_processor(env: &Env, processor: JsObject) -> Result<()> {
let k_worklet_params_cache = env.symbol_for("node-web-audio-api:worklet-params-cache")?;
let js_params_cache = processor.get_property::<JsSymbol, JsObject>(k_worklet_params_cache)?;

let param_cache_128 = js_params_cache.get_element::<JsTypedArray>(0)?;
let _ = recycle_buffer.call1::<JsTypedArray, JsUndefined>(param_cache_128)?;
let js_params_properties = js_params_cache.get_property_names()?;
let len = js_params_properties.get_array_length()?;

let param_cache_1 = js_params_cache.get_element::<JsTypedArray>(1)?;
let _ = recycle_buffer_1.call1::<JsTypedArray, JsUndefined>(param_cache_1)?;
for i in 0..len {
let js_property_name: JsString = js_params_properties.get_element(i)?;
let utf8_str = js_property_name.into_utf8()?.into_owned()?;
let property_name = utf8_str.as_str();
let cache: JsObject = js_params_cache.get_named_property(property_name)?;

let param_cache_128 = cache.get_element::<JsTypedArray>(0)?;
let _ = recycle_buffer.call1::<JsTypedArray, JsUndefined>(param_cache_128)?;

let param_cache_1 = cache.get_element::<JsTypedArray>(1)?;
let _ = recycle_buffer_1.call1::<JsTypedArray, JsUndefined>(param_cache_1)?;
}

Ok(())
}
Expand Down
Loading