public
Created

crazy loop synth

  • Download Gist
loopy_synth.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
var asynth = require('../');
var jynth = require('jynth');
 
var synth = jynth();
 
var recording = true;
var playing = true;
var samples = [];
 
process.stdin.setRawMode(true);
process.stdin.on('data', function (buf) {
if (buf[0] === 3) process.exit();
if (buf[0] === ' '.charCodeAt(0)) {
recording = !recording;
console.log('recording ' + recording);
if (recording) samples = [];
}
if (buf[0] === 'p'.charCodeAt(0)) {
playing = !playing;
console.log('playing ' + playing);
}
});
process.stdin.resume();
 
var notes = {};
 
var s = asynth(function (note, t) {
var freq = 440 * Math.pow(2, (note.key - 49) / 12);
if (!notes[note.key]) {
notes[note.key] = true;
setTimeout(function () {
notes[note.key] = false;
}, 8000);
samples.splice(0);
}
var x = synth(t)
.sine(0.1, freq)
.amod(freq/200,freq/100,3)
.sample
;
var y = synth(t)
.sine(1, freq)
.sample
;
var value = x + y;
if (recording) samples.push(value);
if (samples.length > 44000 * 16) samples.splice(0, 44000);
return value;
});
 
s.push(function (t, i) {
if (!playing) return 0;
return samples[i % samples.length];
});
 
s.play();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.