26 lines
1.7 KiB
JavaScript
26 lines
1.7 KiB
JavaScript
/* Eager settings values; audio graphs remain in lazy feature groups. */
|
|
(function(root) {
|
|
'use strict';
|
|
const frequencies = [31,62,125,250,500,1000,2000,4000,8000,16000];
|
|
const bands = frequencies.map((f,i) => ({ f, label: f >= 1000 ? `${f/1000}k` : String(f), type: i === 0 ? 'lowshelf' : i === 9 ? 'highshelf' : 'peaking' }));
|
|
const clamp = n => Math.max(-12, Math.min(12, Number(n) || 0));
|
|
function migrate(values) {
|
|
if (!Array.isArray(values)) return frequencies.map(() => 0);
|
|
if (values.length !== 5) return frequencies.map((_,i) => clamp(values[i]));
|
|
const old = [60,250,1000,4000,12000], curve = values.map(clamp);
|
|
return frequencies.map(f => { if (f <= old[0]) return curve[0]; if (f >= old[4]) return curve[4]; const i = old.findIndex(x => x >= f), weight = Math.log(f / old[i-1]) / Math.log(old[i] / old[i-1]); return Math.round((curve[i-1] * (1-weight) + curve[i] * weight) * 10) / 10; });
|
|
}
|
|
const presets = {
|
|
flat: { name: 'Flat', g: frequencies.map(() => 0) },
|
|
bass: { name: 'Bass boost', g: [5,7,5,3,1,0,0,0,0,0] },
|
|
vocal: { name: 'Vocal clarity', g: [-3,-4,-2,0,1,2,3,4,1,0] },
|
|
acoustic: { name: 'Acoustic live', g: [-2,-1,0,-2,-1,1,2,2,1,0] },
|
|
classical: { name: 'Classical', g: migrate([4,2,-1,1,3]) },
|
|
treble: { name: 'Treble boost', g: [0,0,0,0,0,0,1,3,5,6] },
|
|
};
|
|
const width = value => Math.max(0, Math.min(100, Number(value) || 0));
|
|
const amount = value => Math.max(0, Math.min(100, Number.isFinite(Number(value)) ? Number(value) : 100));
|
|
const api = { bands, presets, migrate, width, amount };
|
|
if (typeof module !== 'undefined') module.exports = api; else root.EqParameters = api;
|
|
})(typeof window !== 'undefined' ? window : globalThis);
|