Skip to content

Instantly share code, notes, and snippets.

@bepitulaz
Created April 5, 2017 05:27
Show Gist options
  • Save bepitulaz/3bd623cf710b12ae1585d0443d824b04 to your computer and use it in GitHub Desktop.
Save bepitulaz/3bd623cf710b12ae1585d0443d824b04 to your computer and use it in GitHub Desktop.
Membuat suara dengan menggunakan Web Audio API
(function() {
let audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// Create the oscillator
let osc1 = audioCtx.createOscillator();
let osc2 = audioCtx.createOscillator();
// Create the gain node
let gainOsc1 = audioCtx.createGain();
let gainOsc2 = audioCtx.createGain();
// Set the oscillator's parameter
osc1.type = "square";
osc2.type = "sine";
osc1.frequency.value = 30;
osc2.frequency.value = 50;
// Set the gain node's parameter
gainOsc1.gain.value = 0.1;
gainOsc2.gain.value = 0.1;
// Wiring all the nodes
osc1.connect(gainOsc1);
osc2.connect(gainOsc2);
gainOsc1.connect(audioCtx.destination);
gainOsc2.connect(audioCtx.destination);
// Start the oscillator
osc1.start();
osc2.start();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment