• Stars
    star
    196
  • Rank 198,553 (Top 4 %)
  • Language
    JavaScript
  • License
    Mozilla Public Li...
  • Created almost 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Wait-free thread-safe single-consumer single-producer ring buffer using SharedArrayBuffer

ringbuf.js

test npm

A thread-safe wait-free single-consumer single-producer ring buffer for the web, and some utilities.

The main files of this library:

  • js/ringbuf.js: base data structure, implementing the ring-buffer. This is intentionally heavily commented.
  • js/audioqueue.js: wrapper for audio data streaming, without using postMessage.
  • js/param.js: wrapper for parameter changes, allowing to send pairs of index and value without using postMessage.

Examples and use-cases

https://ringbuf-js.netlify.app/ is a deployment of the examples in this repository with a web server that answers with the right headers for this directory, and allows the example to work. More details available at Planned changes to shared memory .

Those examples work in browsers that support both the AudioWorklet, and SharedArrayBuffer.

While most real-time audio work should happen on a real-time thread (which means inside the AudioWorkletGlobaleScope on the Web), sending (resp. receiving) audio to (from) a non-real-time thread is useful:

  • Decoding a audio codecs that browsers don't support natively in a web worker, sending the PCM to an AudioWorklet (no need to fiddle with AudioBufferSourceNode, etc.)
  • Conversely, recording the output of an AudioContext using an AudioWorkletNode with a very high degree of reliability and extreme flexibility, possibly using Web Codecs or a WASM based solution for the encoding, and then sending the result to the network or storing it locally.
  • Implementing emulators for (e.g.) old consoles that only had one execution thread and did everything on the same CPU
  • Porting code that is using a push-style audio API (SDL_QueueAudio) without having to refactor everything.
  • Implement off-main-thread off-real-time-thread audio analysis (streaming the real-time audio data to a web worker, visualizing it using an OffscreenCanvas, shielding the audio processing and visualization from main thread load)

Run locally

cd public; node ../server.js

This is a simple web server that sets the right headers to use SharedArrayBuffer (see Planned changes to shared memory on MDN).

Contribute

Please do (just open an issue or send a PR).

make build

allows running the build step and copying the file to allow the example to work.

make doc

allows rebuilding the documentation.

Compatibility

This needs the SharedArrayBuffer, so a couple of HTTP headers might need to be set on the web server serving the page.

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

As of 2023-05-25, the following browsers are compatible:

  • Firefox Desktop all current versions including current ESR
  • Firefox for Android all current versions
  • Chrome Desktop and Chromium-based browsers (for a long time)
  • Chrome for Android
  • Safari

License

Mozilla Public License 2.0

More Repositories

1

litsynth

A Web Audio API synth for demoscene written in literate javascript
JavaScript
70
star
2

monome-rs

Talk to monome grid and arc devices in rust
Rust
34
star
3

up-to-eleven

Browser extension to boost the volume of a video on a web pages
JavaScript
27
star
4

jsconf.asia-15

Material to do a talk on synths with a live-coding side, possibly in Singapore
JavaScript
22
star
5

web-audio-perf

Notes for Web Audio API performance and debugging worksop
HTML
18
star
6

redverb

A convolution reverb using Juce
C++
17
star
7

metro

implementation of a robust metronome using the Web Audio API
Makefile
16
star
8

bela-sys

Rust bindings for the Bela platform
Rust
15
star
9

flv.js

An FLV demuxer in javascript
JavaScript
12
star
10

wac-19-audioworklet-workshop

Workshop material for the AudioWorklet workshop at the Web Audio Conference 2019
JavaScript
12
star
11

auto-dl

Periodically download a youtube playlist, extract audio, convert to mp3, move to directory (possibly synced using syncthing).
Rust
12
star
12

libop1

a program to generate an AIFF file for use with the op-1 drum sampler
JavaScript
10
star
13

knob.js

A tiny fader & knob library in js
JavaScript
9
star
14

nvim

My .vim directory, containing my nvim configuration
Vim Script
9
star
15

euclidian-rythms

Generate euclidian rythms using the Bjorklund's algorithm
Rust
8
star
16

musical_scales

Working with western musical scales in Rust
Rust
7
star
17

dupdup

helps you in sorting out your mess of a backup
Python
6
star
18

huit

A bitcrusher VST
C++
5
star
19

webaudio-benchmark

Benchmarks for the WebAudio API
JavaScript
5
star
20

usdp

C
5
star
21

snappy

getUserMedia + OpenWebApp + hipstagram
JavaScript
5
star
22

fx-profiler-audio-cb

JavaScript
4
star
23

mlr-rs

sample-slicing program for monome grid, written in rust
Rust
4
star
24

OGP

Shell
4
star
25

carre.js

Tiled-base game engine.
JavaScript
4
star
26

roundtrip-latency-tester

Test your round trip latency for a set of devices, in the browser
HTML
4
star
27

abop

Apache Bench Output Processor
JavaScript
3
star
28

rant.js

A comment system in node.js
JavaScript
3
star
29

fx-32-on-64.sh

A set of scripts to compile a firefox 32 bits on Ubuntu 64 bits
Shell
3
star
30

yadfig2

JavaScript
3
star
31

yadfig

Yet Another Damn Fine Image Gallery
CSS
3
star
32

loop-2017

material presented at ableton loop 2017 in berlin
CSS
3
star
33

mds

control a eurorack synth using a monome
Rust
3
star
34

XML_DTD_XSLT_Parser

Dépôt du projet 4IF : Grammaire et langage
C
2
star
35

MultimodalInteraction

Multimodal interaction project at KTH
Java
2
star
36

fdn-reverb

experiments with feedback delay network reverbs
Rust
2
star
37

.files

My dotfiles
Shell
2
star
38

wac-14-keynote

Third keynote of the WAC'14 Conference at IRCAM
JavaScript
2
star
39

reload-gcli

`reload` command for Firefox's gcli.
2
star
40

PlanningMaker

A tool to ease the planning of events at INSA de Lyon
C
2
star
41

railstraining

Learning RoR is funnier with other peoples
2
star
42

magnify.js

An automatic image magnifier in js.
JavaScript
2
star
43

canvastoy

Like shadertoy, but for 2d canvas.
JavaScript
2
star
44

mozilla-utils

Set of scripts to ease working on mozilla-central
Shell
2
star
45

cubeb-wasapi

VS2010 project aiming to easily write and test a WASAPI cubeb backend.
C
2
star
46

demojs13

F#
2
star
47

bela-utils

Various scripts and assorted things to work with bela boards and monome devices, possibly other things.
Shell
2
star
48

AudioTechnology

Audio Technology project
C++
2
star
49

web-audio-mhd14barcelona

Slides for a talk about the Web Audio API at Music Hack Day 2014 in Barcelona
2
star
50

clock-drift-plot

JavaScript
1
star
51

resume

My resume
TeX
1
star
52

jekyll-newpost

Create a new post for a Jekyll blog in seconds.
Python
1
star
53

popathon-2

Popathon #2 in Paris
JavaScript
1
star
54

audio-clock

propagate a musical clock from an audio thread to other threads
Rust
1
star
55

Carnet

A note app, built with the shiny latest tools available.
1
star
56

cult

Rust wrapper for cubeb
Rust
1
star
57

polyinteif2010

Poly d'inté IF 2010
Shell
1
star
58

zine.py

generate a simple photobook pdf
Python
1
star
59

mbms

monome bela modular sequencer
Rust
1
star
60

talk-rich-media

Slides pour une conférences sur les API media riches sur le web
CSS
1
star
61

loopa

Drum break looper
HTML
1
star
62

pancarte.js

Dynamic clickable overlays on HTML5 video
JavaScript
1
star
63

vagg

Defensive-coding helpers in C
C
1
star
64

web-audio-demojs14-paris

Slides for a talk at DemoJS 2014 in Paris
CSS
1
star
65

mhd14barcelona

monome + web audio api hack
JavaScript
1
star
66

html5demo

A quick and dirty test of HTML5
JavaScript
1
star
67

planningmaker-v1

An old php flat planning maker that was used ages ago at INSA de Lyon.
PHP
1
star
68

wac-19

Workshop and Keynote material for the Web Audio Conference 2019 in Trondheim, Norway
JavaScript
1
star
69

padenot.github.io

This website
1
star
70

wac-17-slides

HTML
1
star
71

traktorhtml2txt

Convert traktor set HTML export to text
Rust
1
star
72

chrome-tracing

chrome://tracing for rust
Rust
1
star
73

drumlab

code to create procedural drum sound
1
star