neume.js example - mouse cursor
by mohayonao
HTML
<script src="http://mohayonao.github.io/neume.js/build/neume.min.js"></script>
<button id="start">start</button>
JavaScript
var Neume = neume(new AudioContext());
var Synth = new Neume(function($) {
var out;
var x = $(mouse, { name: "x", timeConstant: 0.1 });
var y = $(mouse, { name: "y", timeConstant: 0.1 });
out = $("saw", { freq: y, mul: 0.2 });
out = $("lpf", { freq: $("tri", { freq: 3 }).madd(400, 2400), Q: x }, out);
out = $("comb", { gain: 0.25, ffGain: 0.65, fbGain: 0.25, delay: 0.2 }, out);
return out;
});
var mouse = {};
$(window).on("mousemove", function(e) {
var x = e.pageX / window.innerWidth;
var y = e.pageY / window.innerHeight;
mouse.x = linexp(x, 0, 1, 0.1, 20);
mouse.y = linexp(y, 0, 1, 220, 1760);
});
function linexp(value, inMin, inMax, outMin, outMax) {
return Math.pow(outMax / outMin, (value - inMin) / (inMax - inMin)) * outMin;
}
var synth = null;
$("#start").on("click", function() {
if (synth) {
synth.fadeOut("+0", 0.5);
synth = null;
$(this).css({ color: "black" }).text("start");
} else {
synth = new Synth().fadeIn("+0", 0.5);
$(this).css({ color: "red" }).text("stop");
}
});