Lautheit wie im Rundfunk (EBU R128 im AudioWorklet) im Ton-Bereich; Saal-Fenster-Knopf am Handy aus, er schob Beenden aus dem Fenster

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-05 10:04:42 +01:00
co-authored by Claude Opus 5.5
parent 01a2e57952
commit 0aa4a44e4d
60 changed files with 1501 additions and 831 deletions
+27
View File
@@ -0,0 +1,27 @@
/* =====================================================================
LAUTHEIT (05.11.2026) – siehe lautheit.js
Ruhig: keine Signalflächen, nichts blinkt. Der Verlauf bewegt sich nur
über transform (scaleY je Balken).
===================================================================== */
.lt { display: grid; gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--rand, rgba(255, 255, 255, .12)); }
.lt .pult__ueber { margin: 0; }
.lt-werte { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.lt-wert { display: grid; gap: 2px; padding: 8px 10px; border-radius: 12px; background: rgba(255, 255, 255, .035); border: 1px solid var(--rand, rgba(255, 255, 255, .1)); min-width: 0; }
.lt-zahl { font-size: 1.25rem; font-variant-numeric: tabular-nums; color: var(--schrift, #e8f1fa); }
.lt-wort { font-size: .72rem; color: var(--schrift-leise, #a9a3bd); overflow-wrap: anywhere; }
.lt-urteil { margin: 0; font-size: .84rem; line-height: 1.45; color: var(--schrift, #e8f1fa); }
.lt[data-lage="leise"] .lt-urteil, .lt[data-lage="laut"] .lt-urteil { color: #f1dca0; }
.lt[data-lage="gut"] .lt-urteil { color: #9fdcb9; }
.lt-verlauf {
position: relative; display: grid; grid-template-columns: repeat(60, minmax(0, 1fr)); align-items: end; gap: 1px;
height: 56px; padding: 4px; border-radius: 10px; background: rgba(0, 0, 0, .3); border: 1px solid var(--rand, rgba(255, 255, 255, .1));
}
.lt-balken { display: block; height: 100%; transform-origin: bottom; transform: scaleY(0); background: rgba(169, 163, 189, .45); border-radius: 1px; }
.lt-balken[data-lage="gut"] { background: rgba(159, 220, 185, .7); }
.lt-balken[data-lage="leise"] { background: rgba(169, 163, 189, .55); }
.lt-balken[data-lage="laut"] { background: rgba(241, 220, 160, .8); }
/* Die Ziellinie bei −16 LUFS: (−16 + 50) / 44 der Höhe. */
.lt-ziellinie { position: absolute; left: 4px; right: 4px; bottom: calc(4px + (100% - 8px) * .7727); height: 1px; background: rgba(143, 211, 255, .55); pointer-events: none; }
.lt-unten { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
@media (pointer: coarse) { #lt-neu { min-height: 44px; } }
@media (max-width: 420px) { .lt-zahl { font-size: 1.05rem; } }
+4
View File
@@ -5,6 +5,10 @@
was das Fenster selbst braucht.
===================================================================== */
.sf-oeffnen[hidden] { display: none !important; }
/* Am Handy gibt es kein Bild-im-Bild über einem Spiel – und das Cockpit steht
dort in EINER Zeile (cockpit.css). Der Knopf schob „Beenden · halten“ aus
dem Fenster (gemessen 05.11.2026 bei 390 px). */
@media (max-width: 860px) { .sf-oeffnen { display: none !important; } }
body.sf {
/* Spalte statt Raster: Ein verborgenes Element (die Lastzeile) nimmt
keinen Platz, und nur der Chat wächst – nie das Eingabefeld. */
+171
View File
@@ -0,0 +1,171 @@
/* =====================================================================
LAUTHEIT WIE IM RUNDFUNK – der Rechenteil (05.11.2026, Neuplan C9/E7)
Läuft als AudioWorklet in einem eigenen Audiofaden: Die Seite selbst
rechnet nichts. Gemessen nach ITU-R BS.1770-4 / EBU R128:
· K-Gewichtung (Hochregal + Hochpass, Koeffizienten je Abtastrate),
· Momentan (400 ms), Kurzzeit (3 s), Integriert (Gating: absolut
−70 LUFS, relativ −10 LU),
· True Peak über vierfache Überabtastung.
Eine Tonspur mit EINEM Kanal wird als Doppel-Mono gezählt – sie kommt
beim Zuschauer auf beiden Lautsprechern an.
Der Kern ist reines Rechnen ohne Audio-Schnittstellen, damit ihn die
Prüfung in Node mit den Testsignalen aus EBU Tech 3341 füttern kann.
===================================================================== */
'use strict';
function kStufen(fs) {
/* Hochregal (Kopfeinfluss) */
let f0 = 1681.974450955533, G = 3.999843853973347, Q = 0.7071752369554196;
let K = Math.tan(Math.PI * f0 / fs);
const Vh = Math.pow(10, G / 20), Vb = Math.pow(Vh, 0.4996667741545416);
let a0 = 1 + K / Q + K * K;
const eins = {
b: [(Vh + Vb * K / Q + K * K) / a0, 2 * (K * K - Vh) / a0, (Vh - Vb * K / Q + K * K) / a0],
a: [2 * (K * K - 1) / a0, (1 - K / Q + K * K) / a0],
};
/* Hochpass (RLB) */
f0 = 38.13547087602444; Q = 0.5003270373238773;
K = Math.tan(Math.PI * f0 / fs);
a0 = 1 + K / Q + K * K;
const zwei = { b: [1, -2, 1], a: [2 * (K * K - 1) / a0, (1 - K / Q + K * K) / a0] };
return [eins, zwei];
}
/* Vierfache Überabtastung: 48 Abgriffe, Kaiser-gefensterter Sinc, je Phase
auf Verstärkung 1 normiert. */
function firBauen() {
const N = 48, L = 4, beta = 7;
const bessel = (x) => { let s = 1, t = 1; for (let k = 1; k < 30; k++) { t *= (x / (2 * k)) * (x / (2 * k)); s += t; } return s; };
const h = new Float64Array(N);
for (let n = 0; n < N; n++) {
const m = n - (N - 1) / 2;
const x = m / L;
const sinc = x === 0 ? 1 : Math.sin(Math.PI * x) / (Math.PI * x);
const r = 2 * n / (N - 1) - 1;
h[n] = sinc * bessel(beta * Math.sqrt(Math.max(0, 1 - r * r))) / bessel(beta);
}
const phasen = [];
for (let p = 0; p < L; p++) {
const c = [];
for (let n = p; n < N; n += L) c.push(h[n]);
const s = c.reduce((a, b) => a + b, 0);
phasen.push(Float64Array.from(c.map((x) => x / s)));
}
return phasen;
}
class LautheitKern {
constructor(fs) {
this.fs = fs;
this.stufen = kStufen(fs);
this.fir = firBauen();
this.teilLaenge = Math.round(fs / 10); /* 100 ms */
this.kanal = [];
this.summe = 0; this.zahl = 0; this.spitze = 0;
this.teile = []; /* Energie je 100 ms, für Momentan/Kurzzeit */
this.bloecke = []; /* Energie je 400-ms-Block, alle 100 ms – fürs Integrierte */
this.spitzeGesamt = 0;
}
zuruecksetzen() { this.bloecke = []; this.spitzeGesamt = 0; }
zustand(i) {
if (!this.kanal[i]) this.kanal[i] = { z: [[0, 0], [0, 0]], verlauf: new Float64Array(12), pos: 0 };
return this.kanal[i];
}
/* kanaele: Liste gleich langer Float32Array. Gibt fertige 100-ms-Teile zurück. */
schieben(kanaele) {
const fertig = [];
const gewicht = kanaele.length === 1 ? 2 : 1;
const n = kanaele[0]?.length || 0;
for (let j = 0; j < n; j++) {
let quadrat = 0;
for (let c = 0; c < kanaele.length; c++) {
const k = this.zustand(c);
const x = kanaele[c][j];
/* True Peak */
k.verlauf[k.pos] = x; k.pos = (k.pos + 1) % 12;
for (const ph of this.fir) {
let y = 0;
for (let t = 0; t < 12; t++) y += ph[t] * k.verlauf[(k.pos - 1 - t + 24) % 12];
const b = Math.abs(y);
if (b > this.spitze) this.spitze = b;
}
/* K-Gewichtung, zwei Biquads (Direktform II transponiert) */
let v = x;
for (let s = 0; s < 2; s++) {
const f = this.stufen[s], z = k.z[s];
const y = f.b[0] * v + z[0];
z[0] = f.b[1] * v - f.a[0] * y + z[1];
z[1] = f.b[2] * v - f.a[1] * y;
v = y;
}
quadrat += v * v;
}
this.summe += quadrat * gewicht;
this.zahl++;
if (this.zahl >= this.teilLaenge) {
const e = this.summe / this.zahl;
this.teile.push(e);
if (this.teile.length > 30) this.teile.shift();
if (this.teile.length >= 4) {
const t = this.teile;
this.bloecke.push((t[t.length - 1] + t[t.length - 2] + t[t.length - 3] + t[t.length - 4]) / 4);
if (this.bloecke.length > 216000) this.bloecke.shift(); /* 6 h */
}
if (this.spitze > this.spitzeGesamt) this.spitzeGesamt = this.spitze;
fertig.push({ e, tp: this.spitze });
this.summe = 0; this.zahl = 0; this.spitze = 0;
}
}
return fertig;
}
static lufs(e) { return e > 0 ? -0.691 + 10 * Math.log10(e) : -Infinity; }
static db(a) { return a > 0 ? 20 * Math.log10(a) : -Infinity; }
mittel(anzahl) {
const t = this.teile;
if (t.length < anzahl) return -Infinity;
let s = 0; for (let i = t.length - anzahl; i < t.length; i++) s += t[i];
return LautheitKern.lufs(s / anzahl);
}
integriert() {
const ABS = Math.pow(10, (-70 + 0.691) / 10);
let s = 0, n = 0;
for (const b of this.bloecke) if (b > ABS) { s += b; n++; }
if (!n) return -Infinity;
const rel = (s / n) * Math.pow(10, -10 / 10);
let s2 = 0, n2 = 0;
for (const b of this.bloecke) if (b > ABS && b > rel) { s2 += b; n2++; }
return n2 ? LautheitKern.lufs(s2 / n2) : -Infinity;
}
bericht() {
return {
momentan: this.mittel(4), kurz: this.mittel(30), integriert: this.integriert(),
spitze: LautheitKern.db(this.spitzeGesamt), bloecke: this.bloecke.length,
};
}
}
if (typeof registerProcessor === 'function') {
registerProcessor('lautheit', class extends AudioWorkletProcessor {
constructor() {
super();
this.kern = new LautheitKern(sampleRate);
this.port.onmessage = (ev) => { if (ev.data === 'neu') this.kern.zuruecksetzen(); };
}
process(eingaenge) {
const ein = eingaenge[0];
if (ein && ein.length && ein[0].length) {
const fertig = this.kern.schieben(ein);
if (fertig.length) {
const b = this.kern.bericht();
b.spitzeJetzt = LautheitKern.db(fertig[fertig.length - 1].tp);
this.port.postMessage(b);
}
}
return true;
}
});
} else if (typeof globalThis !== 'undefined') {
globalThis.LautheitKern = LautheitKern;
}
+131
View File
@@ -0,0 +1,131 @@
/* =====================================================================
LAUTHEIT WIE IM RUNDFUNK – die Anzeige (05.11.2026, Neuplan C9)
Im Ton-Bereich der Regie: Was gerade als Ton hinausgeht (Mikro bzw.
Mischung aus Mikro und Spiel), gemessen nach EBU R128 in einem
AudioWorklet (lautheit-worklet.js, eigener Faden). Ziel −16 LUFS, wie
es die großen Plattformen für Streams empfehlen, Spitzen unter −1 dBTP.
Dazu ein Urteil in Worten und der Verlauf der letzten 60 Sekunden.
Gemessen wird NUR, solange der Ton-Bereich offen ist – niemand soll für
eine Anzeige bezahlen, die er nicht ansieht. Der Verlauf bewegt sich
nur über `transform` (60 Balken, je ein scaleY).
===================================================================== */
(() => {
'use strict';
const ZIEL = -16, SPANNE = 3, SPITZE_MAX = -1;
const $ = (id) => document.getElementById(id);
const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; };
const KANN = !!(window.AudioContext && window.AudioWorkletNode);
/* Der Rechenteil kommt mit DEMSELBEN Stempel wie diese Datei – sonst hielte
ein Browser eine alte Fassung fest (immutable). Gelesen beim Laden:
`document.currentScript` gibt es später nicht mehr. */
const HIER = document.currentScript?.src || location.href;
const WERK = new URL(`lautheit-worklet.js${new URL(HIER).search}`, HIER).href;
let ctx = null, knoten = null, quelle = null, spur = null, still = null;
let letzter = null;
const verlauf = [];
let letzteSekunde = 0;
function bauen() {
if ($('lt')) return $('lt');
const tafel = $('tafel-ton');
if (!tafel) return null;
const s = el('section', 'lt'); s.id = 'lt';
s.setAttribute('aria-labelledby', 'lt-titel');
const h = el('h3', 'pult__ueber', 'Lautheit wie im Rundfunk'); h.id = 'lt-titel';
const werte = el('div', 'lt-werte');
const wert = (id, wort) => { const k = el('div', 'lt-wert'); const z = el('strong', 'lt-zahl', '–'); z.id = id; k.append(z, el('span', 'lt-wort', wort)); werte.append(k); };
wert('lt-kurz', 'Kurzzeit · LUFS');
wert('lt-integriert', 'seit Messbeginn · LUFS');
wert('lt-spitze', 'höchste Spitze · dBTP');
const urteil = el('p', 'lt-urteil'); urteil.id = 'lt-urteil'; urteil.setAttribute('aria-live', 'polite');
const bahn = el('div', 'lt-verlauf'); bahn.id = 'lt-verlauf'; bahn.setAttribute('aria-hidden', 'true');
const ziel = el('i', 'lt-ziellinie'); bahn.append(ziel);
for (let i = 0; i < 60; i++) bahn.append(el('span', 'lt-balken'));
const unten = el('div', 'lt-unten');
unten.append(el('span', 'pult__klein', 'Ziel −16 LUFS · Spitzen unter −1 dBTP · letzte 60 s'));
const neu = el('button', 'btn btn-klein btn-sekundaer', 'Neu messen'); neu.type = 'button'; neu.id = 'lt-neu';
neu.addEventListener('click', () => { knoten?.port.postMessage('neu'); verlauf.length = 0; letzter = null; zeichnen(); });
unten.append(neu);
s.append(h, werte, urteil, bahn, unten);
($('ton-hinweis') || $('regler'))?.after(s);
return s;
}
const zahl = (x, n = 1) => (Number.isFinite(x) ? x.toFixed(n).replace('.', ',').replace('-', '−') : '–');
function urteilSatz(b) {
if (!KANN) return 'Dieser Browser kann die Lautheit nicht messen.';
if (!spur) return 'Gerade geht kein Ton hinaus – nichts zu messen.';
if (!b) return 'Misst …';
const k = b.kurz;
let satz;
if (!Number.isFinite(k) || k < -60) satz = 'Still – kommt am Mikro oder im Spiel Ton an?';
else if (k < ZIEL - SPANNE) satz = `Zu leise – etwa ${zahl(ZIEL - k, 0)} dB lauter wäre richtig.`;
else if (k > ZIEL + SPANNE) satz = `Zu laut – etwa ${zahl(k - ZIEL, 0)} dB leiser wäre richtig.`;
else satz = 'Passt – nah am Ziel von −16 LUFS.';
if (Number.isFinite(b.spitze) && b.spitze > SPITZE_MAX) satz += ' Spitzen über −1 dBTP: Pegel etwas runter, sonst kann es beim Zuschauer verzerren.';
return satz;
}
function zeichnen() {
if (!$('lt')) return;
const b = letzter;
$('lt-kurz').textContent = zahl(b?.kurz);
$('lt-integriert').textContent = zahl(b?.integriert);
$('lt-spitze').textContent = zahl(b?.spitze);
const s = urteilSatz(b);
if ($('lt-urteil').textContent !== s) $('lt-urteil').textContent = s;
const k = b?.kurz;
$('lt').dataset.lage = !b || !Number.isFinite(k) || k < -60 ? 'still' : k < ZIEL - SPANNE ? 'leise' : k > ZIEL + SPANNE ? 'laut' : 'gut';
const balken = $('lt-verlauf').querySelectorAll('.lt-balken');
const v = verlauf.slice(-60);
balken.forEach((x, i) => {
const w = v[i - (60 - v.length)];
/* −50 LUFS = leer, −6 LUFS = voll */
const anteil = Number.isFinite(w) ? Math.max(0.02, Math.min(1, (w + 50) / 44)) : 0;
x.style.transform = `scaleY(${anteil.toFixed(3)})`;
x.dataset.lage = !Number.isFinite(w) ? '' : w > ZIEL + SPANNE ? 'laut' : w < ZIEL - SPANNE ? 'leise' : 'gut';
});
}
function sichtbar() { const t = $('tafel-ton'); return !!t && !t.hidden && t.getClientRects().length > 0; }
async function anschliessen(neu) {
abbauen(false);
spur = neu;
if (!spur || !KANN) return;
try {
if (!ctx) {
ctx = new AudioContext({ sampleRate: 48000 });
await ctx.audioWorklet.addModule(WERK);
}
if (spur !== neu) return;
quelle = ctx.createMediaStreamSource(new MediaStream([spur]));
knoten = new AudioWorkletNode(ctx, 'lautheit', { numberOfOutputs: 1, outputChannelCount: [1] });
still = ctx.createGain(); still.gain.value = 0;
quelle.connect(knoten); knoten.connect(still); still.connect(ctx.destination);
knoten.port.onmessage = (ev) => {
letzter = ev.data;
const jetzt = Math.floor(performance.now() / 1000);
if (jetzt !== letzteSekunde) { letzteSekunde = jetzt; verlauf.push(letzter.kurz); if (verlauf.length > 60) verlauf.shift(); }
};
if (ctx.state === 'suspended') ctx.resume().catch(() => {});
} catch { abbauen(true); }
}
function abbauen(ganz) {
try { quelle?.disconnect(); knoten?.disconnect(); still?.disconnect(); } catch { /* egal */ }
quelle = knoten = still = null;
if (ganz && ctx) { ctx.close().catch(() => {}); ctx = null; }
if (ganz) { spur = null; letzter = null; verlauf.length = 0; }
}
function takt() {
if (!bauen()) return;
if (!sichtbar()) { if (ctx) abbauen(true); return; }
const jetzt = window.SaalKamera?.ton?.() || null;
if (jetzt !== spur || (jetzt && !knoten)) anschliessen(jetzt);
if (ctx?.state === 'suspended') ctx.resume().catch(() => {});
zeichnen();
}
setInterval(takt, 250);
window.Lautheit = { bericht: () => letzter && { ...letzter }, verlauf: () => verlauf.slice() };
})();
+2
View File
@@ -3818,6 +3818,8 @@
Angehalten wird nur, wer weder sendet noch gerade gefragt ist. */
window.SaalKamera = {
strom: () => meinStrom,
/* Lautheit (lautheit.js): was gerade als Ton hinausgeht. */
ton: () => tonSpurJetzt(),
aus: () => {
if (binSender || !meinStrom || lage?.ich?.einladung || lage?.ich?.backstage) return false;
for (const s of meinStrom.getTracks()) { try { s.stop(); } catch { /* war aus */ } }