load eq ui early

This commit is contained in:
ed 2022-09-08 18:47:30 +02:00
parent 0a81aba899
commit 68a9c05947

View file

@ -1908,8 +1908,7 @@ function ev_play(e) {
} }
var actx = null, var actx = null;
audio_eq = null;
function start_actx() { function start_actx() {
// bonus: speedhack for unfocused file hashing (removes 1sec delay on subtle.digest resolves) // bonus: speedhack for unfocused file hashing (removes 1sec delay on subtle.digest resolves)
@ -1933,11 +1932,8 @@ function start_actx() {
} }
} }
function create_eq() { var audio_eq = (function () {
if (audio_eq) var r = {
return start_actx();
var r = audio_eq = {
"en": false, "en": false,
"bands": [31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000], "bands": [31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000],
"gains": [4, 3, 2, 1, 0, 0, 1, 2, 3, 4], "gains": [4, 3, 2, 1, 0, 0, 1, 2, 3, 4],
@ -1948,51 +1944,59 @@ function create_eq() {
"acst": {} "acst": {}
}; };
start_actx(); if (!ACtx)
if (!actx)
ebi('audio_eq').parentNode.style.display = 'none'; ebi('audio_eq').parentNode.style.display = 'none';
// some browsers have insane high-frequency boost r.init = function () {
// (or rather the actual problem is Q but close enough) start_actx();
r.cali = (function () { if (r.cfg)
try { return;
var fi = actx.createBiquadFilter(),
freqs = new Float32Array(1),
mag = new Float32Array(1),
phase = new Float32Array(1);
freqs[0] = 14000; if (!actx)
fi.type = 'peaking'; ebi('audio_eq').parentNode.style.display = 'none';
fi.frequency.value = 18000;
fi.Q.value = 0.8;
fi.gain.value = 1;
fi.getFrequencyResponse(freqs, mag, phase);
return mag[0]; // 1.0407 good, 1.0563 bad // some browsers have insane high-frequency boost
} // (or rather the actual problem is Q but close enough)
catch (ex) { r.cali = (function () {
return 0; try {
} var fi = actx.createBiquadFilter(),
})(); freqs = new Float32Array(1),
console.log('eq cali: ' + r.cali); mag = new Float32Array(1),
phase = new Float32Array(1);
var e1 = r.cali < 1.05; freqs[0] = 14000;
fi.type = 'peaking';
fi.frequency.value = 18000;
fi.Q.value = 0.8;
fi.gain.value = 1;
fi.getFrequencyResponse(freqs, mag, phase);
var cfg = [ // hz, q, g return mag[0]; // 1.0407 good, 1.0563 bad
[31.25 * 0.88, 0, 1.4], // shelf }
[31.25 * 1.04, 0.7, 0.96], // peak catch (ex) {
[62.5, 0.7, 1], return 0;
[125, 0.8, 1], }
[250, 0.9, 1.03], })();
[500, 0.9, 1.1], console.log('eq cali: ' + r.cali);
[1000, 0.9, 1.1],
[2000, 0.9, 1.105], var e1 = r.cali < 1.05;
[4000, 0.88, 1.05],
[8000 * 1.006, 0.73, e1 ? 1.24 : 1.2], r.cfg = [ // hz, q, g
[16000 * 0.89, 0.7, e1 ? 1.26 : 1.2], // peak [31.25 * 0.88, 0, 1.4], // shelf
[16000 * 1.13, 0.82, e1 ? 1.09 : 0.75], // peak [31.25 * 1.04, 0.7, 0.96], // peak
[16000 * 1.205, 0, e1 ? 1.9 : 1.85] // shelf [62.5, 0.7, 1],
]; [125, 0.8, 1],
[250, 0.9, 1.03],
[500, 0.9, 1.1],
[1000, 0.9, 1.1],
[2000, 0.9, 1.105],
[4000, 0.88, 1.05],
[8000 * 1.006, 0.73, e1 ? 1.24 : 1.2],
[16000 * 0.89, 0.7, e1 ? 1.26 : 1.2], // peak
[16000 * 1.13, 0.82, e1 ? 1.09 : 0.75], // peak
[16000 * 1.205, 0, e1 ? 1.9 : 1.85] // shelf
];
};
try { try {
r.amp = fcfg_get('au_eq_amp', r.amp); r.amp = fcfg_get('au_eq_amp', r.amp);
@ -2033,6 +2037,7 @@ function create_eq() {
}; };
r.apply = function () { r.apply = function () {
r.init();
r.draw(); r.draw();
if (!actx) if (!actx)
@ -2066,12 +2071,12 @@ function create_eq() {
gains.push(t); gains.push(t);
gains.unshift(gains[0]); gains.unshift(gains[0]);
for (var a = 0; a < cfg.length && min != max; a++) { for (var a = 0; a < r.cfg.length && min != max; a++) {
var fi = actx.createBiquadFilter(); var fi = actx.createBiquadFilter(), c = r.cfg[a];
fi.frequency.value = cfg[a][0]; fi.frequency.value = c[0];
fi.gain.value = cfg[a][2] * gains[a]; fi.gain.value = c[2] * gains[a];
fi.Q.value = cfg[a][1]; fi.Q.value = c[1];
fi.type = a == 0 ? 'lowshelf' : a == cfg.length - 1 ? 'highshelf' : 'peaking'; fi.type = a == 0 ? 'lowshelf' : a == r.cfg.length - 1 ? 'highshelf' : 'peaking';
r.filters.push(fi); r.filters.push(fi);
} }
@ -2209,7 +2214,8 @@ function create_eq() {
bcfg_bind(r, 'en', 'au_eq', false, r.apply); bcfg_bind(r, 'en', 'au_eq', false, r.apply);
r.draw(); r.draw();
} return r;
})();
// plays the tid'th audio file on the page // plays the tid'th audio file on the page
@ -2287,7 +2293,6 @@ function play(tid, is_ev, seek) {
else else
mp.au.src = mp.au.rsrc = url; mp.au.src = mp.au.rsrc = url;
create_eq();
audio_eq.apply(); audio_eq.apply();
setTimeout(function () { setTimeout(function () {