62 lines
2.1 KiB
JavaScript
62 lines
2.1 KiB
JavaScript
import {
|
|
computeDasMap,
|
|
createDasAnalysisPlan,
|
|
estimateDasWorkload,
|
|
} from "./das.js";
|
|
import {
|
|
computeGccPhatMap,
|
|
createGccPhatAnalysisPlan,
|
|
estimateGccPhatWorkload,
|
|
} from "./gcc-phat.js";
|
|
import {
|
|
computeMusicMap,
|
|
createMusicAnalysisPlan,
|
|
estimateMusicWorkload,
|
|
} from "./music.js";
|
|
import {
|
|
isDasAlgorithm,
|
|
requireLocalizationAlgorithmDefinition,
|
|
} from "./localization-algorithms.js";
|
|
|
|
function requestedAlgorithm(options) {
|
|
return requireLocalizationAlgorithmDefinition(
|
|
options?.experiment?.beamforming?.algorithm,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Estimate implementation-level work for whichever localization algorithm the
|
|
* experiment requests.
|
|
*/
|
|
export function estimateLocalizationWorkload(options) {
|
|
const algorithm = requestedAlgorithm(options);
|
|
if (isDasAlgorithm(algorithm.id)) return estimateDasWorkload(options);
|
|
if (algorithm.id === "gcc-phat") return estimateGccPhatWorkload(options);
|
|
if (algorithm.id === "music") return estimateMusicWorkload(options);
|
|
throw new RangeError("No workload estimator is registered for " + algorithm.id + ".");
|
|
}
|
|
|
|
/**
|
|
* Compile immutable geometry/workspace state for repeated CPU analyses.
|
|
*/
|
|
export function createLocalizationAnalysisPlan(options) {
|
|
const algorithm = requestedAlgorithm(options);
|
|
if (isDasAlgorithm(algorithm.id)) return createDasAnalysisPlan(options);
|
|
if (algorithm.id === "gcc-phat") return createGccPhatAnalysisPlan(options);
|
|
if (algorithm.id === "music") return createMusicAnalysisPlan(options);
|
|
throw new RangeError("No analysis-plan factory is registered for " + algorithm.id + ".");
|
|
}
|
|
|
|
/**
|
|
* Compute a CPU localization map using the algorithm selected by the
|
|
* experiment. The returned `algorithm` and each band's `rawScale` make the
|
|
* result semantics explicit.
|
|
*/
|
|
export async function computeLocalizationMap(options) {
|
|
const algorithm = requestedAlgorithm(options);
|
|
if (isDasAlgorithm(algorithm.id)) return computeDasMap(options);
|
|
if (algorithm.id === "gcc-phat") return computeGccPhatMap(options);
|
|
if (algorithm.id === "music") return computeMusicMap(options);
|
|
throw new RangeError("No CPU localization implementation is registered for " + algorithm.id + ".");
|
|
}
|