From e043358a4a827c8a82454326f68289dc46a0090a Mon Sep 17 00:00:00 2001 From: Geraint Date: Sun, 9 Feb 2025 09:06:05 +0000 Subject: [PATCH] Reorganise, add README for web release --- web/{ => demo}/Scope.mjs | 0 web/{demo.html => demo/index.html} | 77 +++++++++++++++++++++-------- web/{ => demo}/loop.mp3 | Bin web/release/README.md | 46 +++++++++++++++++ web/release/package.json | 48 +++++++++--------- 5 files changed, 127 insertions(+), 44 deletions(-) rename web/{ => demo}/Scope.mjs (100%) rename web/{demo.html => demo/index.html} (71%) rename web/{ => demo}/loop.mp3 (100%) create mode 100644 web/release/README.md diff --git a/web/Scope.mjs b/web/demo/Scope.mjs similarity index 100% rename from web/Scope.mjs rename to web/demo/Scope.mjs diff --git a/web/demo.html b/web/demo/index.html similarity index 71% rename from web/demo.html rename to web/demo/index.html index 157d471..1328517 100644 --- a/web/demo.html +++ b/web/demo/index.html @@ -2,6 +2,7 @@ Signalsmith Stretch Web Audio demo + +
- - - - + + - - + + +
diff --git a/web/loop.mp3 b/web/demo/loop.mp3 similarity index 100% rename from web/loop.mp3 rename to web/demo/loop.mp3 diff --git a/web/release/README.md b/web/release/README.md new file mode 100644 index 0000000..5477994 --- /dev/null +++ b/web/release/README.md @@ -0,0 +1,46 @@ +# Signalsmith Stretch Web + +This is an official release of the Signalsmith Stretch library for Web Audio, using WASM/AudioWorklet. It includes both plain `.js` (UMD), and ES6 `.mjs` versions. + +## How to use it + +Call `SignalsmithStretch(audioContext, ?channelOptions)` from the main thread. This returns a Promise which resolves to an `AudioNode`, with extra methods attached to it. + +It can operate either on live/streaming input, or on a sample buffer you load into it. + +### `stretch.inputTime` + +The current input time, within the sample buffer. You can change how often this is updated, with an optional callback function, using `stretch.setUpdateInterval(seconds, ?callback)`. + +### `stretch.schedule({...})` + +This adds a scheduled change, removing any scheduled changes occuring after this one. The object properties are: + +* `output` (seconds): audio context time for this change. The node compensates for its own latency, but this means you might want to schedule some things ahead of time, otherwise you'll have a softer transition as it catches up. +* `active` (bool): processing audio +* `input` (seconds): position in input buffer +* `rate` (number): playback rate, e.g. 0.5 == half speed +* `semitones` (number): pitch shift +* `loopStart` / `loopEnd`: sets a section of the input to auto-loop. Disabled if both are set to the same value. + +### `stretch.start(?when)` / `stretch.stop(?when)` + +Starts/stops playback or processing, immediately or at some future time. These are convenience methods which call `.schedule(...)` under the hood. + +`.start()` actually has more parameters, presenting a similar interface to [AudioBufferSourceNode](https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/start). + +### `stretch.addBuffers([...])` + +This adds buffers to the end of the current input. Buffers should be typed arrays of equal length, one per channel. + +It can be called multiple times, and the new buffers are inserted after the existing ones, which lets you start playback before the entire audio is loaded. It returns (as a Promise) the new end time for the stored input, in seconds. + +### `stretch.dropBuffers()` + +This drops all input buffers, and resets the input buffer start time to 0. + +### `stretch.dropBuffers(toSeconds)` + +This drops all input buffers before the given time. It returns (as a Promise) the an object with the current input buffer extent: `{start: ..., end: ...}`. + +This can be useful when processing streams or very long audio files, letting the Stretch node release old buffers once that section of the input will no longer be played back. diff --git a/web/release/package.json b/web/release/package.json index 8effb75..f92fbf5 100644 --- a/web/release/package.json +++ b/web/release/package.json @@ -1,26 +1,26 @@ { - "name": "signalsmith-stretch", - "version": "1.0.0", - "description": "JS/WASM release of the Signalsmith Stretch library", - "main": "SignalsmithStretch.mjs", - "exports": { - "import": "./SignalsmithStretch.mjs", - "require": "./SignalsmithStretch.js" - }, - "type": "module", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "https://signalsmith-audio.co.uk/code/stretch.git" - }, - "keywords": [ - "audio", - "pitch", - "time", - "web-audio" - ], - "author": "Geraint Luff", - "license": "MIT" + "name": "signalsmith-stretch", + "version": "1.1.1", + "description": "JS/WASM release of the Signalsmith Stretch library", + "main": "SignalsmithStretch.mjs", + "exports": { + "import": "./SignalsmithStretch.mjs", + "require": "./SignalsmithStretch.js" + }, + "type": "module", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://signalsmith-audio.co.uk/code/stretch.git" + }, + "keywords": [ + "audio", + "pitch", + "time", + "web-audio" + ], + "author": "Geraint Luff", + "license": "MIT" }