Home

Awesome

Webgl-based audio processing stream.

npm install audio-shader

var AudioShader = require('audio-shader');
var Speaker = require('audio-speaker');

//Create shader stream based on sound processing function
AudioShader(`
	vec2 mainSound( float time ){
		return vec2( sin(6.2831*880.0*time)*exp(-3.0*time) );
	}
`)

//Send generated sound to speaker
.pipe(Speaker());

API

API is fully compatible with shadertoy to copy-paste and run it’s code locally. Note that shadertoy limits output sound to 60s, whereas audio-shader runs till it is stoped.

It also might be found helpful to use glslify to get code inserted neatly:

//index.js
var Shader = require('audio-shader');
var Speaker = require('speaker');
var glslify = require('glslify');

Shader(glslify('./sound.glsl'), options?).pipe(Speaker());
//sound.glsl
vec2 mainSound( float time ){
	return vec2( sin(6.2831*440.0*time)*exp(-3.0*time) );
}

Audio-shader can also be used as a processing stream. It inherits audio-through, which is basically a transform stream, so it can be used with other node streams.

var MusicXML = require('musicxml-to-pcm');
var Processor = require('audio-shader');
var Speaker = require('speaker');

MusicXML()
.pipe(Processor(`
	vec2 main (float time) {
		//TODO test this example and document it, shadertoy is down
		return vec2();
	}
`))
.pipe(Speaker());

Related