PageSourceSearch

https://www.gazette.red/interactive/script/184/lib/audio-engine.js

js gazette.red collected 2026-09-29 01:34:58 UTC 1,586 bytes, 38 lines download raw bytes

1export default class AudioEngine {
2    static audioContext = new (window.AudioContext || window.webkitAudioContext)();
3    static sounds = {};
4    static lastPlaytimes = {}; // Object to keep track of the last playtimes
5    static cooldownPeriod = 1000; // Cooldown period in milliseconds (e.g., 3000ms = 3 seconds)
6
7    static async load(name, url) {
8        const response = await fetch(url);
9        const arrayBuffer = await response.arrayBuffer();
10        AudioEngine.sounds[name] = await AudioEngine.audioContext.decodeAudioData(arrayBuffer);
11    }
12
13    static play(name, volume = 0.1, loop = false) {
14        if (AudioEngine.sounds[name]) {
15            const currentTime = Date.now();
16            const lastPlaytime = AudioEngine.lastPlaytimes[name] || 0;
17
18            // Check if the current time is past the cooldown period since the last playtime
19            if (currentTime - lastPlaytime < AudioEngine.cooldownPeriod) {
20                return; // Do not play the sound if we're within the cooldown period
21            }
22
23            const source = AudioEngine.audioContext.createBufferSource();
24            const gainNode = AudioEngine.audioContext.createGain();
25
26            source.buffer = AudioEngine.sounds[name];
27            gainNode.gain.value = volume;
28            source.loop = loop;
29
30            source.connect(gainNode);
31            gainNode.connect(AudioEngine.audioContext.destination);
32
33            source.start();
34            AudioEngine.lastPlaytimes[name] = currentTime; // Update the last playtime for this sound
35            return source;
36        }
37    }
38}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.