Skip to content

Instantly share code, notes, and snippets.

@yo-to
Last active December 30, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yo-to/7840690 to your computer and use it in GitHub Desktop.
Save yo-to/7840690 to your computer and use it in GitHub Desktop.
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);
@yo-to
Copy link
Author

yo-to commented Dec 28, 2013

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

@yo-to
Copy link
Author

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