Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Mac用 Firefox 25.0.1 のスクラッチパッドで音を鳴らす (矩形波、メロディを奏でる)
var ctx = new AudioContext();
var vol = ctx.createGain();
vol.gain.value = 0.2; // 0.0 - 1.0
vol.connect(ctx.destination);
osc_freq = new Array(0, 262, 294, 330, 349, 392, 440);
melody = new Array(
1, 2, 3, 0, 1, 2, 3, 0, 5, 3, 2, 1, 2, 3, 2, 0,
1, 2, 3, 0, 1, 2, 3, 0, 5, 3, 2, 1, 2, 3, 1, 0,
5, 5, 3, 5, 6, 6, 5, 0, 3, 3, 2, 2, 1
);
length = 0.8;
for(i=0; i<melody.length; i++) {
osc = ctx.createOscillator();
osc.type = 'square';
osc.frequency.value = osc_freq[melody[i]];
osc.connect(vol);
osc.start(i * length);
osc.stop((i + 1) * length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment