work.suroh.tk/js/audio.js

24 lines
588 B
JavaScript

// audio for events
// AUDIO SETUP
const audioEngine = new (window.AudioContext || window.webkitAudioContext)()
audioEngine.suspend()
const masterGain = audioEngine.createGain()
const audioEl = document.querySelector('#audioToggle')
masterGain.gain.value = 0.9
masterGain.connect(audioEngine.destination)
// window.onload = function() {
// // create gain
// }
const audioToggle = () => {
audioEl.classList.toggle('active');
if (audioEngine.state == 'suspended') {
audioEngine.resume()
} else {
audioEngine.suspend()
}
}
audioEl.addEventListener('click', audioToggle)