Pico.js is a JavaScript library for real-time audio processing that runs a browser and node.js.






process(L, R)Arguments L and R are instanceof Float32Array
pico.play(gen);Write signal into L and R in gen.process(L, R)
pico.pause();The silence come
// Generate whitenoise
var noise = {
process: function(L, R) {
for (var i = 0; i < L.length; i++) {
L[i] = R[i] = Math.random() * 0.25;
}
}
};
pico.play(noise);
pico.setup({samplerate:24000})
You can choose some one [8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000]
Put in the 'pico.swf' to in the same folder as 'pico.js'
You can install with npm.
$ npm install node-pico
See: repository demo/node-demo.js
// Generate sinetone
function sinetone(freq) {
var phase = 0,
phaseStep = freq / pico.samplerate;
return {
process: function(L, R) {
for (var i = 0; i < L.length; i++) {
L[i] = R[i] = Math.sin(6.28318 * phase) * 0.25;
phase += phaseStep;
}
}
};
}
pico.play(sinetone(880));
pico.play(gen)Start processing
pico.pause()Stop processing
pico.setup(opts)Setup samplerate and cellsize
pico.bind(PlayerClass, opts)Use another PlayerClass (for example via Flash)
pico.isPlayingReturn true if processing
pico.envReturn environment (webkit, moz, flash, nop=no operation)
pico.samplerateReturn samplerate
pico.channelsReturn channels (always return 2)
pico.cellsizeReturn length of samples to be processed
// Generate music from one-liner function
window.f1 = function(t) {
return Math.sin(t*(0.001+Math.sin(t>>10)))*64;
};
window.f2 = function(t) {
return (t>>9)&((t<<5)|(Math.sin(t*1.4142)*3000))+(t>>3);
};
function oneliner() {
var t = 0, dt = 8000 / pico.samplerate;
var dlyL = new pico.DelayNode({time:225, feedback:0.8});
var dlyR = new pico.DelayNode({time:225, feedback:0.8});
return {
process: function(L, R) {
for (var i = 0; i < L.length; i++) {
L[i] = (window.f1(t|0) % 256) / 512;
R[i] = (window.f2(t|0) % 256) / 512;
t += dt;
}
dlyL.process(L, true);
dlyR.process(R, true);
}
};
}
pico.play(oneliner());
// Demo song of MML and FM synthesis // TO MAKE THE END OF BATTLE/Ys2 // Copyright© Nihon Falcom Corporation // // Original MML Data // http://d.hatena.ne.jp/mosshm/20071013/p1 pico.play(demo());