"""Production pass for the 5 per-altitude soundtracks (audio spec §5.3). The audio
analogue of build_pool_manifest.py --media: read the sourced ambience clips
(re-downloadable per docs/audio-candidate-pool.md), and make each a seamless
loudness-normalized loop.

Media is gitignored; this script is the reproducible record. Outputs land under
simulator/sample_media/audio/<scale>/<name>.loop.mp3, served at /media/audio/...
Run:  python simulator/build_audio_media.py

(White-noise is deferred — the live Audio control is a simple on/off soundtrack
toggle. `tools.pipeline.audio_run.generate_white_noise` remains for when it's
wanted, but no noise bed is built here.)
"""

from __future__ import annotations

from pathlib import Path

from tools.pipeline.audio_run import process_soundtrack

AUDIO = Path(__file__).parent / "sample_media" / "audio"

# scale -> (sourced raw file, production output file), both under audio/<scale>/.
# Sources per docs/audio-candidate-pool.md (the "✓ KEEP" picks).
SOURCES: dict[str, tuple[str, str]] = {
    "cosmos": ("pillars.mp3", "pillars.loop.mp3"),
    "orbit": ("spaceamb.mp3", "spaceamb.loop.mp3"),
    "coast": ("waves.mp3", "waves.loop.mp3"),
    "reef": ("soundscape.mp3", "soundscape.loop.mp3"),
    "abyss": ("whale.wav", "whale.loop.mp3"),
}


def main() -> None:
    for scale, (raw, out) in SOURCES.items():
        src = AUDIO / scale / raw
        if not src.exists():
            print(f"  SKIP {scale}: source missing ({src}) — re-source per audio-candidate-pool.md")
            continue
        dst = process_soundtrack(src, AUDIO / scale / out)
        print(f"  produced {dst.relative_to(AUDIO.parent)}")


if __name__ == "__main__":
    main()
