|
@@ -7,6 +7,7 @@ function AudioForm(el) { |
|
|
let audioIndex = 0 |
|
|
let audioIndex = 0 |
|
|
const items = 50 |
|
|
const items = 50 |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
for (let i = 0; i < items; i += 1) { |
|
|
for (let i = 0; i < items; i += 1) { |
|
|
const newAudio = new Audio('./sfx/weapons/guns/smg-hkmp7/1_unload_var0.wav') |
|
|
const newAudio = new Audio('./sfx/weapons/guns/smg-hkmp7/1_unload_var0.wav') |
|
|
newAudio.volume = 0.2; |
|
|
newAudio.volume = 0.2; |
|
@@ -25,33 +26,61 @@ function AudioForm(el) { |
|
|
} |
|
|
} |
|
|
newAudio.load() |
|
|
newAudio.load() |
|
|
} |
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
let started = false; |
|
|
|
|
|
window.addEventListener('click', () => { |
|
|
|
|
|
if (started) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
started = true; |
|
|
|
|
|
const audioContext = new AudioContext(); |
|
|
|
|
|
|
|
|
const playSound = () => { |
|
|
|
|
|
for (let i = 0; i < items; i += 1) { |
|
|
|
|
|
if (!audioPool[i].ready) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const gain = audioContext.createGain(); |
|
|
|
|
|
gain.gain.setValueAtTime(0, audioContext.currentTime); |
|
|
|
|
|
|
|
|
audioPool[audioIndex].audio.play(); |
|
|
|
|
|
audioIndex = (audioIndex + 1) % items; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const oscillator = audioContext.createOscillator(); |
|
|
|
|
|
|
|
|
el.addEventListener('submit', (e) => { |
|
|
|
|
|
e.preventDefault() |
|
|
|
|
|
|
|
|
|
|
|
const ms = 60000 / Number(interval.value); |
|
|
|
|
|
output.innerText = `${ms} ms` |
|
|
|
|
|
if (play.checked) { |
|
|
|
|
|
intervalHandle = window.setInterval(() => { |
|
|
|
|
|
playSound() |
|
|
|
|
|
}, ms) |
|
|
|
|
|
} else { |
|
|
|
|
|
window.clearInterval(intervalHandle); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
oscillator.type = 'square'; |
|
|
|
|
|
oscillator.frequency.setValueAtTime(1000, audioContext.currentTime); |
|
|
|
|
|
oscillator.start(); |
|
|
|
|
|
|
|
|
|
|
|
oscillator.connect(gain); |
|
|
|
|
|
gain.connect(audioContext.destination); |
|
|
|
|
|
|
|
|
|
|
|
const playSound = () => { |
|
|
|
|
|
gain.gain.setValueAtTime(0.25, audioContext.currentTime); |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
gain.gain.setValueAtTime(0, audioContext.currentTime); |
|
|
|
|
|
}, 10); |
|
|
|
|
|
/* |
|
|
|
|
|
for (let i = 0; i < items; i += 1) { |
|
|
|
|
|
if (!audioPool[i].ready) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
audioPool[audioIndex].audio.play(); |
|
|
|
|
|
audioIndex = (audioIndex + 1) % items; |
|
|
|
|
|
*/ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
el.addEventListener('submit', (e) => { |
|
|
|
|
|
e.preventDefault() |
|
|
|
|
|
|
|
|
|
|
|
const ms = 60000 / Number(interval.value); |
|
|
|
|
|
output.innerText = `${ms} ms` |
|
|
|
|
|
if (play.checked) { |
|
|
|
|
|
intervalHandle = window.setInterval(() => { |
|
|
|
|
|
playSound() |
|
|
|
|
|
}, ms) |
|
|
|
|
|
} else { |
|
|
|
|
|
gain.gain.setValueAtTime(0, audioContext.currentTime); |
|
|
|
|
|
window.clearInterval(intervalHandle); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
play.checked = !play.checked |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
play.checked = !play.checked |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const audioForm = new AudioForm(window.document.getElementById('formAudio')) |
|
|
const audioForm = new AudioForm(window.document.getElementById('formAudio')) |