## 2026-10-08T06:52:00Z
You are teamwork_preview_worker (M3 4-Stem Audio Continuity Engine & Ambience Continuity Worker).
Your working directory is: c:\Projects\KieuStory\.agents\teamwork\worker_m3_1

You MUST read:
- c:\Projects\KieuStory\.agents\teamwork\ORIGINAL_REQUEST.md
- c:\Projects\KieuStory\PROJECT.md
- c:\Projects\KieuStory\.agents\teamwork\explorer_m3_1\handoff.md (and analysis.md)
- c:\Projects\KieuStory\.agents\teamwork\explorer_m3_2\handoff.md (and proposed_audio_continuity_engine.py, generate_festival_ambience_bed.py)
- c:\Projects\KieuStory\.agents\teamwork\explorer_m3_3\handoff.md (and analysis.md)
before starting work.

Files owned exclusively by you:
- c:\Projects\KieuStory\05_Production_Pipeline\audio_continuity_engine.py
- c:\Projects\KieuStory\05_Production_Pipeline\production_orchestrator.py
- c:\Projects\KieuStory\04_Assets\audio_sfx\ep01_scene04_festival_crowd_ambience_120s.wav
- c:\Projects\KieuStory\PROJECT.md

MANDATORY INTEGRITY WARNING:
DO NOT CHEAT. All implementations must be genuine. DO NOT hardcode test results, create dummy/facade implementations, or circumvent the intended task. A teamwork_preview_auditor will independently verify your work. Integrity violations WILL be detected and your work WILL be rejected.

Your implementation tasks:
1. Upgrade `05_Production_Pipeline/audio_continuity_engine.py`:
   - Incorporate the complete architectural upgrades from `explorer_m3_2/proposed_audio_continuity_engine.py` and `explorer_m3_1/handoff.md`:
     * Two-Pass Linear EBU R128 Loudness Normalization: implement `measure_loudness` Pass 1 parsing JSON statistics (`input_i`, `input_tp`, `input_lra`, `input_thresh`), and Pass 2 with `linear=true` and measured parameters. Include `-inf` silence guard to prevent FFmpeg crashes.
     * 4-Stem Mixing Architecture via `mix_four_stems()`: Stem 1 (BGM with 800Hz-3500Hz notch filter), Stem 2 (Ambience), Stem 3 (Foley), Stem 4 (Dialogue) with -14dB speech ducking.
     * Boundary Micro-Fade Mode A (30ms `curve=qsin` for zero cumulative duration loss and click/pop prevention) & Mode B (`acrossfade` with tail padding).
     * Stream Pre-conditioning: `aresample=48000,aformat=channel_layouts=stereo` and synthetic audio fallback (`aevalsrc=0`) for clips lacking audio streams.
     * Active RMS Gain Staging: adjust volume deltas exceeding 3.0 dB towards -24.0 dBFS target with peak headroom safeguard.
     * Preserve all AST/regex tokens (`loudnorm=I=-14`, `-stream_loop`, `-1`, `48000`, `3.0`, `qsin`, `target_lufs`) and existing signatures to ensure 100% test compatibility.
2. Upgrade `05_Production_Pipeline/production_orchestrator.py`:
   - In `concat_scene_shots`: use `AudioContinuityEngine.stitch_with_audio_crossfade` as the primary concatenation engine instead of naive hard-cut FFmpeg concat.
   - In `master_scene_audio`: accept `--ambience` (Stem 2) parameter and call the 4-stem mixing and two-pass loudness normalization.
   - Enforce MP4 versioning convention (`_v<N>.mp4`).
3. Generate Stem 2 Festival Ambience Asset:
   - Run `c:\Projects\KieuStory\.agents\teamwork\explorer_m3_2\generate_festival_ambience_bed.py` (or write generator script) to generate `c:\Projects\KieuStory\04_Assets\audio_sfx\ep01_scene04_festival_crowd_ambience_120s.wav` (48kHz, stereo, 120s, with ambient crowd murmur, festival bells, flute melodies, and chatter).
4. Update `c:\Projects\KieuStory\PROJECT.md`:
   - Line 48: Update Milestone 2 Status to `DONE`.
   - Line 49: Update Milestone 3 Status to `IN_PROGRESS`.
5. Run Verification:
   - Run `python tests/run_all_tests.py` and verify all M3 tests pass (`test_f8_*`, `test_f9_*`, `test_f10_*`).
   - Run individual audio test suites to ensure 0 regressions.
6. Document all changes and test outputs in `handoff.md` following the 5-component protocol, and notify parent orchestrator.
