feat: add independent full-band activity workflow

This commit is contained in:
2026-08-29 13:56:09 +09:00
parent 3ebc0f84e0
commit 51e346a477
8 changed files with 2176 additions and 50 deletions
+12
View File
@@ -191,6 +191,17 @@ export function createCameraAssetRuntime(onChange = () => {}) {
return statuses(scene).filter((status) => !status.ready).map(({ descriptor }) => descriptor.id);
}
function missingAudioAssetIds(scene) {
const audioIds = audioAssetIds(scene);
return statuses(scene)
.filter(
(status) =>
audioIds.has(status.descriptor.id) &&
!status.ready,
)
.map(({ descriptor }) => descriptor.id);
}
async function decodeAudioAssets(scene, signal, onProgress = () => {}) {
const ids = [...audioAssetIds(scene)];
const entries = [...scene.sources, ...(scene.ambient ?? [])];
@@ -248,6 +259,7 @@ export function createCameraAssetRuntime(onChange = () => {}) {
return imageElement;
},
missingAssetIds,
missingAudioAssetIds,
reset,
statuses,
transferListForAudio,
+42
View File
@@ -109,6 +109,48 @@
<div class="band-editor-list" id="band-list"></div>
</div>
<details class="activity-monitor utility-details" id="activity-monitor">
<summary><span>전 대역 활동 검사</span><small>위치추정과 분리 · ADC spectrum</small></summary>
<div class="activity-monitor__body">
<p class="activity-monitor__copy">Scene은 물리 마이크 신호 합성에만 사용하며 음원 위치·주파수·개수 정답은 검출기에 전달하지 않습니다. 위치추정과 독립적으로 ADC의 0…Fs/2만 관측하므로 analog alias order는 사용자가 지정해야 합니다.</p>
<div class="activity-field-grid">
<label class="field"><span>검출 알고리즘</span><select id="activity-algorithm"><option value="os-cfar">OS-CFAR</option><option value="ca-cfar">CA-CFAR</option><option value="dixon-spectral-flux">Dixon spectral flux</option></select></label>
<label class="field"><span>기준 마이크</span><select id="activity-microphone" disabled><option value="">마이크를 불러오세요</option></select></label>
</div>
<div class="activity-option-grid" id="activity-cfar-options">
<label class="field"><span>Nominal Pfa / tested CUT</span><input id="activity-pfa" type="number" min="0.000000001" max="0.999999999" step="0.001" value="0.001" /></label>
<label class="field"><span>Training cells / side</span><input id="activity-training" type="number" min="1" step="1" value="8" /></label>
<label class="field"><span>Guard cells / side</span><input id="activity-guard" type="number" min="0" step="1" value="2" /></label>
<label class="field"><span>OS rank k</span><input id="activity-rank" type="number" min="1" step="1" value="12" /></label>
</div>
<div class="activity-option-grid" id="activity-flux-options" hidden>
<label class="activity-checkbox field--wide"><input id="activity-peak-picker-enabled" type="checkbox" /><span>Böck–Krebs–Schedl causal peak picker 사용</span></label>
<label class="field"><span>Threshold δ</span><input id="activity-delta" type="number" min="0" step="0.01" placeholder="사용자 보정값" /></label>
<label class="field"><span>Pre-max frames</span><input id="activity-pre-max" type="number" min="0" step="1" value="3" /></label>
<label class="field"><span>Pre-mean frames</span><input id="activity-pre-mean" type="number" min="0" step="1" value="8" /></label>
<label class="field"><span>Refractory frames</span><input id="activity-refractory" type="number" min="0" step="1" value="3" /></label>
</div>
<p class="activity-monitor__note activity-monitor__note--cfar">OS/CA의 Pfa는 IID exponential 배경 모델에서 tested CUT 하나당 정한 nominal false-alarm 값입니다. 위치 확률·신뢰도·실측 보정값이 아닙니다.</p>
<p class="activity-monitor__note activity-monitor__note--flux">Spectral flux는 onset novelty이며 지속 activity가 아닙니다. δ는 사용자가 데이터에 맞춰 정하는 보정값입니다.</p>
<div class="activity-actions">
<button class="button button--primary" id="activity-run-button" type="button">전 대역 검사</button>
<button class="button button--ghost" id="activity-export-button" type="button" disabled>Activity JSON</button>
</div>
<p class="activity-status" id="activity-status" role="status" aria-live="polite">검사할 입력과 기준 마이크를 준비하세요.</p>
<label class="activity-frame-control">
<span id="activity-frame-label">Frame 0 / 0</span>
<input id="activity-frame" type="range" min="0" max="0" step="1" value="0" disabled />
</label>
<div class="activity-result-list" id="activity-result-list" role="list" aria-label="전 대역 활동 검사 결과" aria-live="polite">
<p class="activity-result-empty">검사 후 선택 frame의 원시 검출 통계와 candidate band를 표시합니다.</p>
</div>
</div>
</details>
<details class="advanced-settings" id="advanced-settings">
<summary><span>고급 설정</span><small>음향 · 범위 · STFT · 식별자</small></summary>
<div class="advanced-settings__body">
File diff suppressed because it is too large Load Diff
+227 -1
View File
@@ -5,6 +5,11 @@ import { localizationAlgorithmSupportsBackend } from "/packages/acoustics-core/l
import { computeLocalizationWithBackend } from "/packages/webgpu-kernels/compute.js";
import { isMusicUnavailableError } from "/packages/acoustics-core/music.js";
import { getCompleteFrameCount } from "/packages/acoustics-core/stft.js";
import { analyzeCfarActivity } from "/packages/acoustics-core/activity-monitor.js";
import {
computeDixonSpectralFlux,
pickCausalSpectralFluxPeaks,
} from "/packages/acoustics-core/spectral-flux.js";
function post(type, jobId, payload = {}, transfer = []) {
self.postMessage({ type, jobId, ...payload }, transfer);
@@ -50,6 +55,219 @@ function collectBandTransfers(run, transfer) {
}
}
function collectTypedArrayTransfers(value, transfer, seen = new Set(), buffers = new Set()) {
if (value === null || typeof value !== "object" || seen.has(value)) return;
seen.add(value);
if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
if (!buffers.has(value.buffer)) {
buffers.add(value.buffer);
transfer.push(value.buffer);
}
return;
}
if (Array.isArray(value)) {
for (const item of value) collectTypedArrayTransfers(item, transfer, seen, buffers);
return;
}
for (const item of Object.values(value)) {
collectTypedArrayTransfers(item, transfer, seen, buffers);
}
}
function activitySignalStats(synthesis, scene) {
const channel = synthesis.channels[0];
let selectedChannelPeak = 0;
for (const sample of channel) {
selectedChannelPeak = Math.max(selectedChannelPeak, Math.abs(sample));
}
const workingSetWithoutSourceIdentity = {
model: synthesis.workingSet.model,
channelBytes: synthesis.workingSet.channelBytes,
maximumTransientBytes: synthesis.workingSet.maximumTransientBytes,
maximumTransientScope: synthesis.workingSet.maximumTransientScope,
pathSummary: synthesis.workingSet.pathSummary,
summaryPathPairEvaluations:
synthesis.workingSet.summaryPathPairEvaluations,
synthesisPathBuildPairEvaluations:
synthesis.workingSet.synthesisPathBuildPairEvaluations,
retainedPathObjects: synthesis.workingSet.retainedPathObjects,
remainingNonToneTransformModel:
synthesis.workingSet.remainingNonToneTransformModel,
};
const windowingWithoutSourceTruth = {
model: synthesis.windowing.model,
renderStartSample: synthesis.windowing.renderStartSample,
outputStartSample: synthesis.windowing.outputStartSample,
outputSampleCount: synthesis.windowing.outputSampleCount,
preRollSamples: synthesis.windowing.preRollSamples,
renderMaximumPropagationDelaySeconds:
synthesis.windowing.renderMaximumPropagationDelaySeconds,
activePathMaximumDelaySeconds:
synthesis.windowing.activePathMaximumDelaySeconds,
requestedMaximumPropagationDelaySeconds:
synthesis.windowing.requestedMaximumPropagationDelaySeconds,
geometryModel: synthesis.windowing.geometryModel,
sourcePositionSampleTime: synthesis.windowing.sourcePositionSampleTime,
dopplerMode: synthesis.windowing.dopplerMode,
delayedTailPolicy: synthesis.windowing.delayedTailPolicy,
arrivalOverlapModel: synthesis.windowing.arrivalOverlapModel,
};
const peakNormalization = scene.mix?.normalization === "peak";
return {
preNormalizationPeak: synthesis.preNormalizationPeak,
appliedScale: synthesis.appliedScale,
clippedSampleCount: synthesis.clippedSampleCount,
selectedChannelPeak,
acousticModel: synthesis.acousticModel,
acousticPathCount: synthesis.acousticPathCount,
acousticPathCounts: synthesis.acousticPathCounts,
workingSet: workingSetWithoutSourceIdentity,
windowing: windowingWithoutSourceTruth,
preprocessing: {
configuredNormalization: scene.mix?.normalization ?? "none",
normalizationScope: peakNormalization
? "selected-physical-microphone-whole-render"
: "none",
futureDependentNormalization: peakNormalization,
detectorCausalAfterPreprocessing: true,
endToEndCausal: !peakNormalization,
},
samplingModel: "ideal-real-sampler-no-antialias-filter",
sampleRate: synthesis.sampleRate,
nyquistHz: synthesis.sampleRate / 2,
explicitSceneSourceIdentitiesAndArrivalsIncluded: false,
sourceDerivedAggregatePhysicalAuditIncluded: true,
};
}
async function runActivity({
jobId,
scene,
arrayDefinition,
experiment,
assetBuffers,
activityConfig,
}) {
if (!activityConfig || typeof activityConfig !== "object") {
throw new TypeError("activityConfig must be an object.");
}
const channelIndex = activityConfig.channelIndex;
if (
!Number.isInteger(channelIndex) ||
channelIndex < 0 ||
channelIndex >= arrayDefinition.microphones.length
) {
throw new RangeError("activityConfig.channelIndex is outside the microphone array.");
}
const microphone = arrayDefinition.microphones[channelIndex];
const totalStartedAt = performance.now();
post("progress", jobId, {
stage: "activity-signal",
message: "전 대역 감시용 마이크 수신 신호를 합성하고 있습니다…",
});
const signalStartedAt = performance.now();
const selectedMicrophoneArray = {
...arrayDefinition,
microphones: [microphone],
};
const synthesis = synthesizeMicrophoneSignals({
scene,
arrayDefinition: selectedMicrophoneArray,
assetBuffers,
minimumDistance: experiment.beamforming.minimumDistance,
});
const signalGeneration = performance.now() - signalStartedAt;
const samples = synthesis.channels[0];
const detectorStartedAt = performance.now();
let analysis;
let peakPicking = null;
if (
activityConfig.algorithm === "ca-cfar" ||
activityConfig.algorithm === "os-cfar"
) {
analysis = await analyzeCfarActivity({
samples,
sampleRate: synthesis.sampleRate,
fftSize: experiment.stft.fftSize,
hopSize: experiment.stft.hopSize,
window: experiment.stft.window,
channelId: microphone.id,
detector: activityConfig.algorithm,
trainingCellsPerSide: activityConfig.trainingCellsPerSide,
guardCellsPerSide: activityConfig.guardCellsPerSide,
nominalFalseAlarmProbability:
activityConfig.nominalFalseAlarmProbability,
...(activityConfig.algorithm === "os-cfar"
? { rank: activityConfig.rank }
: {}),
onProgress: (progress) => post("progress", jobId, {
stage: progress.stage,
progress,
}),
});
} else if (activityConfig.algorithm === "dixon-spectral-flux") {
post("progress", jobId, {
stage: "activity-spectral-flux",
message: "Dixon spectral flux 원시 onset novelty를 계산하고 있습니다…",
});
analysis = computeDixonSpectralFlux({
samples,
sampleRate: synthesis.sampleRate,
fftSize: experiment.stft.fftSize,
hopSize: experiment.stft.hopSize,
channelId: microphone.id,
maximumOutputBytes: activityConfig.maximumOutputBytes,
});
if (activityConfig.peakPicker) {
peakPicking = pickCausalSpectralFluxPeaks(
analysis.rawOdf,
activityConfig.peakPicker,
);
}
} else {
throw new RangeError(
'activityConfig.algorithm must be "ca-cfar", "os-cfar", or "dixon-spectral-flux".',
);
}
const detectorTime = performance.now() - detectorStartedAt;
const report = {
kind: "micarrsim.activity-worker-report/1",
algorithm: activityConfig.algorithm,
channel: {
index: channelIndex,
id: microphone.id,
position: [...microphone.position],
selection: "user-selected-single-physical-microphone",
microphoneFusion: "none",
},
input: {
sampleRate: synthesis.sampleRate,
sampleCount: samples.length,
fftSize: experiment.stft.fftSize,
hopSize: experiment.stft.hopSize,
experimentWindow: experiment.stft.window,
adcRangeHz: [0, synthesis.sampleRate / 2],
analogAliasOrderResolved: false,
sceneSourceTruthUsedByPhysicalSimulator: true,
sceneSourceTruthPassedToDetector: false,
synthesizedMicrophoneCount: 1,
},
signalStats: activitySignalStats(synthesis, scene),
analysis,
...(peakPicking ? { peakPicking } : {}),
timingMs: {
total: performance.now() - totalStartedAt,
signalGeneration,
detector: detectorTime,
},
};
const transfer = [];
collectTypedArrayTransfers(report, transfer);
post("activity-result", jobId, { activityReport: report }, transfer);
}
async function computeLocalizationOrUnavailable(options) {
try {
return await computeLocalizationWithBackend(options);
@@ -255,10 +473,18 @@ async function runTimeline({ jobId, scene, arrayDefinition, experiment, assetBuf
}
self.addEventListener("message", async (event) => {
if (event.data?.type !== "run" && event.data?.type !== "run-timeline") return;
if (
event.data?.type !== "run" &&
event.data?.type !== "run-timeline" &&
event.data?.type !== "detect-activity"
) return;
const { jobId, scene, arrayDefinition, experiment, assetBuffers } = event.data;
const totalStartedAt = performance.now();
try {
if (event.data.type === "detect-activity") {
await runActivity(event.data);
return;
}
if (event.data.type === "run-timeline") {
await runTimeline(event.data);
return;
+202 -2
View File
@@ -300,6 +300,193 @@
.band-editor input[type="color"] { padding: 3px; }
.band-editor__remove { border: 0; border-radius: 7px; color: var(--danger); background: rgb(255 123 115 / 8%); cursor: pointer; }
.activity-monitor__body {
display: grid;
min-width: 0;
gap: 9px;
padding: 10px;
border-top: 1px solid var(--line);
}
.activity-monitor__copy,
.activity-monitor__note,
.activity-status,
.activity-result-empty {
margin: 0;
overflow-wrap: anywhere;
font-size: .6rem;
line-height: 1.5;
}
.activity-monitor__copy { color: var(--muted); }
.activity-field-grid,
.activity-option-grid,
.activity-actions {
display: grid;
min-width: 0;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
}
.activity-option-grid {
padding: 9px;
border: 1px solid var(--line);
border-radius: 9px;
background: #0b1714;
}
.activity-option-grid[hidden] { display: none; }
.activity-checkbox {
display: flex;
min-width: 0;
align-items: center;
gap: 7px;
color: var(--muted);
cursor: pointer;
font-size: .61rem;
font-weight: 650;
}
.activity-checkbox input {
width: 16px;
height: 16px;
flex: 0 0 auto;
margin: 0;
accent-color: var(--mint);
}
.activity-monitor__note {
padding: 8px 9px;
border-left: 2px solid rgb(88 199 232 / 45%);
border-radius: 0 7px 7px 0;
color: var(--muted);
background: rgb(88 199 232 / 4%);
}
.activity-actions { margin-top: 1px; }
.activity-status {
min-width: 0;
padding: 7px 8px;
border-radius: 7px;
color: var(--muted);
background: #0b1714;
}
.activity-frame-control {
display: grid;
min-width: 0;
gap: 5px;
color: var(--muted);
font-size: .59rem;
font-weight: 650;
}
.activity-frame-control input { width: 100%; min-width: 0; accent-color: var(--cyan); }
.activity-result-list {
display: grid;
overflow-y: auto;
min-width: 0;
min-height: 140px;
max-height: min(52vh, 520px);
gap: 6px;
padding: 8px;
border: 1px solid var(--line);
border-radius: 8px;
background: #07110f;
overscroll-behavior: contain;
scrollbar-width: thin;
resize: vertical;
}
.activity-result-empty { color: var(--muted); text-align: center; }
.activity-result-item {
min-width: 0;
padding: 7px 8px;
border: 1px solid var(--line);
border-radius: 7px;
background: #0b1714;
overflow-wrap: anywhere;
}
.activity-message,
.activity-caveat,
.activity-frame-summary,
.activity-empty,
.activity-event-selected {
margin: 0;
padding: 7px 8px;
border-radius: 7px;
overflow-wrap: anywhere;
font-size: .6rem;
line-height: 1.5;
}
.activity-message,
.activity-frame-summary {
color: var(--text);
background: #0b1714;
}
.activity-message.is-stale {
color: var(--amber);
border: 1px solid rgb(255 197 110 / 24%);
}
.activity-caveat {
color: var(--muted);
border-left: 2px solid rgb(88 199 255 / 42%);
background: rgb(88 199 255 / 5%);
}
.activity-empty { color: var(--muted); text-align: center; }
.activity-event-selected {
color: var(--mint);
border: 1px solid rgb(101 242 191 / 24%);
background: rgb(101 242 191 / 5%);
}
.activity-result-row {
display: grid;
min-width: 0;
gap: 5px;
padding: 8px;
border: 1px solid var(--line);
border-radius: 8px;
background: #0b1714;
}
.activity-result-row > strong {
min-width: 0;
overflow-wrap: anywhere;
color: var(--text);
font-size: .64rem;
}
.activity-result-row > span {
min-width: 0;
overflow-wrap: anywhere;
color: var(--muted);
font: 550 .57rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.activity-hypothesis {
display: grid;
min-width: 0;
grid-template-columns: minmax(0, 1fr) auto;
gap: 5px;
}
.activity-hypothesis > span {
grid-column: 1 / -1;
color: var(--muted);
font-size: .56rem;
}
.activity-hypothesis input {
width: 100%;
min-width: 0;
min-height: 32px;
padding: 6px 7px;
border: 1px solid var(--line);
border-radius: 7px;
color: var(--text);
background: #07110f;
font-size: .62rem;
}
.activity-event-button {
width: 100%;
min-width: 0;
padding: 7px 8px;
border: 1px solid var(--line);
border-radius: 7px;
color: var(--text);
background: #0b1714;
cursor: pointer;
overflow-wrap: anywhere;
text-align: left;
font: 550 .59rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.activity-event-button:hover { border-color: var(--cyan); }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.inline-details, .advanced-settings, .utility-details, .mode-help {
@@ -470,22 +657,35 @@ html[data-run-state="running"] #snapshot-mode { border-color: var(--mint); box-s
.header-status { grid-column: 1 / -1; }
.run-status { max-width: 100%; }
.workflow-strip { top: 88px; }
.input-file-grid, .quick-field-grid, .algorithm-options, .advanced-field-grid, .output-actions, .band-editor, .live-controls { grid-template-columns: 1fr; }
.input-file-grid, .quick-field-grid, .algorithm-options, .advanced-field-grid, .output-actions, .band-editor, .live-controls, .activity-field-grid, .activity-option-grid, .activity-actions { grid-template-columns: 1fr; }
.field--wide, .live-scrubber { grid-column: auto; }
.band-editor__remove { min-height: 32px; }
.live-actions .button { flex: 1 1 calc(50% - 4px); }
.metric-grid { grid-template-columns: 1fr 1fr; }
.overlay-toolbar { justify-content: flex-start; }
.activity-hypothesis { grid-template-columns: 1fr; }
.activity-hypothesis > span { grid-column: auto; }
}
@container camera-controls (max-width: 350px) {
.input-file-grid,
.quick-field-grid,
.advanced-field-grid,
.output-actions {
.output-actions,
.activity-field-grid,
.activity-option-grid,
.activity-actions {
grid-template-columns: minmax(0, 1fr);
}
.activity-hypothesis {
grid-template-columns: minmax(0, 1fr);
}
.activity-hypothesis > span {
grid-column: auto;
}
.field--wide {
grid-column: auto;
}