• Stars
    star
    190
  • Rank 203,739 (Top 5 %)
  • Language
    JavaScript
  • License
    GNU Affero Genera...
  • Created over 10 years ago
  • Updated over 10 years ago

Reviews

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

Repository Details

Generate Audio in the GPU and pipe to the Audio Card.

wavegl

Generate Audio in the GPU and stream to the Audio Card.

WebGL + Web Audio API.

JS Libraries:

Some code taken from GLSL.io.

The idea

  • We can implement a DSP function in a GLSL Fragment. A texture will package a buffer of DSPs calls.
  • The DSP signal must be encoded in a scanline direction: colors, left-right, top-bottom,
  • Then we can just use the buffer of the texture as an audio chunk: We just have to schedule this buffer with Web Audio API.
  • Then, we just do this loop again each second :-)

A 105 x 105 image is enough to code 1 second of audio (1-channel, 44100Hz, 8bit-samples). Rendering a 105x105 image each second is nothing :-)

Proof of Concept

WebGL uses GLSL language: a C-like, but with high level types and math functions.

https://www.khronos.org/registry/webgl/specs/latest/1.0/#readpixels

function readPixels (gl, width, height) {
  var pixels = new Uint8Array(width * height * 4);
  gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
  return pixels;
}

http://www.w3.org/TR/webaudio/

var audioCtx = new AudioContext();
var playTime = audioCtx.currentTime;
var bufferSource = context.createBufferSource();
bufferSource.buffer = pixels;
bufferSource.start(time);
setInterval(function schedulingLoop () {
  if (endOfTheScheduledAudioIsSoon()) {
    scheduleNext();
  }
}, 100);

See also https://github.com/gre/zampling/blob/master/src/utils/AudioChunker.js

Notes:

  • The GLSL code will have to encode the image in order that it respect the readPixels order: RGBA, left to right, top to bottom. Then we can just plug this into the Audio Card !!
  • Render one frame in the GPU is very fast.
  • a texture of 105x105 is enough to generate 1 second of sound. (44100 samples – 105x105x4)

Then we can make a wrapper to only have to implement this:

const float PI = acos(-1.0)
float dsp (float t) {
  return 0.1 * sin(2.0 * PI * t * 440); // Hello world of the audio
}

About "Functional Audio"

"Functional Audio" is a low level way to generate music, quite different from Web Audio API paradigm (modular audio).

dsp: (t: Number) => (sample: Float)

t: absolute time in seconds.

sample: value from -1.0 to 1.0. Amplitude of the sound.

This function is called 44'100 times per second!

It is:

  • Generative audio.
  • Low Level.
  • Pure Math.

The team

  • @dohzya
  • @c4m
  • @guyonvarch
  • @gre

Bootstraped in Hackday @zengularity

License

AGPLv3

Build the project

First time:

npm install

Then:

npm run build

Then open index.html.

Watch loop for development:

npm run watch

Known limitations

the main idea is to have this pipeline: GLSL (GPU) -> readPixels -> WebAudioAPI (Audio Card). No overhead of JS, pipe an Uint8Array from the GPU to the Audio Card !

The idea is a hack at the start but they could be some real potential :-)

The GLSL have limitation for such hack usage though :-D After like 2 minutes you will start notice some noise in the sound, well that is due to float imprecision (I also had to use a float in second instead of an int sample number) + there is no support for binary logic operator so we can't make ByteBeat + Latency is an issue if you want to have user interaction.

More Repositories

1

gl-react

gl-react – React library to write and compose WebGL shaders
JavaScript
2,866
star
2

react-native-view-shot

Snapshot a React Native view and save it to an image
JavaScript
2,420
star
3

gl-react-native-v2

DEPRECATED, Please migrate to latest version of gl-react-native that works nicely with expo-gl and unimodules
Java
1,937
star
4

bezier-easing

cubic-bezier implementation for your JavaScript animation easings – MIT License
JavaScript
1,660
star
5

diaporama

image/video/content slideshow engine providing high quality animation effects including Kenburns Effect and GLSL Transitions.
JavaScript
798
star
6

gl-transition-libs

libraries to run GL Transitions and source code of
JavaScript
756
star
7

illuminated.js

Illuminated.js – 2D lights and shadows rendering engine for HTML5 applications
JavaScript
421
star
8

bezier-easing-editor

Cubic Bezier Curve editor made with React & SVG
JavaScript
325
star
9

deprecated-glsl.js

NOT MAINTAINED prefer the use of http://stack.gl or gl-react – a light Javascript & GLSL library for vizualisation and game purposes (2D or 3D).
JavaScript
286
star
10

gl-react-v2

DEPRECATED =>
JavaScript
265
star
11

gl-react-image-effects

[WIP] universal image app that uses different gl-react components
JavaScript
225
star
12

deprecated-flexible-nav

NOT MAINTAINED – Improve your navigation experience - this jQuery lib improves a webpage navigation and helps to visualize different sections. of a document, an article,.. any web page.
CoffeeScript
159
star
13

gl-react-dom-v2

WebGL bindings for React to implement complex effects over images and content, in the descriptive VDOM paradigm
JavaScript
138
star
14

behind-asteroids

"Behind Asteroids, The Dark Side" is a JS13K entry for 2015 – winner in Desktop, Mobile and Community categories
JavaScript
128
star
15

diaporama-maker

[BETA] An image slideshow editor – including KenBurns effect and GLSL Transitions. (performed with diaporama)
JavaScript
99
star
16

qrloop

Encode a big binary blob to a loop of QR codes
TypeScript
90
star
17

transitions.glsl.io

WE HAVE MOVED TO
JavaScript
89
star
18

play2vim

Play framework vim plugin
Vim Script
81
star
19

playpainter

A simple Play 2 framework, Canvas and WebSocket experiment where many users can paint their draws simultaneously on a Canvas.
JavaScript
77
star
20

screenshot-webservice

UNMAINTAINED – Screenshot Webservice is an open-source REST web service to perform web page screenshots.
Scala
71
star
21

playCLI

Play Framework Iteratees + UNIX pipe library
Scala
70
star
22

kenburns

Ken Burns effect for DOM, Canvas2D, WebGL
JavaScript
66
star
23

gl-react-image

Universal gl-react Image that implements resizeMode in OpenGL
JavaScript
59
star
24

dta

Drone Tank Arena is a BattleZone-like FPS made in WebGL made during 7dfps contest.
JavaScript
59
star
25

gre

https://greweb.me/
Rust
57
star
26

zound-live

ZOUND live
JavaScript
56
star
27

ipo

easing library allowing to describe complex easings in JSON
JavaScript
55
star
28

zound

Zound, a PlayFramework 2 audio streaming experiment using Iteratees
Scala
53
star
29

multi-slider

React component for multiple values slider (allocate values)
JavaScript
49
star
30

reactjsconf2016

Example used in gl-react's talk at React.js conf 2016
JavaScript
46
star
31

json-beautify

JSON.stringify with fixed maximum character width.
JavaScript
40
star
32

gl-react-blur

Universal gl-react multi-pass gaussian Blur effect with configurable intensity
JavaScript
38
star
33

one-day-one-plot

=> now merged into https://github.com/gre/gre
Rust
37
star
34

beez

100% web real-time audio experiment using smartphones as effect controller. (tech: Android Chrome + WebRTC + Web Audio API)
JavaScript
35
star
35

deprecated-qajax

NOT MAINTAINED – this library was fun but hey, you can just use https://github.com/github/fetch now :) – Minimal Promise ajax library based on Q
JavaScript
35
star
36

glsl-transitions

OUTDATED – please migrate to gl-transitions
JavaScript
30
star
37

same-game-gravity

The Same Game Gravity Desktop version code - licence GPL v3
JavaScript
30
star
38

gl-react-dom-static-container

StaticContainer for gl-react-dom: render the Surface once, snapshot it and release the WebGL context
JavaScript
30
star
39

json2d

Express vectorial content in JSON using canvas2d directives
JavaScript
28
star
40

smoothstep

the smoothstep() function
JavaScript
26
star
41

webaudio-hooks

web audio & midi VS react hooks
JavaScript
26
star
42

glsl-transition

DEPRECATED – new project =>
JavaScript
21
star
43

zpeech

ZPeech, vowel formant analysis experiment with Web Audio API
JavaScript
21
star
44

jscrush

Minimal version of a JSCrusher to be used for js#k golf contest.
JavaScript
20
star
45

diaporama-react

Diaporama component for React
JavaScript
19
star
46

deprecated-gl-react-inspector

DEPRECATED it will be in gre/gl-react monolithic repo
JavaScript
18
star
47

js1k-starter

A convenient JS1K starter with livereload, jscrushing, multifiles support, shader minification, env code splitting
HTML
16
star
48

WebAppBuilder

Important note: I'm working on a more Makefile compliant way for WebAppBuilder (like i've done in some of my recent libs) | using Rakefile and ant are good alternatives | a lightweight Makefile to build a web app project for multiple platforms. This is a mashup of existing cool stuff like : a small template system (Mustache), SASS with Compass, Javascript minimizer, ...
JavaScript
16
star
49

react-native-webgl-view-shot

React Native WebGL extension to rasterize a view as a GL Texture.
Java
15
star
50

memocart

MEMO CART – lowrezjam 2017 – game
JavaScript
13
star
51

deprecated-qretry

UNMAINTAINED– Promise retry system for Q
JavaScript
13
star
52

timelapse

js13kgames submission - Timelapse, a psychedelic rhythm game - Web Audio API + WebGL (GLSL)
JavaScript
12
star
53

audio-notes

Note frequencies for equal-tempered scale
JavaScript
12
star
54

jardin

[STATUS: project paused. no time to maintain] gre's personal gardening data & tools
JavaScript
11
star
55

webgltexture-loader

load & cache various kind of WebGLTexture with an extensible and loosely coupled system
JavaScript
11
star
56

DEPRECATED_react-native-view-shot-example

DEPRECATED – see updated example in https://github.com/gre/react-native-view-shot (example folder)
JavaScript
11
star
57

deprecated-qimage

UNMAINTAINED no need for a lib, see https://twitter.com/greweb/status/675620261232836608 – Simple Promise Image Loader based on Q
JavaScript
10
star
58

diaporama-recorder

Client side library to record a diaporama and obtain a stream of frames
JavaScript
10
star
59

kenburns-editor

React component to edit a Kenburns effect
JavaScript
10
star
60

ibex

the entry hosted on js13k is broken, please go on ->
JavaScript
10
star
61

glsl-uniforms-editor

UNMAINTAINED – React component with inputs to edit uniforms of a GLSL shader
JavaScript
9
star
62

sliding-window

sliding-window is an unidimensional chunk allocation / free system.
JavaScript
8
star
63

glsl-transition-vignette-grid

OUTDATED – renders a grid of glsl-transition-vignette efficiently (cached + pull of WebGL canvas)
JavaScript
8
star
64

chess-game

NOT MAINTAINED – A sample Chess Game made with HTML5 and CSS3 and targeting multi plateform. (made for "HTML5 Game Most Wanted") - the game is not fully finished but illustrates some concepts explained in the book
JavaScript
8
star
65

twitbot

a Clojure twitter bot engine that uses Google Spreadsheet as a sentence database, made for educational purpose
Clojure
7
star
66

livedraw

livedraw is a real-time collaborative pen plotter stream experience (e.g. twitch)
HTML
7
star
67

gl-react-contrast-saturation-brightness

Universal gl-react which combines Contrast, Saturation and Brightness effects
JavaScript
7
star
68

HTML5-File-Uploader

Asynchronous file upload, using html5 drag and drop if supported. Example with play! framework
JavaScript
6
star
69

gl-react-hue-rotate

Universal gl-react Hue Rotate effect
JavaScript
6
star
70

zampling

a simple audio editor built with Web Audio API
JavaScript
6
star
71

playCLI-examples

Presentation slides and Examples for playCLI
Scala
6
star
72

gl-react-color-matrix

Universal gl-react effect to apply 4x4 rgba color matrix on a content
JavaScript
6
star
73

glsl-transition-examples

OUTDATED – GLSL Transition Examples
CSS
6
star
74

glsl-transition-vignette

OUTDATED – A React component which display a GLSL Transition as a vignette (with hover and click controls)
JavaScript
6
star
75

deprecated-qanimationframe

DEPRECATED just use requestAnimationFrame– Promisified requestAnimationFrame with Q
JavaScript
6
star
76

workshop-gl-react-expo

JavaScript
5
star
77

Battle-Brushes

HTML5 Canvas game - brushes try to paint the best surface on screen
JavaScript
5
star
78

same-game

a same game in HTML canvas
JavaScript
5
star
79

ld29

Anthill, a game made for LudumDare 29
JavaScript
5
star
80

glsldoc

a JSON-structured documentation of all WebGL GLSL predefined functions, constants, types, qualifiers,...
5
star
81

blazing-race

Blazing Race is a HTML5 against-the-clock platform game where you control a fireball with your mouse and you try to light candles.
JavaScript
5
star
82

ld25

Ludum Dare 25 "You are the Villain" submission - HTML5 game
JavaScript
5
star
83

deprecated-kenburns-webgl

DEPRECATED use [email protected] – Ken Burns effect – webgl implementation
JavaScript
5
star
84

backbone-extend-standalone

Standalone version of Backbone's extend
JavaScript
4
star
85

Play-completion

a bash completion for Play! Framework
4
star
86

react-json2d

JavaScript
4
star
87

morpion-solitaire

A morpion solitaire game implementation in C using ncurses.
C
4
star
88

audio-chunks

slice/append/insert/subset/copy operations on AudioBuffer linked-list chunks
JavaScript
4
star
89

shape-editor

A graphic editor in Java made for an university project.
Java
3
star
90

rect-crop

Crop a dimension in a viewport: Compute a rectangle from a zoom ratio and a center point while preserving the dimension ratio.
JavaScript
3
star
91

rect-clamp

Constraint a Rectangle into another by preserving the ratio.
JavaScript
3
star
92

bezier-easing-picker

React component which allows to pick predefined bezier curve
JavaScript
3
star
93

deprecated-kenburns-dom

DEPRECATED use [email protected] – Ken Burns effect – DOM implementation
JavaScript
3
star
94

gl-react-negative

Universal gl-react negative effect
JavaScript
3
star
95

Bee--Hornets-and-flowers

A WebWorkers and Canvas demo. You control the bee and have to consume flowers pollen and avoid hornets collision.
JavaScript
3
star
96

deprecated-kenburns-core

DEPRECATED use [email protected] – Ken Burns effect – core
JavaScript
3
star
97

rust-generative-web-setup-example

JavaScript
3
star
98

js13k-2017

AMAZ3D is a game, made in a few days for js13k 2017 gamejam.
JavaScript
3
star
99

ld41

Tetrikaruga – entry for LD41 gamejam
JavaScript
3
star
100

ld28

LudumDare 28 - You Only Get One
JavaScript
3
star