Created
April 7, 2017 07:57
-
-
Save bepitulaz/de02a8625e0a3e0ebbdd689e707d09b1 to your computer and use it in GitHub Desktop.
Belajar membuat 3D sound dengan menggunakan Panner Node
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(); | |
// Create the gain node | |
let gainOsc1 = audioCtx.createGain(); | |
// Create the panner | |
let panner = audioCtx.createPanner(); | |
panner.panningModel = "HRTF"; | |
// Set the panner position. You can try different value for it. | |
panner.positionX.value = 30; | |
panner.positionY.value = -20; | |
panner.positionZ.value = 10; | |
// Set the oscillator's parameter | |
osc1.type = "square"; | |
osc1.frequency.value = 30; | |
// Set the gain node's parameter | |
gainOsc1.gain.value = 0.1; | |
// Wiring all the nodes | |
osc1.connect(panner); | |
panner.connect(gainOsc1); | |
panner.connect(audioCtx.destination); | |
// Start the oscillator | |
osc1.start(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment