Last active
December 30, 2015 14:09
-
-
Save yo-to/7840690 to your computer and use it in GitHub Desktop.
Mac用 Firefox 25.0.1 のスクラッチパッドで音を鳴らす
(矩形波、デフォルトの周波数)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
複数のブラウザに対応する場合〜その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
複数のブラウザに対応する場合(1行目を下記のように記載)
window.AudioContext = window.AudioContext ||
window.webkitAudioContext || //for Chrome, Safari
window.mozAudioContext; //for Firefox
var ctx = new AudioContext();