# Tasks: enterprise-audio-analysis-pitch **Change ID**: enterprise-audio-analysis-pitch **Package**: `@suaveplan/audio-analysis-pitch` **Target path**: `packages/media/audio/audio-analysis-pitch` **Prerequisite packages on Verdaccio**: `@suaveplan/audio-core`, `@suaveplan/error`, `@suaveplan/types` --- ## 1. Scaffold - [ ] Create directory `packages/media/audio/audio-analysis-pitch/` with `src/`, `tests/`, `src/__benchmarks__/`, and all feature subdirectories per the layout in `proposal.md`. - [ ] Write `package.json` at version `0.1.0` with `"type": "module"`, `"sideEffects": false`, full `exports` map, deps: `@suaveplan/audio-core workspace:^`, `@suaveplan/error workspace:^`, `@suaveplan/types workspace:^`, `@suaveplan/opentelemetry workspace:^`, `zod catalog:forms`. - [ ] Write `tsconfig.json` extending `@suaveplan/typescript-config/library.json`. - [ ] Write `vitest.config.ts` using `createTestConfig()` from `@suaveplan/testing/config`. - [ ] Add `lint`, `typecheck`, `test`, `test:coverage`, `build`, `docs:check` scripts. --- ## 2. Types + errors - [ ] Write `src/error-codes.ts` — `PITCHErrorCode`, `AUDIO_ANALYSIS_PITCH_ERROR_METADATA`, `registerAudioAnalysisErrorCodes()`. - [ ] Write Zod schemas: `PitchDetectorOptionsSchema`, `PitchResultSchema`, `KeyDetectorOptionsSchema`, `KeyResultSchema`, `ChordResultSchema`. --- ## 3. Algorithms - [ ] Implement `yin.ts` — YIN pitch detection algorithm. - [ ] Write `yin.test.ts` and `yin.md` (≥200 words). - [ ] Implement `chromagram.ts` — 12-bin pitch class profile from magnitude spectrum. - [ ] Write `chromagram.test.ts` and `chromagram.md` (≥200 words). - [ ] Implement `key-finding.ts` — Krumhansl-Schmuckler and Temperley key profiles. - [ ] Write `key-finding.test.ts` and `key-finding.md` (≥200 words). - [ ] Implement `chord-matching.ts` — template matching for chord recognition. - [ ] Write `chord-matching.test.ts` and `chord-matching.md` (≥200 words). --- ## 4. Detectors - [ ] Implement `PitchDetector` class with `analyze()`, `analyzeStream()`, `analyzeBlock()`. - [ ] Write `pitch-detector.test.ts` and `pitch-detector.md` (≥200 words). - [ ] Implement `KeyDetector` class with `analyze()`, `analyzeStream()`. - [ ] Write `key-detector.test.ts` and `key-detector.md` (≥200 words). - [ ] Implement `ChordDetector` class with `analyze()`, `analyzeStream()`. - [ ] Write `chord-detector.test.ts` and `chord-detector.md` (≥200 words). - [ ] Wire OTel: spans, counters, histograms per detector. --- ## 5. Benchmarks - [ ] Write `src/__benchmarks__/pitch.bench.ts` — pitch detect 1-minute track, key detect 1-minute track. --- ## 6. Tests - [ ] Write `tests/integration.test.ts` — full pitch/key/chord round-trip on real audio fixture. - [ ] Write `tests/property.test.ts` (fast-check) — sine wave frequency → exact pitch, confidence in [0,1]. --- ## 7. Docs + verify + publish - [ ] All co-located `.md` files (≥200 words each). - [ ] Write `README.md` at package root. - [ ] `bunx turbo lint typecheck test --filter=@suaveplan/audio-analysis-pitch` — green. - [ ] `bunx turbo test:coverage --filter=@suaveplan/audio-analysis-pitch` — 100%. - [ ] `bun scripts/publish.ts --package @suaveplan/audio-analysis-pitch`. - [ ] Fold `specs/audio-analysis-pitch/spec.md` into `openspec/specs/audio-analysis-pitch/spec.md`. - [ ] Archive to `openspec/archive/2026-05-14-enterprise-audio-analysis-pitch/`.