53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
export const DEFAULT_LOCALIZATION_ALGORITHM = "das";
|
|
export const DEFAULT_PHAT_RELATIVE_FLOOR = 1e-6;
|
|
|
|
function definition(id, label, rawScale, spectralWeighting, backends) {
|
|
return Object.freeze({
|
|
id,
|
|
label,
|
|
rawScale,
|
|
spectralWeighting,
|
|
backends: Object.freeze([...backends]),
|
|
});
|
|
}
|
|
|
|
const ALGORITHM_DEFINITIONS = Object.freeze([
|
|
definition("das", "DAS", "power", "none", ["cpu", "webgpu"]),
|
|
definition("das-phat", "DAS-PHAT", "score", "phat", ["cpu", "webgpu"]),
|
|
definition("gcc-phat", "GCC-PHAT", "score", "phat", ["cpu"]),
|
|
]);
|
|
|
|
const ALGORITHM_BY_ID = new Map(
|
|
ALGORITHM_DEFINITIONS.map((algorithm) => [algorithm.id, algorithm]),
|
|
);
|
|
|
|
export const LOCALIZATION_ALGORITHM_IDS = Object.freeze(
|
|
ALGORITHM_DEFINITIONS.map((algorithm) => algorithm.id),
|
|
);
|
|
|
|
export function localizationAlgorithmDefinition(id = DEFAULT_LOCALIZATION_ALGORITHM) {
|
|
return ALGORITHM_BY_ID.get(id);
|
|
}
|
|
|
|
export function requireLocalizationAlgorithmDefinition(
|
|
id = DEFAULT_LOCALIZATION_ALGORITHM,
|
|
) {
|
|
const algorithm = localizationAlgorithmDefinition(id);
|
|
if (!algorithm) {
|
|
throw new RangeError(`unsupported localization algorithm: ${id}`);
|
|
}
|
|
return algorithm;
|
|
}
|
|
|
|
export function isDasAlgorithm(id = DEFAULT_LOCALIZATION_ALGORITHM) {
|
|
return id === "das" || id === "das-phat";
|
|
}
|
|
|
|
export function localizationAlgorithmLabel(id = DEFAULT_LOCALIZATION_ALGORITHM) {
|
|
return localizationAlgorithmDefinition(id)?.label ?? String(id);
|
|
}
|
|
|
|
export function localizationAlgorithmSupportsBackend(id, backend) {
|
|
return localizationAlgorithmDefinition(id)?.backends.includes(backend) ?? false;
|
|
}
|