Created
April 5, 2017 05:27
-
-
Save bepitulaz/3bd623cf710b12ae1585d0443d824b04 to your computer and use it in GitHub Desktop.
Membuat suara dengan menggunakan Web Audio API
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
(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