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 osc = ctx.createOscillator();
osc.type = 'square';
var vol = ctx.createGain();
vol.gain.value = 0.2; // 0.0 - 1.0
osc.connect(vol);
vol.connect(ctx.destination);
osc.start(0);
osc.stop(1.5);
Owner

yo-to commented Dec 28, 2013

複数のブラウザに対応する場合(1行目を下記のように記載)
window.AudioContext = window.AudioContext ||
window.webkitAudioContext || //for Chrome, Safari
window.mozAudioContext; //for Firefox
var ctx = new AudioContext();

Owner

yo-to commented Dec 29, 2013

複数のブラウザに対応する場合〜その2(3行目を下記のように記載)
osc.type = (typeof osc.type === 'string') ? 'square' : 1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment