33 lines
1.6 KiB
JavaScript
33 lines
1.6 KiB
JavaScript
// Sonneries (Web Audio, aucun fichier audio). Utilisé par la page de suivi (aperçu) et par offscreen.html (alertes).
|
|
// [fréquence Hz, durée s] ; fréquence 0 = silence.
|
|
const TTA_TONES = {
|
|
depart: [[523, .12], [784, .22]], // montée douce : le train est parti
|
|
delay10: [[660, .16], [0, .07], [660, .16]], // deux bips : retard
|
|
etd5: [[880, .11], [0, .05], [880, .11], [0, .05], [880, .11]], // trois bips vifs : pas parti à l'heure
|
|
red: [[392, .30], [0, .06], [294, .45]], // grave et long : retard important
|
|
arrive: [[784, .10], [988, .26]], // carillon léger
|
|
session: [[523, .14], [0, .05], [392, .14], [0, .05], [262, .32]], // descente : session TIS expirée
|
|
};
|
|
|
|
function ttaPlay(kind) {
|
|
try {
|
|
const seq = TTA_TONES[kind] || TTA_TONES.delay10;
|
|
const AC = globalThis.AudioContext || globalThis.webkitAudioContext;
|
|
const ctx = new AC();
|
|
let t = ctx.currentTime + 0.02;
|
|
for (const [f, d] of seq) {
|
|
if (f > 0) {
|
|
const o = ctx.createOscillator(), g = ctx.createGain();
|
|
o.type = 'triangle'; o.frequency.value = f;
|
|
g.gain.setValueAtTime(0.0001, t);
|
|
g.gain.exponentialRampToValueAtTime(0.22, t + 0.015);
|
|
g.gain.exponentialRampToValueAtTime(0.0001, t + d);
|
|
o.connect(g); g.connect(ctx.destination);
|
|
o.start(t); o.stop(t + d + 0.02);
|
|
}
|
|
t += d;
|
|
}
|
|
setTimeout(() => ctx.close(), (t - ctx.currentTime) * 1000 + 300);
|
|
} catch (e) { /* audio indisponible : on ignore */ }
|
|
}
|