diff --git a/sfm/event_browser.html b/sfm/event_browser.html index 5d7a493..1ef883b 100644 --- a/sfm/event_browser.html +++ b/sfm/event_browser.html @@ -289,7 +289,12 @@ — - + + @@ -328,6 +333,29 @@ const CHANNEL_COLORS = { }; const CHANNEL_ORDER = ['MicL', 'Long', 'Vert', 'Tran']; +// Reference pressure for dB(L) — 20 µPa expressed in psi (≈ 2.9e-9 psi). +const DBL_REF = 2.9e-9; + +// User-toggleable mic display unit: 'dBL' (default, matches BW printout +// + the rest of SFM) or 'psi' (raw sample unit). +function _getMicUnit() { + return localStorage.getItem('sfm_mic_unit') === 'psi' ? 'psi' : 'dBL'; +} +function _setMicUnit(u) { + localStorage.setItem('sfm_mic_unit', u === 'psi' ? 'psi' : 'dBL'); + _refreshMicUnitToggle(); + if (currentEventId) loadEvent(currentEventId); +} +function _refreshMicUnitToggle() { + const b = document.getElementById('mic-unit-toggle'); + if (b) b.textContent = `Mic: ${_getMicUnit()}`; +} +// psi → dB(L). Null for non-positive (log undefined; Chart.js renders as a gap). +function _psiToDbl(psi) { + if (psi == null || !(psi > 0)) return null; + return 20 * Math.log10(psi / DBL_REF); +} + // Adaptive decimal formatter — scientific notation only for truly extreme // values. Normal-range peaks render as plain decimals with sensible // precision (was previously forcing toExponential(3) which produced ugly @@ -502,6 +530,19 @@ function renderMeta(data, ev) { ['Vert', ev?.vert_ppv], ['Long', ev?.long_ppv], ]; + // Mic display honors the current user preference (dBL default). + // mic_ppv is stored as raw psi on series3 events; convert when needed. + const micPsi = ev?.mic_ppv; + const micUnitDisplay = _getMicUnit(); + let micStr; + if (micPsi == null) { + micStr = '—'; + } else if (micUnitDisplay === 'dBL') { + const d = _psiToDbl(Number(micPsi)); + micStr = (d != null ? d.toFixed(1) : '—') + ' dBL'; + } else { + micStr = Number(micPsi).toExponential(2) + ' psi'; + } const statsHtml = `
| ${ch} | ${fmt(ppv)} |
| MicL | ${fmt(ev?.mic_ppv)} psi |
| MicL | ${micStr} |