All Projects → jariseon → audioworklet-polyfill

jariseon / audioworklet-polyfill

Licence: MIT License
strictly unofficial polyfill for Web Audio API AudioWorklet

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to audioworklet-polyfill

weakmap-polyfill
ECMAScript6 WeakMap polyfill
Stars: ✭ 25 (-48.98%)
Mutual labels:  polyfill
react-native-wasm
A polyfill to use WebAssembly in React Native.
Stars: ✭ 39 (-20.41%)
Mutual labels:  polyfill
o9n
🖥 A screen.orientation ponyfill
Stars: ✭ 55 (+12.24%)
Mutual labels:  polyfill
symfony-tools
Collection of polyfill (backport) and incubator features for Symfony 3
Stars: ✭ 19 (-61.22%)
Mutual labels:  polyfill
require-polyfill
Make `require` work in browsers, at runtime. No code bundling needed!
Stars: ✭ 37 (-24.49%)
Mutual labels:  polyfill
github-wc-polyfill
Ensure that all GitHub and GitLab scripts required for UXP and SeaMonkey are loaded correctly
Stars: ✭ 87 (+77.55%)
Mutual labels:  polyfill
nikku
👽 Web-based BRSTM player
Stars: ✭ 35 (-28.57%)
Mutual labels:  web-audio-api
Array.prototype.at
An ES-spec-compliant (proposed) `Array.prototype.at`shim/polyfill/replacement that works as far down as ES3.
Stars: ✭ 20 (-59.18%)
Mutual labels:  polyfill
webpack2-polyfill-plugin
Insert polyfills (such as Promise) for Webpack 2
Stars: ✭ 18 (-63.27%)
Mutual labels:  polyfill
appHistory
A polyfill for the AppHistory proposal
Stars: ✭ 21 (-57.14%)
Mutual labels:  polyfill
Polyfill
An artifact repository to assist writing Gradle Plugins for Android build system.
Stars: ✭ 68 (+38.78%)
Mutual labels:  polyfill
react-redux-webaudio
An event manager for the Web Audio API, integrated with react-redux.
Stars: ✭ 23 (-53.06%)
Mutual labels:  web-audio-api
NetStandardPolyfills
Type and Reflection polyfill extension methods. .NET 3.5+ and .NET Standard 1.0+.
Stars: ✭ 22 (-55.1%)
Mutual labels:  polyfill
AudioMasher
Generative Audio Playground
Stars: ✭ 50 (+2.04%)
Mutual labels:  web-audio-api
async generator
Making it easy to write async iterators in Python 3.5
Stars: ✭ 87 (+77.55%)
Mutual labels:  polyfill
polyfill-php81
This component provides functions unavailable in releases prior to PHP 8.1.
Stars: ✭ 618 (+1161.22%)
Mutual labels:  polyfill
object-keys
Object.keys shim
Stars: ✭ 41 (-16.33%)
Mutual labels:  polyfill
finding-nora
Find your name in a field of letters (kids game)
Stars: ✭ 40 (-18.37%)
Mutual labels:  web-audio-api
midio
midio will work really hard to generate you endlessly interesting audio on the fly.
Stars: ✭ 21 (-57.14%)
Mutual labels:  web-audio-api
oscilloscope.js
A small javascript plugin to create an oscilloscope of an audio-context
Stars: ✭ 28 (-42.86%)
Mutual labels:  web-audio-api

audioworklet-polyfill

Strictly unofficial polyfill for Web Audio API AudioWorklet. The processor runs in a Web Worker, which is connected via SharedArrayBuffer to a main thread ScriptProcessorNode.

edit: SharedArrayBuffers (SABs) are currently disabled in Firefox and Safari due to security concerns. As a workaround, the polyfill falls back to transferable ArrayBuffers that are bounced back and forth between main thread and web worker. This requires double buffering, which increases latency. The polyfill still works reasonably well even with this, in all tested user agents. SABs will be re-enabled when available.

demos

https://webaudiomodules.org/wamsynths

Tested in stable Firefox 75.0 and Safari 12.1.2.

More info at webaudiomodules.org

usage

<script src="audioworklet.js"></script>
<script>
// audioworker.js should also reside at root
const context = new AudioContext();

// -- buflenSPN defines ScriptProcessorNode buffer length in samples
// -- default is 512. use larger values if there are audible glitches
AWPF.polyfill(context, { buflenSPN:512 }).then(() => {
  let script = document.createElement("script");
  script.src = "my-worklet.js";
  script.onload = () => {
    // that's it, then just proceed 'normally'
    // const awn = new MyAudioWorkletNode(context);
    // ...
  }
  document.head.appendChild(script);    
});
</script>

AWPF.polyfill() resolves immediately if polyfill is not required. note that polyfilled AudioWorklet inputs (if any) need to be connected as in sourceNode.connect(awn.input).

description

audioworklet.js polyfills AudioWorkletNode and creates a web worker. Worker is initialized with audioworker.js script, which in turn polyfills AudioWorkletGlobalScope and AudioWorkletProcessor. audioWorklet.addModule() is thereby routed to web worker's importScript(), and raw audio processing takes place off main thread. Processed audio is put into a SAB (or transferable ArrayBuffer when SAB is unavailable), which is accessed in main thread ScriptProcessorNode (SPN) onaudioprocess() for audio output.

caveats

Due to SPN restrictions the number of input and output ports is limited to 1, and the minimum buffer length is 256. I've also cut corners here and there, so the polyfill does not accurately follow the spec in all details. Please raise an issue if you find an offending conflict.

AudioParams are still unsupported.

similar libraries

@developit has implemented a similar polyfill that uses an isolated main thread scope for audio processing.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].