4.0 KiB
4.0 KiB
Tasks: enterprise-audio-analysis-loudness
Change ID: enterprise-audio-analysis-loudness
Package: @suaveplan/audio-analysis-loudness
Target path: packages/media/audio/audio-analysis-loudness
Prerequisite packages on Verdaccio: @suaveplan/audio-core, @suaveplan/error, @suaveplan/types
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Scaffold
- Create directory
packages/media/audio/audio-analysis-loudness/withsrc/,tests/,src/__benchmarks__/, and all feature subdirectories per the layout inproposal.md. - Write
package.jsonat version0.1.0with"type": "module","sideEffects": false, fullexportsmap, deps:@suaveplan/audio-core workspace:^,@suaveplan/error workspace:^,@suaveplan/types workspace:^,@suaveplan/opentelemetry workspace:^,zod catalog:forms. - Write
tsconfig.jsonextending@suaveplan/typescript-config/library.json. - Write
vitest.config.tsusingcreateTestConfig()from@suaveplan/testing/config. - Add
lint,typecheck,test,test:coverage,build,docs:checkscripts.
2. Types + errors
- Write
src/error-codes.ts—LOUDNESSErrorCode,AUDIO_ANALYSIS_LOUDNESS_ERROR_METADATA,registerAudioAnalysisErrorCodes(). - Write Zod schemas:
LoudnessMeterOptionsSchema,LoudnessResultSchema.
3. Filters + algorithms
- Implement
k-weighting.ts— ITU-R BS.1770 K-weighting filter (high-shelf + high-pass). - Write
k-weighting.test.tsandk-weighting.md(≥200 words). - Implement
lufs.ts— momentary/short-term/integrated loudness with gating. - Write
lufs.test.tsandlufs.md(≥200 words). - Implement
true-peak.ts— 4x oversampled true peak detection. - Write
true-peak.test.tsandtrue-peak.md(≥200 words). - Implement
loudness-range.ts— EBU Tech 3342 statistical loudness range. - Write
loudness-range.test.tsandloudness-range.md(≥200 words).
4. LoudnessMeter
- Implement
LoudnessMeterclass:analyze()— full-document BS.1770-4 measurementanalyzeStream()— running integrated loudness as blocks arriveanalyzeBlock()— momentary loudness for real-time meters
- Wire OTel: span
audio.analysis.loudness, counter, histogram. - Write
loudness-meter.test.ts(≤500 lines): reference signal → known LUFS, silence → graceful, true peak > sample peak. - Write
loudness-meter.md(≥200 words).
5. Benchmarks
- Write
src/__benchmarks__/loudness.bench.ts— meter 1-minute track, meter 10-minute track.
6. Tests
- Write
tests/integration.test.ts— full loudness measurement round-trip on real audio fixture. - Write
tests/property.test.ts(fast-check) — LUFS monotonic with gain, true peak ≥ sample peak.
7. Docs + verify + publish
- All co-located
.mdfiles (≥200 words each). - Write
README.mdat package root. bunx turbo lint typecheck test --filter=@suaveplan/audio-analysis-loudness— green.bunx turbo test:coverage --filter=@suaveplan/audio-analysis-loudness— 100%.bun scripts/publish.ts --package @suaveplan/audio-analysis-loudness.- Fold
specs/audio-analysis-loudness/spec.mdintoopenspec/specs/audio-analysis-loudness/spec.md. - Archive to
openspec/archive/2026-05-14-enterprise-audio-analysis-loudness/.