Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
@soundtouchjs/audio-worklet
Advanced tools
An ES2015+ AudioWorklet implementation of the SoundTouchJS library
The SoundTouchNode is an extension of the Web Audio API AudioWorkletNode. It works in conjunction with the SoundTouchWorklet, the AudioWorkletProcessor that processes the audio from the buffer. You must have the worklet registered in your code prior to utilizing the node. The node is represented as a true AudioNode.
AudioWorklets are currently only available in Chrome, MS Edge, and Electron (with hacks). We use RollupJS and Babel to compile all of our dependencies.
The SoundTouchNode is compiled using the @babel/plugin-external-helpers plugin, so you'll have to manually include the 'helpers'. If you're bundling SoundTouchNode into your application, with Babel, this may happen automagically (I haven't tested that).
The SoundTouchWorklet runs in it's own context, off the main thread. As such, the Babel runtime is bundled with the other worklet dependencies. All of the necessary SoundTouch bits are precompiled into the worklet, and the SoundTouchNode controls their properties. Adding worklets/webworkers to your application can be tricky. Read the documentation below for more information.
The worklet must first be registered with the audio context, prior to
creating an instance of your SoundTouchNode, and is compiled and included in this package (/dist/soundtouch-worklet.js
). According to new browser
security bits, you must have some form of user interaction prior to
creating your AudioContext. The following is a setupContext()
method
called from the 'loadSource()' method
const setupContext = function () {
audioCtx = new AudioContext();
return audioCtx.audioWorklet
.addModule('./js/soundtouch-worklet.js')
.catch((err) => console.log(err));
};
The AudioContext audioWorklet.addModule() method returns a Promise. The path
passed to this method is the path to the SoundTouchWorklet, available
from the build dist/soundtouch-worklet.js
. Pathing to this file is
important, and your server must include a 'Content-Type' header of
text/javascript
or application/javascript
for the file to
run properly.
[NOTE]: If you are using a bundler (webpack, rollup, etc) to bundle your app, you may require a special 'loader' for worklets/ web workers.
Once you have setup your worklet, and retrieved your raw (undecoded) file for processing, you can now setup your SoundTouchNode.
//top of the file
import { SoundTouchNode } from 'soundtouchjs';
//... and later
// called from our `loadSource()` method, after we've retrieved the
// raw audio data
const setupSoundtouch = function () {
if (soundtouch) {
soundtouch.off();
}
soundtouch = new SoundTouchNode(audioCtx, buffer);
soundtouch.on('initialized', onInitialized);
};
You must connect the SoundTouchNode with the AudioBufferSourceNode, so that audio will move from the AudioBuffer through the AudioWorkletNode and, by extension, through the AudioWorkletProcessor. You do this by calling the connectToBuffer()
method of the SoundTouchNode, which returns the AudioBufferSourceNode object. This means that additional audio processing happens by chaining additional AudioNodes, passing audio from the SoundTouchNode on to the next node in the chain, until you finally connect the AudioContext AudioDestintionNode. You can see this in our example by looking at it's play()
method.
const play = function () {
if (is_ready) {
bufferNode = soundtouch.connectToBuffer();
gainNode = audioCtx.createGain();
soundtouch.connect(gainNode);
gainNode.connect(audioCtx.destination);
// ...
}
};
This also means that, when pausing or stopping audio, you must disconnect all AudioNodes as well. You can see this in our example by looking at it's pause()
method.
const pause = function (stop = false, override = false) {
if (bufferNode) {
gainNode.disconnect();
soundtouch.disconnect();
soundtouch.disconnectFromBuffer();
// ...
}
};
The SoundTouchNode provides several 'events' that your interface may require:
Three methods are provided for controlling that 'playHead' of your audio
[Note]: 'stop()' does not fire the 'end' event, and will require you to setup new AudioContext, worklet, and SoundTouchNode instances to start audio again.
There are several properties you can set to control the SoundTouchWorklet, effecting the playback.
You also have several other read-only properties available
(There are other read-only properties, but they are derived values, and shouldn't be accessed externally when the Node is 'playing' as latency may effect the values given)
Due to the Stretch and Rate Transposition features of SoundTouch, as well as the nature of AudioWorklets, it is currently necessary to maintain copies of the AudioBuffer in both the browser's main process thread as well as in the AudioWorkletGlobalScope (where the processor processes). This may change in the future, once the SharedArrayBuffer gains complete adoption in other browsers, but for now it's necessary, and you should be aware of the overhead it creates.
FAQs
An ES2015+ AudioWorklet implementation of the SoundTouchJS library
The npm package @soundtouchjs/audio-worklet receives a total of 32 weekly downloads. As such, @soundtouchjs/audio-worklet popularity was classified as not popular.
We found that @soundtouchjs/audio-worklet demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.