@wildshard/sdk 0.0.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GUIDE.md +790 -0
- package/README.md +13 -5
- package/bin/wildshard.mjs +38 -0
- package/lint/declaration-config.d.mts +2 -0
- package/lint/declaration-config.mjs +19 -0
- package/lint/engine-plugin.d.mts +2 -0
- package/lint/engine-plugin.mjs +40 -0
- package/lint/host-callbacks.d.mts +6 -0
- package/lint/host-callbacks.mjs +123 -0
- package/lint/host-files.d.mts +1 -0
- package/lint/host-files.mjs +7 -0
- package/lint/layer-exports.d.mts +2 -0
- package/lint/layer-exports.mjs +21 -0
- package/lint/legacy-line-basis.json +995 -0
- package/lint/nine-tiling-baseline.json +35 -0
- package/lint/ratchet.json +11 -0
- package/lint/runtime-files.d.mts +12 -0
- package/lint/runtime-files.json +16 -0
- package/lint/runtime-files.mjs +69 -0
- package/lint/runtime-performance.d.mts +6 -0
- package/lint/runtime-performance.mjs +184 -0
- package/lint/sdk-plugin.d.mts +4 -0
- package/lint/sdk-plugin.mjs +134 -0
- package/lint/shardfile-boundaries.d.mts +10 -0
- package/lint/shardfile-boundaries.mjs +122 -0
- package/lint/tile-bake-debt.json +556 -0
- package/package.json +365 -3
- package/scripts/agent-parity.mjs +1524 -0
- package/scripts/agent-sync.mjs +518 -0
- package/scripts/apfs-clone.mjs +67 -0
- package/scripts/assert-store-layout.mjs +23 -0
- package/scripts/astc6-phone-cap.d.mts +3 -0
- package/scripts/astc6-phone-cap.mjs +137 -0
- package/scripts/audit-assets.d.mts +10 -0
- package/scripts/audit-assets.mjs +151 -0
- package/scripts/bake/coatFiles.d.mts +6 -0
- package/scripts/bake/coatFiles.mjs +37 -0
- package/scripts/bake/environment.d.mts +2 -0
- package/scripts/bake/environment.mjs +58 -0
- package/scripts/bake/far-proxies.mjs +45 -0
- package/scripts/bake/keyed-sky.d.mts +4 -0
- package/scripts/bake/keyed-sky.mjs +34 -0
- package/scripts/bake/movers.mjs +56 -0
- package/scripts/bake/nativeWorld.d.mts +6 -0
- package/scripts/bake/nativeWorld.mjs +43 -0
- package/scripts/bake/navmeshGround.ts +22 -0
- package/scripts/bake/near-placeholder.mjs +331 -0
- package/scripts/bake/placeholderShards.mjs +41 -0
- package/scripts/bake/skins.mjs +15 -0
- package/scripts/bake/template-skins.mjs +33 -0
- package/scripts/bake/viewmodelBytes.ts +26 -0
- package/scripts/bake/viewmodelPage.ts +11 -0
- package/scripts/bake/worldHost.d.mts +35 -0
- package/scripts/bake/worldHost.mjs +110 -0
- package/scripts/bake-astc6.cache.json +80 -0
- package/scripts/bake-astc6.far-reach.cache.json +23 -0
- package/scripts/bake-astc6.list.json +111 -0
- package/scripts/bake-astc6.mjs +279 -0
- package/scripts/bake-astc6.nalati-grasslands.cache.json +42 -0
- package/scripts/bake-catalogue.mjs +44 -0
- package/scripts/bake-check.mjs +54 -0
- package/scripts/bake-chunk.mjs +124 -0
- package/scripts/bake-cloud-field.mjs +24 -0
- package/scripts/bake-coats.mjs +110 -0
- package/scripts/bake-data-maps.d.mts +24 -0
- package/scripts/bake-data-maps.mjs +72 -0
- package/scripts/bake-entry-programs.mjs +117 -0
- package/scripts/bake-geometry.mjs +106 -0
- package/scripts/bake-hybrid-tiles.mjs +28 -0
- package/scripts/bake-ktx2.cache.json +276 -0
- package/scripts/bake-ktx2.list.json +365 -0
- package/scripts/bake-ktx2.mjs +477 -0
- package/scripts/bake-map-glb.mjs +127 -0
- package/scripts/bake-map-rest.d.mts +7 -0
- package/scripts/bake-map-rest.mjs +50 -0
- package/scripts/bake-maps.mjs +200 -0
- package/scripts/bake-navmesh.mjs +259 -0
- package/scripts/bake-packs.mjs +129 -0
- package/scripts/bake-pickups.mjs +102 -0
- package/scripts/bake-query-terrain.mjs +64 -0
- package/scripts/bake-recurve-pool.mjs +16 -0
- package/scripts/bake-section-schemas.d.mts +3 -0
- package/scripts/bake-template-shardfile.mjs +32 -0
- package/scripts/bake-textures.mjs +80 -0
- package/scripts/bake-viewmodel-sets.json +45 -0
- package/scripts/bake-viewmodel-sets.mjs +137 -0
- package/scripts/bake-voxel-ao.mjs +119 -0
- package/scripts/bake-water-ripples.mjs +25 -0
- package/scripts/blender/README.md +129 -0
- package/scripts/blender/build.sh +166 -0
- package/scripts/blender/lib/export-scene.mjs +129 -0
- package/scripts/blender/lib/glb-digest.mjs +188 -0
- package/scripts/blender/lib/glb.py +68 -0
- package/scripts/blender/lib/save_blend.py +17 -0
- package/scripts/blender/lib/world_fixture.py +55 -0
- package/scripts/blender/targets.json +591 -0
- package/scripts/build-sdk.mjs +95 -0
- package/scripts/build-shardfiles.d.mts +7 -0
- package/scripts/build-shardfiles.mjs +206 -0
- package/scripts/capture-hero.mjs +137 -0
- package/scripts/check-lift-review.mjs +23 -0
- package/scripts/chromium-keychain-check.mjs +139 -0
- package/scripts/chromium-keychain.d.mts +1 -0
- package/scripts/chromium-keychain.mjs +5 -0
- package/scripts/compile-script.d.mts +3 -0
- package/scripts/compile-script.mjs +8 -0
- package/scripts/creature-color.mjs +255 -0
- package/scripts/decide/calibrate.py +127 -0
- package/scripts/decide/calibration/2026-10-03/labels-s1.tsv +281 -0
- package/scripts/decide/calibration/2026-10-03/labels-s2.tsv +97 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3.tsv +48 -0
- package/scripts/decide/calibration/2026-10-03/labels-s3b.tsv +26 -0
- package/scripts/decide/calibration/2026-10-03/res-capture-status-v1.jsonl +376 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-strings.jsonl +48 -0
- package/scripts/decide/calibration/2026-10-03/res-text-garbled-v1.jsonl +73 -0
- package/scripts/decide/decide.py +262 -0
- package/scripts/decide/decide.sh +50 -0
- package/scripts/decide/layer-purity-pilot.mjs +41 -0
- package/scripts/decide/sets/capture-status.json +46 -0
- package/scripts/decide/sets/layer-purity.json +28 -0
- package/scripts/decide/sets/text-garbled.json +17 -0
- package/scripts/decide/test_decide.py +37 -0
- package/scripts/docs.mjs +15 -0
- package/scripts/entry-reads/crawl.ts +152 -0
- package/scripts/entry-reads/tsconfig.json +25 -0
- package/scripts/gen-format-schema.d.mts +2 -0
- package/scripts/gen-format-schema.mjs +21 -0
- package/scripts/gen-host-catalogue.d.mts +14 -0
- package/scripts/gen-host-catalogue.mjs +108 -0
- package/scripts/gen-shard-layout-doc.d.mts +4 -0
- package/scripts/gen-shard-layout-doc.mjs +55 -0
- package/scripts/gen-shards.d.mts +17 -0
- package/scripts/gen-shards.mjs +311 -0
- package/scripts/goldens/capture-inputs.d.mts +4 -0
- package/scripts/goldens/capture-inputs.mjs +34 -0
- package/scripts/goldens/colour_shift.py +27 -0
- package/scripts/goldens/native-residency.d.mts +10 -0
- package/scripts/goldens/native-residency.mjs +104 -0
- package/scripts/goldens/plot-inputs.d.mts +12 -0
- package/scripts/goldens/plot-inputs.mjs +46 -0
- package/scripts/gpu-texmem.mjs +98 -0
- package/scripts/horizon-matte/config.py +24 -0
- package/scripts/horizon-matte/encode.py +91 -0
- package/scripts/horizon-matte/key.py +141 -0
- package/scripts/horizon-matte/mkjobs.py +33 -0
- package/scripts/horizon-matte/mkjobs_day2.py +11 -0
- package/scripts/horizon-matte/overlap.py +80 -0
- package/scripts/horizon-matte/run_codex.py +57 -0
- package/scripts/horizon-matte/stitch.py +133 -0
- package/scripts/img2mesh/CC0.md +105 -0
- package/scripts/img2mesh/README.md +209 -0
- package/scripts/img2mesh/ab_board.py +102 -0
- package/scripts/img2mesh/birds/birds.json +255 -0
- package/scripts/img2mesh/birds/birds_atlas.py +150 -0
- package/scripts/img2mesh/birds/birds_fix_preview.mjs +103 -0
- package/scripts/img2mesh/birds/birds_fix_render.py +75 -0
- package/scripts/img2mesh/birds/birds_pack.py +110 -0
- package/scripts/img2mesh/birds/birds_phone_b.py +112 -0
- package/scripts/img2mesh/birds/birds_post.py +550 -0
- package/scripts/img2mesh/birds/birds_render.py +125 -0
- package/scripts/img2mesh/birds/birds_sheet.py +33 -0
- package/scripts/img2mesh/birds/birds_view.py +60 -0
- package/scripts/img2mesh/board.py +100 -0
- package/scripts/img2mesh/build_cc0.sh +52 -0
- package/scripts/img2mesh/build_driftwood.sh +12 -0
- package/scripts/img2mesh/build_faces.sh +53 -0
- package/scripts/img2mesh/build_props.py +81 -0
- package/scripts/img2mesh/cc0_export.py +186 -0
- package/scripts/img2mesh/driftwood_post.py +571 -0
- package/scripts/img2mesh/e304_faces.sh +67 -0
- package/scripts/img2mesh/face_remaster.py +911 -0
- package/scripts/img2mesh/face_views.py +95 -0
- package/scripts/img2mesh/faces-e304.json +9 -0
- package/scripts/img2mesh/faces.json +30 -0
- package/scripts/img2mesh/head_cut.py +100 -0
- package/scripts/img2mesh/hi3d_paint.py +94 -0
- package/scripts/img2mesh/hi3d_refine.py +161 -0
- package/scripts/img2mesh/hunyuan_cpu_rasterizer.sh +42 -0
- package/scripts/img2mesh/pine_hollow_phone.sh +13 -0
- package/scripts/img2mesh/props/coral-arch.json +32 -0
- package/scripts/img2mesh/props/ember-furnace.json +30 -0
- package/scripts/img2mesh/props/night-market-gate.json +10 -0
- package/scripts/img2mesh/render_still.py +86 -0
- package/scripts/img2mesh/rig_strip.mjs +46 -0
- package/scripts/img2mesh/rig_transfer.mjs +104 -0
- package/scripts/img2mesh/split_sheet.py +48 -0
- package/scripts/img2mesh/trellis_batch.py +110 -0
- package/scripts/img2mesh/versus_board.py +114 -0
- package/scripts/import-bundle.d.mts +2 -0
- package/scripts/import-bundle.mjs +20 -0
- package/scripts/ktx2-ab-board.py +133 -0
- package/scripts/ktx2-ab.mjs +111 -0
- package/scripts/ktx2-settings.mjs +18 -0
- package/scripts/land.d.mts +14 -0
- package/scripts/land.mjs +809 -0
- package/scripts/lint-dispatch.mjs +14 -0
- package/scripts/map-bake-frames.d.mts +4 -0
- package/scripts/map-bake-frames.mjs +23 -0
- package/scripts/map-geometry.d.mts +9 -0
- package/scripts/map-geometry.mjs +29 -0
- package/scripts/map-world.mjs +162 -0
- package/scripts/mockup-local.sh +46 -0
- package/scripts/music/export-midi.mjs +68 -0
- package/scripts/music/gen/analyze.py +308 -0
- package/scripts/music/gen/audio_jobs.py +46 -0
- package/scripts/music/gen/briefs.json +51 -0
- package/scripts/music/gen/build_page.py +334 -0
- package/scripts/music/gen/folk.json +3187 -0
- package/scripts/music/gen/gen_ace_step.py +156 -0
- package/scripts/music/gen/gen_heartmula.py +187 -0
- package/scripts/music/gen/gen_minimax.py +143 -0
- package/scripts/music/gen/gen_sao.py +122 -0
- package/scripts/music/gen/gen_sao_small.py +104 -0
- package/scripts/music/gen/gen_sfx.py +98 -0
- package/scripts/music/gen/gen_sfx_ezaudio.py +112 -0
- package/scripts/music/gen/gen_sfx_moss.py +112 -0
- package/scripts/music/gen/models.json +61 -0
- package/scripts/music/gen/nalati-jobs.json +104 -0
- package/scripts/music/gen/nalati-score-build.json +119 -0
- package/scripts/music/gen/nalati-score.json +3448 -0
- package/scripts/music/gen/ob7-fit-decisions.json +38 -0
- package/scripts/music/gen/ob7-score-jobs.json +152 -0
- package/scripts/music/gen/ob7-sfx-jobs.json +897 -0
- package/scripts/music/gen/ob7_build.py +469 -0
- package/scripts/music/gen/ob7_generate.py +67 -0
- package/scripts/music/gen/ob7_run.sh +42 -0
- package/scripts/music/gen/orchestral.json +3187 -0
- package/scripts/music/gen/own_score.py +486 -0
- package/scripts/music/gen/ph-jobs.json +27 -0
- package/scripts/music/gen/ph_page.py +222 -0
- package/scripts/music/gen/piano.json +3175 -0
- package/scripts/music/gen/rank_v3.py +248 -0
- package/scripts/music/gen/sfx-best.json +2486 -0
- package/scripts/music/gen/sfx-ezaudio.json +4082 -0
- package/scripts/music/gen/sfx-jobs.json +57 -0
- package/scripts/music/gen/sfx-minimax-jobs.json +16 -0
- package/scripts/music/gen/sfx-minimax.json +289 -0
- package/scripts/music/gen/sfx-moss.json +4082 -0
- package/scripts/music/gen/sfx-nalati-b3-jobs.json +17 -0
- package/scripts/music/gen/sfx-nalati-jobs.json +338 -0
- package/scripts/music/gen/sfx-nalati.json +11202 -0
- package/scripts/music/gen/sfx-nd-jobs.json +57 -0
- package/scripts/music/gen/sfx-nd-moss.json +2097 -0
- package/scripts/music/gen/sfx-nd-sa3-medium.json +2097 -0
- package/scripts/music/gen/sfx-nd-summary.json +38 -0
- package/scripts/music/gen/sfx-peaks.json +7 -0
- package/scripts/music/gen/sfx-ph-jobs.json +169 -0
- package/scripts/music/gen/sfx-ph-moss.json +6564 -0
- package/scripts/music/gen/sfx-ph-sa3-medium.json +7239 -0
- package/scripts/music/gen/sfx-ph-summary.json +63 -0
- package/scripts/music/gen/sfx-sa3-medium.json +4082 -0
- package/scripts/music/gen/sfx-sa3.json +4082 -0
- package/scripts/music/gen/sfx-summary.json +107 -0
- package/scripts/music/gen/sfx_build.py +332 -0
- package/scripts/music/gen/sfx_merge.py +255 -0
- package/scripts/music/gen/sfx_minimax.py +61 -0
- package/scripts/music/gen/sfx_nalati.py +331 -0
- package/scripts/music/gen/sfx_sprite.py +424 -0
- package/scripts/music/gen/stems.py +539 -0
- package/scripts/music/gen/test_loop_meter.py +29 -0
- package/scripts/music/gen/test_ob7_provenance.py +77 -0
- package/scripts/music/gen/v3-folk-build.json +148 -0
- package/scripts/music/gen/v3-folk.json +1818 -0
- package/scripts/music/gen/v3-jobs.json +145 -0
- package/scripts/music/gen/v3-orchestral-build.json +148 -0
- package/scripts/music/gen/v3-orchestral.json +1813 -0
- package/scripts/music/gen/v3-ph-folk-build.json +94 -0
- package/scripts/music/gen/v3-ph-folk.json +1806 -0
- package/scripts/music/gen/v3-ph-orchestral-build.json +94 -0
- package/scripts/music/gen/v3-ph-orchestral.json +1824 -0
- package/scripts/music/gen/v3-ph-piano-build.json +94 -0
- package/scripts/music/gen/v3-ph-piano.json +1818 -0
- package/scripts/music/gen/v3-piano-build.json +148 -0
- package/scripts/music/gen/v3-piano.json +1813 -0
- package/scripts/music/wildshard-theme.mid +0 -0
- package/scripts/music/wildshard-trailer30.mid +0 -0
- package/scripts/named-blob-output.d.mts +8 -0
- package/scripts/named-blob-output.mjs +48 -0
- package/scripts/pack-all.mjs +15 -0
- package/scripts/pid-lock.d.mts +1 -0
- package/scripts/pid-lock.mjs +63 -0
- package/scripts/practice/bake_dummy.py +53 -0
- package/scripts/practice/build_dummies.sh +43 -0
- package/scripts/practice/dummy_parts.py +568 -0
- package/scripts/practice/dummy_rig_gate.py +139 -0
- package/scripts/practice/gate_sheet.py +36 -0
- package/scripts/practice/generate_dummy_unimate.py +132 -0
- package/scripts/practice/pack_dummy.mjs +59 -0
- package/scripts/practice/repair_dummy_weights.mjs +68 -0
- package/scripts/practice/rig_dummy.py +828 -0
- package/scripts/practice/verify_unimate_skin.mjs +356 -0
- package/scripts/preparation-seed.mjs +15 -0
- package/scripts/prepare-basis-tool.mjs +6 -0
- package/scripts/prepare-product.d.mts +14 -0
- package/scripts/prepare-product.mjs +101 -0
- package/scripts/product-build-tools.d.mts +3 -0
- package/scripts/product-build-tools.json +3 -0
- package/scripts/product-build-tools.mjs +31 -0
- package/scripts/publish-public.mjs +7 -0
- package/scripts/push-tables.d.mts +1 -0
- package/scripts/push-tables.mjs +28 -0
- package/scripts/record-shard-mounts.mjs +133 -0
- package/scripts/sdk-externals.d.mts +2 -0
- package/scripts/sdk-externals.mjs +2 -0
- package/scripts/section-inventory.ts +209 -0
- package/scripts/select-candidate.mjs +15 -0
- package/scripts/shard-build-pool.d.mts +4 -0
- package/scripts/shard-build-pool.mjs +53 -0
- package/scripts/shard-line-baseline.json +17 -0
- package/scripts/shard-milestones.d.mts +15 -0
- package/scripts/shard-milestones.mjs +105 -0
- package/scripts/shard-output-report.d.mts +9 -0
- package/scripts/shard-output-report.mjs +85 -0
- package/scripts/shard-platform-cli.mjs +93 -0
- package/scripts/shard-progress.mjs +212 -0
- package/scripts/shard-timelapse.py +102 -0
- package/scripts/shardfile-cold-boot.mjs +79 -0
- package/scripts/shardfile-vite.d.mts +4 -0
- package/scripts/shardfile-vite.mjs +20 -0
- package/scripts/simplify-models.mjs +24 -0
- package/scripts/site-facts.mjs +88 -0
- package/scripts/test-template-gate.mjs +44 -0
- package/scripts/test_golden_compare.py +68 -0
- package/scripts/tex-tiers.cache.json +181 -0
- package/scripts/tex-tiers.mjs +240 -0
- package/scripts/texmem-probe.mjs +184 -0
- package/scripts/unused-assets.mjs +173 -0
- package/scripts/vite-tmp.d.mts +23 -0
- package/scripts/vite-tmp.mjs +157 -0
- package/scripts/wave-line-baselines.json +32 -0
- package/scripts/wildshard.d.mts +4 -0
- package/scripts/wildshard.mjs +105 -0
- package/scripts/witness-checkpoints.d.mts +10 -0
- package/scripts/witness-checkpoints.mjs +84 -0
- package/scripts/witness-generation.d.mts +10 -0
- package/scripts/witness-generation.mjs +45 -0
- package/scripts/witness-manifests.d.mts +8 -0
- package/scripts/witness-manifests.mjs +157 -0
- package/scripts/worktree-ignore.d.mts +4 -0
- package/scripts/worktree-ignore.mjs +36 -0
- package/scripts/worktree-reap.mjs +214 -0
- package/scripts/worktree.mjs +396 -0
- package/scripts/worldclaw/capture-front.sh +28 -0
- package/scripts/worldclaw/design-template.md +62 -0
- package/scripts/worldclaw/spec-map.py +92 -0
- package/scripts/worldclaw/spec.ts +96 -0
- package/skills/wildshard/SKILL.md +50 -0
- package/skills/wildshard-goldens/SKILL.md +54 -0
- package/skills/wildshard-mockup-to-model/SKILL.md +56 -0
- package/skills/wildshard-upgrade/SKILL.md +46 -0
- package/src/.oxfmtrc.json +50 -0
- package/src/.oxlintrc.json +173 -0
- package/src/cli/account/account.ts +199 -0
- package/src/cli/account/command.ts +193 -0
- package/src/cli/account/key.ts +154 -0
- package/src/cli/args.ts +97 -0
- package/src/cli/audio/audio.ts +24 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/delete/delete.ts +258 -0
- package/src/cli/help.ts +196 -0
- package/src/cli/hero/adopt.ts +103 -0
- package/src/cli/hero/hero.ts +112 -0
- package/src/cli/hero/stamp.ts +298 -0
- package/src/cli/main.ts +292 -0
- package/src/cli/report.ts +16 -0
- package/src/cli/shardfile/command.ts +50 -0
- package/src/cli/shardfile/shardfile.ts +192 -0
- package/src/cli/upload/api.ts +246 -0
- package/src/cli/upload/compress.ts +55 -0
- package/src/cli/upload/hero.ts +62 -0
- package/src/cli/upload/placement.ts +115 -0
- package/src/cli/upload/provenance.ts +192 -0
- package/src/cli/upload/signature.ts +30 -0
- package/src/cli/upload/upload.ts +269 -0
- package/src/cli/upload/validate.ts +74 -0
- package/src/cli/upload/wire.ts +147 -0
- package/src/cli/version.ts +63 -0
- package/src/commons/bake/portableMath.ts +187 -0
- package/src/commons/catalogue.ts +10 -0
- package/src/commons/courseProgram.ts +32 -0
- package/src/commons/practiceCourse.ts +16 -0
- package/src/commons/scripts/abi.as +14 -0
- package/src/commons/scripts/bridge.as +14 -0
- package/src/commons/scripts/course.as +63 -0
- package/src/scripts/ask-new.sh +29 -0
- package/src/scripts/asks.mjs +141 -0
- package/src/scripts/herdr-prompt.sh +34 -0
- package/src/scripts/herdr-question-open.sh +67 -0
- package/src/scripts/md-wrap.mjs +229 -0
- package/src/server/app.ts +19 -0
- package/src/server/serve.ts +49 -0
- package/src/sharddev/admission.ts +7 -0
- package/src/sharddev/arenaView.ts +15 -0
- package/src/sharddev/as/groupBankV2.ts +36 -0
- package/src/sharddev/as/groupStepV2.ts +13 -0
- package/src/sharddev/as/ws.ts +30 -0
- package/src/sharddev/as/wsV2.ts +180 -0
- package/src/sharddev/assemblyscriptCompiler.d.mts +5 -0
- package/src/sharddev/assemblyscriptCompiler.mjs +14 -0
- package/src/sharddev/assetHandle.ts +84 -0
- package/src/sharddev/assetOwner.ts +70 -0
- package/src/sharddev/assetScope.ts +30 -0
- package/src/sharddev/assets.ts +21 -0
- package/src/sharddev/audio.ts +9 -0
- package/src/sharddev/audioEncode.ts +211 -0
- package/src/sharddev/author.ts +3 -0
- package/src/sharddev/authorError.ts +28 -0
- package/src/sharddev/authorManifest.ts +39 -0
- package/src/sharddev/bake/annulus.ts +19 -0
- package/src/sharddev/bake/assemblyscriptMemo.ts +76 -0
- package/src/sharddev/bake/assemblyscriptMemoPort.ts +4 -0
- package/src/sharddev/bake/authoredWorld.ts +201 -0
- package/src/sharddev/bake/basisEncoder.ts +95 -0
- package/src/sharddev/bake/basisGlb.ts +85 -0
- package/src/sharddev/bake/basisTool.ts +74 -0
- package/src/sharddev/bake/basisToolInputs.ts +476 -0
- package/src/sharddev/bake/byteCodec.ts +33 -0
- package/src/sharddev/bake/canvasAtlas.ts +406 -0
- package/src/sharddev/bake/coarseCopy.ts +59 -0
- package/src/sharddev/bake/colliders.ts +87 -0
- package/src/sharddev/bake/compactGlb.ts +224 -0
- package/src/sharddev/bake/compileScript.ts +119 -0
- package/src/sharddev/bake/compileScriptV2.ts +75 -0
- package/src/sharddev/bake/contactRows.ts +84 -0
- package/src/sharddev/bake/creaturePlacement.ts +117 -0
- package/src/sharddev/bake/export.ts +67 -0
- package/src/sharddev/bake/facetedGeometry.ts +379 -0
- package/src/sharddev/bake/farImpostor.ts +120 -0
- package/src/sharddev/bake/forest.ts +100 -0
- package/src/sharddev/bake/format-hook.mjs +2 -0
- package/src/sharddev/bake/generatorGlb.ts +23 -0
- package/src/sharddev/bake/geometryBounds.ts +77 -0
- package/src/sharddev/bake/geometryError.ts +48 -0
- package/src/sharddev/bake/glb.ts +355 -0
- package/src/sharddev/bake/glbCompression.ts +143 -0
- package/src/sharddev/bake/gltfSource.ts +59 -0
- package/src/sharddev/bake/groundMap.ts +142 -0
- package/src/sharddev/bake/image.ts +20 -0
- package/src/sharddev/bake/isleMap.ts +64 -0
- package/src/sharddev/bake/json.mjs +84 -0
- package/src/sharddev/bake/keyedSky.ts +47 -0
- package/src/sharddev/bake/keyedSkyMemo.ts +39 -0
- package/src/sharddev/bake/kinds.ts +137 -0
- package/src/sharddev/bake/lightSources.ts +31 -0
- package/src/sharddev/bake/mapAssembly.ts +84 -0
- package/src/sharddev/bake/mapRaster.ts +173 -0
- package/src/sharddev/bake/mapRest.ts +57 -0
- package/src/sharddev/bake/mapScenes.ts +234 -0
- package/src/sharddev/bake/materialGraph.ts +32 -0
- package/src/sharddev/bake/meadow.ts +27 -0
- package/src/sharddev/bake/meshoptChoiceMemo.ts +34 -0
- package/src/sharddev/bake/nativeInteractionFacts.ts +5 -0
- package/src/sharddev/bake/nativeLattice.ts +178 -0
- package/src/sharddev/bake/nativeRaster.ts +106 -0
- package/src/sharddev/bake/nativeTerrainField.ts +11 -0
- package/src/sharddev/bake/navigation-json.mjs +38 -0
- package/src/sharddev/bake/navigation.ts +113 -0
- package/src/sharddev/bake/navigationAsset.ts +18 -0
- package/src/sharddev/bake/nearPlaceholder.ts +206 -0
- package/src/sharddev/bake/normalizeRig.ts +80 -0
- package/src/sharddev/bake/phoneAstc.ts +93 -0
- package/src/sharddev/bake/placeholders.ts +581 -0
- package/src/sharddev/bake/placement.ts +80 -0
- package/src/sharddev/bake/portableBytes.ts +18 -0
- package/src/sharddev/bake/portableBytesMemo.ts +50 -0
- package/src/sharddev/bake/practiceCourse.ts +49 -0
- package/src/sharddev/bake/primitives.ts +96 -0
- package/src/sharddev/bake/props.ts +443 -0
- package/src/sharddev/bake/questPlacement.ts +98 -0
- package/src/sharddev/bake/rawTexture.ts +26 -0
- package/src/sharddev/bake/riderArms.ts +97 -0
- package/src/sharddev/bake/rig.ts +95 -0
- package/src/sharddev/bake/riggedHullRecipes.ts +40 -0
- package/src/sharddev/bake/signPlacements.ts +25 -0
- package/src/sharddev/bake/simplifier.ts +52 -0
- package/src/sharddev/bake/skinned.ts +312 -0
- package/src/sharddev/bake/slabChunks.ts +149 -0
- package/src/sharddev/bake/slabs.ts +263 -0
- package/src/sharddev/bake/source-loader.mjs +55 -0
- package/src/sharddev/bake/sourceMetadata.ts +54 -0
- package/src/sharddev/bake/species.ts +368 -0
- package/src/sharddev/bake/specimenCatalogue.ts +47 -0
- package/src/sharddev/bake/splatGround.ts +141 -0
- package/src/sharddev/bake/staticMaterials.ts +171 -0
- package/src/sharddev/bake/terrain.ts +195 -0
- package/src/sharddev/bake/texture.ts +33 -0
- package/src/sharddev/bake/textureWasm.ts +81 -0
- package/src/sharddev/bake/tileEncoder.ts +11 -0
- package/src/sharddev/bake/tileGrid.ts +62 -0
- package/src/sharddev/bake/v2Finite.ts +160 -0
- package/src/sharddev/bake/v2Fuel.ts +71 -0
- package/src/sharddev/bake/wholePartition.ts +74 -0
- package/src/sharddev/bake/wholePieceJoin.ts +147 -0
- package/src/sharddev/bake/world.ts +173 -0
- package/src/sharddev/bake/worldCollision.ts +128 -0
- package/src/sharddev/bake/worldGeometry.ts +237 -0
- package/src/sharddev/bake/worldGlb.ts +123 -0
- package/src/sharddev/bake/worldImage.ts +12 -0
- package/src/sharddev/bake/worldLod.ts +128 -0
- package/src/sharddev/bake/worldRows.ts +102 -0
- package/src/sharddev/bake/worldTextureMemo.ts +63 -0
- package/src/sharddev/bake/zstdBytesMemo.ts +52 -0
- package/src/sharddev/bake.ts +193 -0
- package/src/sharddev/bakePublication.ts +31 -0
- package/src/sharddev/behaviourSource.ts +94 -0
- package/src/sharddev/bin/wildshard.mjs +7 -0
- package/src/sharddev/blobBytes.ts +65 -0
- package/src/sharddev/blobs.ts +138 -0
- package/src/sharddev/bootInventory.ts +129 -0
- package/src/sharddev/bossProfiles.ts +18 -0
- package/src/sharddev/buildBehaviour.ts +77 -0
- package/src/sharddev/buildCacheMetrics.ts +17 -0
- package/src/sharddev/buildDecisionScripts.ts +122 -0
- package/src/sharddev/check.ts +117 -0
- package/src/sharddev/checkProject.ts +126 -0
- package/src/sharddev/cli.ts +191 -0
- package/src/sharddev/clientChannels.ts +169 -0
- package/src/sharddev/clientScripts.ts +10 -0
- package/src/sharddev/commons.ts +77 -0
- package/src/sharddev/commonsCosts.ts +11 -0
- package/src/sharddev/compileMovers.ts +11 -0
- package/src/sharddev/configBoundary.ts +6 -0
- package/src/sharddev/cookInput.ts +40 -0
- package/src/sharddev/crowds.ts +6 -0
- package/src/sharddev/decisionBindingMap.ts +11 -0
- package/src/sharddev/decisionScriptBindings.ts +117 -0
- package/src/sharddev/decisionScripts.ts +28 -0
- package/src/sharddev/decisionSource.ts +51 -0
- package/src/sharddev/dev.ts +113 -0
- package/src/sharddev/director.ts +26 -0
- package/src/sharddev/directorAbi.ts +77 -0
- package/src/sharddev/discoveryDocument.ts +97 -0
- package/src/sharddev/draft.ts +11 -0
- package/src/sharddev/eliteEntryRows.ts +29 -0
- package/src/sharddev/entries.ts +76 -0
- package/src/sharddev/entryReads.ts +73 -0
- package/src/sharddev/executeBundle.ts +55 -0
- package/src/sharddev/finds.ts +5 -0
- package/src/sharddev/formatJsonSchema.ts +3 -0
- package/src/sharddev/generationCache.ts +257 -0
- package/src/sharddev/generationRecipe.ts +94 -0
- package/src/sharddev/handwritten.ts +110 -0
- package/src/sharddev/immutable.ts +14 -0
- package/src/sharddev/interactions.ts +38 -0
- package/src/sharddev/kit/bakedGeometry.ts +16 -0
- package/src/sharddev/kit/geometryPack.ts +110 -0
- package/src/sharddev/ledger.ts +13 -0
- package/src/sharddev/looks/tileField.ts +67 -0
- package/src/sharddev/materialGraphFiles.ts +57 -0
- package/src/sharddev/materials.ts +574 -0
- package/src/sharddev/measure.ts +18 -0
- package/src/sharddev/modes.ts +115 -0
- package/src/sharddev/moverPrograms.ts +213 -0
- package/src/sharddev/movers.ts +75 -0
- package/src/sharddev/nativePopulationRows.ts +46 -0
- package/src/sharddev/newProject.ts +247 -0
- package/src/sharddev/noise.ts +54 -0
- package/src/sharddev/outputProduct.ts +188 -0
- package/src/sharddev/outputRuntime.ts +66 -0
- package/src/sharddev/performancePolicy.ts +18 -0
- package/src/sharddev/phasedBoss.ts +34 -0
- package/src/sharddev/physics.ts +194 -0
- package/src/sharddev/platformSections.ts +42 -0
- package/src/sharddev/plumbing.ts +8 -0
- package/src/sharddev/productOutput.ts +128 -0
- package/src/sharddev/project.ts +337 -0
- package/src/sharddev/projectCompilerIdentity.ts +94 -0
- package/src/sharddev/projectDecisions.ts +66 -0
- package/src/sharddev/projectEntryProof.ts +32 -0
- package/src/sharddev/projectGeneration.ts +219 -0
- package/src/sharddev/projectInputFiles.ts +47 -0
- package/src/sharddev/projectManifest.ts +108 -0
- package/src/sharddev/projectMap.ts +35 -0
- package/src/sharddev/projectOutput.ts +242 -0
- package/src/sharddev/projectPolicy.ts +17 -0
- package/src/sharddev/projectSections.ts +27 -0
- package/src/sharddev/questGraph.ts +25 -0
- package/src/sharddev/quests.ts +65 -0
- package/src/sharddev/random.ts +61 -0
- package/src/sharddev/refusals.ts +234 -0
- package/src/sharddev/reportCard.ts +13 -0
- package/src/sharddev/returnProjectionV2.ts +81 -0
- package/src/sharddev/rows.ts +192 -0
- package/src/sharddev/runtimeImports.ts +38 -0
- package/src/sharddev/runtimeMirrors.ts +39 -0
- package/src/sharddev/runtimePerformance.ts +38 -0
- package/src/sharddev/scene.ts +321 -0
- package/src/sharddev/sceneAnimation.ts +54 -0
- package/src/sharddev/sceneAudio.ts +64 -0
- package/src/sharddev/sceneDeclarations.ts +100 -0
- package/src/sharddev/sceneGraph.ts +139 -0
- package/src/sharddev/sceneTransform.ts +12 -0
- package/src/sharddev/schemaValidation.ts +61 -0
- package/src/sharddev/sections.ts +47 -0
- package/src/sharddev/shardSource.ts +59 -0
- package/src/sharddev/sourceReader.ts +26 -0
- package/src/sharddev/spawns.ts +38 -0
- package/src/sharddev/species/clips.ts +24 -0
- package/src/sharddev/species.ts +29 -0
- package/src/sharddev/speciesBrains.ts +19 -0
- package/src/sharddev/synth.ts +66 -0
- package/src/sharddev/test/compileDualScriptV2.ts +71 -0
- package/src/sharddev/test/compileSimV2.ts +21 -0
- package/src/sharddev/test/diskScriptScenario.ts +86 -0
- package/src/sharddev/test/scriptScenario.ts +249 -0
- package/src/sharddev/test/scriptSource.ts +12 -0
- package/src/sharddev/version.ts +4 -0
- package/src/sharddev/weapons/bowProfile.ts +20 -0
- package/src/sharddev/weapons/firearmRows.ts +11 -0
- package/src/sharddev/weapons/meleeProfile.ts +71 -0
- package/src/sharddev/weapons/thrownProfile.ts +10 -0
- package/src/sharddev/worldScenes.ts +308 -0
- package/src/sharddev/worldSource.ts +82 -0
- package/src/shards/_template/README.md +78 -0
- package/src/shards/_template/assets/2bf489fdb15f1734ddb4c4f32d500ec6da85c765ec7a4eb28dc6781160e7ec8c +0 -0
- package/src/shards/_template/assets/97ec4d8f75f5fa6239ee919444d6dc19fd35896bb305930c1f050ac6e0e0e6a6 +1 -0
- package/src/shards/_template/assets/a6a587a31327f936b1b04c05ade818c73fc8964260918662db43539465e27586 +0 -0
- package/src/shards/_template/assets/b4fbde0422e125b498c3dc8b9a5cc2516c8598f09e9d0e5f6b639b32f98179e6 +0 -0
- package/src/shards/_template/assets/bfa4dfc9c18979f904557ee8deab0058b8a399be10266f5fb1578b403f482fd4 +1 -0
- package/src/shards/_template/assets/ef3b7ff4fd22715771cb7d68a3977a903c5e7c3dc293542687d04b3ef3ace2cb +0 -0
- package/src/shards/_template/assets/f2db05998615ce1cb79ea96be32c168842eb6a2b34ec01feb86d36404603ee54 +0 -0
- package/src/shards/_template/assets/fef98ebb7fce6f66b26e78ac699e5c90f9bdcfaf8cabeb2b58125347eea8b4ab +0 -0
- package/src/shards/_template/behaviour/boss.as +39 -0
- package/src/shards/_template/behaviour/door.as +32 -0
- package/src/shards/_template/behaviour/hooks.json +129 -0
- package/src/shards/_template/behaviour/idle.as +75 -0
- package/src/shards/_template/behaviour/items.as +22 -0
- package/src/shards/_template/card/landscape.jpg +0 -0
- package/src/shards/_template/card/portrait.jpg +0 -0
- package/src/shards/_template/card/thumb.jpg +0 -0
- package/src/shards/_template/data/audio.json +45 -0
- package/src/shards/_template/data/bossDecision.json +83 -0
- package/src/shards/_template/data/budgets.json +70 -0
- package/src/shards/_template/data/card.json +281 -0
- package/src/shards/_template/data/clientScripts.json +987 -0
- package/src/shards/_template/data/creatures.json +65 -0
- package/src/shards/_template/data/director.json +39 -0
- package/src/shards/_template/data/encounters.json +96 -0
- package/src/shards/_template/data/items.json +172 -0
- package/src/shards/_template/data/layout.json +66 -0
- package/src/shards/_template/data/ledger.json +32 -0
- package/src/shards/_template/data/look.json +521 -0
- package/src/shards/_template/data/map.json +64 -0
- package/src/shards/_template/data/moves.json +16 -0
- package/src/shards/_template/data/placeholder.json +8 -0
- package/src/shards/_template/data/plumbing.json +32 -0
- package/src/shards/_template/data/quests.json +223 -0
- package/src/shards/_template/data/rows.json +423 -0
- package/src/shards/_template/data/skins.json +66 -0
- package/src/shards/_template/data/spawn.json +6 -0
- package/src/shards/_template/data/targets.json +150 -0
- package/src/shards/_template/data/text.json +12 -0
- package/src/shards/_template/data/ui.json +33 -0
- package/src/shards/_template/data/water.json +13 -0
- package/src/shards/_template/generators/behaviour.ts +34 -0
- package/src/shards/_template/generators/boss.ts +29 -0
- package/src/shards/_template/generators/buildOptions.ts +2 -0
- package/src/shards/_template/generators/cell.ts +224 -0
- package/src/shards/_template/generators/districts.ts +215 -0
- package/src/shards/_template/generators/farLook.ts +15 -0
- package/src/shards/_template/generators/generate.ts +27 -0
- package/src/shards/_template/generators/ground.ts +15 -0
- package/src/shards/_template/generators/kit.ts +69 -0
- package/src/shards/_template/generators/landscape.ts +59 -0
- package/src/shards/_template/generators/landscapeNoise.ts +62 -0
- package/src/shards/_template/generators/mapInputs.ts +10 -0
- package/src/shards/_template/generators/product.ts +100 -0
- package/src/shards/_template/generators/productOutput.ts +18 -0
- package/src/shards/_template/generators/props.ts +9 -0
- package/src/shards/_template/generators/templatePropsSource.ts +58 -0
- package/src/shards/_template/generators/terrain.ts +17 -0
- package/src/shards/_template/generators/world.ts +630 -0
- package/src/shards/_template/hero.json +10 -0
- package/src/shards/_template/look/entry-reads.json +20 -0
- package/src/shards/_template/manifest.json +281 -0
- package/src/shards/_template/shard.config.ts +10 -0
- package/src/shared/health.ts +10 -0
- package/src/tools/build-web.ts +59 -0
- package/src/tsconfig.json +30 -0
- package/src/web/app.tsx +53 -0
- package/src/web/index.html +12 -0
- package/src/web/main.tsx +10 -0
- package/src/web/tsconfig.json +13 -0
- package/tsconfig.author.json +23 -0
- package/tsconfig.commons.json +21 -0
- package/tsconfig.json +47 -0
- package/tsconfig.sharddev.json +20 -0
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
"""MUSIC.md v3 row 5: turn each slot's pick into the game's files - demucs stems, bar-exact loops, -18 LUFS, AAC.
|
|
2
|
+
|
|
3
|
+
~/ml/music/analysis/.venv/bin/python scripts/music/gen/stems.py <raw3-dir> [--style piano] [--pick piano/pine=minimax3-303 ...]
|
|
4
|
+
|
|
5
|
+
Reads the picks from scripts/music/gen/v3-<style>.json (rank_v3.py); --pick overrides one (after the user's veto).
|
|
6
|
+
Writes public/assets/music/<style>/ :
|
|
7
|
+
pine-calm-<h>.m4a pine-tension-<h>.m4a island-calm-<h>.m4a island-tension-<h>.m4a title-<h>.m4a
|
|
8
|
+
sting-pickup-<h>.m4a sting-death-<h>.m4a sting-chunk-<h>.m4a music.json (<h> = content hash, see 6.)
|
|
9
|
+
and scripts/music/gen/v3-<style>-build.json (every decision: grid, loop search, gains, sizes).
|
|
10
|
+
|
|
11
|
+
Per loop slot (pine / island):
|
|
12
|
+
1. htdemucs splits the take (44.1 kHz) into drums / bass / other / vocals; residual = mix - sum(stems).
|
|
13
|
+
2. calm = mix - drums - bass/2 (= other + vocals-stem + residual + bass at -6 dB; the vocals stem of an
|
|
14
|
+
instrumental take is lead-instrument bleed. If it holds a real voice - over 3 % of the energy -
|
|
15
|
+
it is dropped from calm instead.)
|
|
16
|
+
tension = drums + bass/2 so calm + tension == the original mix, sample for sample.
|
|
17
|
+
3. Beats: librosa's detected beats (MiniMax does not play to a click, so a straight-line grid drifts off them).
|
|
18
|
+
4. Loop: loopStart on a detected downbeat, loopEnd on the detected beat 4*N beats later; the manifest's bpm is
|
|
19
|
+
defined as 4N beats over that span, so the loop is exactly N bars by construction. Seam score = chroma + MFCC
|
|
20
|
+
similarity over 2 s either side of both cut points x level match; the longest loop within 0.06 of the best
|
|
21
|
+
seam wins (less repetition); length capped so a style fits 5 MB.
|
|
22
|
+
5. Seam: the last bar before loopEnd is crossfaded (equal-gain) into the bar before loopStart, so the audio at
|
|
23
|
+
loopEnd continues exactly as it did at loopStart; after loopEnd the file carries 1 bar of the loop's start,
|
|
24
|
+
faded out, for a player that runs off the end. Same operation on both stems, so they stay sample-aligned.
|
|
25
|
+
6. One gain for both stems: calm integrated loudness -> -18 LUFS; then ONE lookahead limiter curve (driven by the
|
|
26
|
+
mix and by calm alone, ceiling PEAK_DB) multiplies both stems, so peaks are caught without lowering the whole
|
|
27
|
+
loop and calm + tension is still the mix.
|
|
28
|
+
File names are content-addressed (<slot>-calm-<sha1[:8]>.m4a ...): the service worker serves audio cache-first, so
|
|
29
|
+
a changed file must never keep its old name.
|
|
30
|
+
7. AAC-LC 48 kHz: calm stereo 96 kb/s, tension MONO 64 kb/s (the phone holds both decoded: ~25 MB per stereo
|
|
31
|
+
66 s stem). Loop points are then re-measured on the DECODED files (ffmpeg honours the mp4 edit list the way
|
|
32
|
+
decodeAudioData does): the decoder lag is added to them, calm and tension must decode to the same length
|
|
33
|
+
(< 50 ms apart) and the same lag, and loopEnd must sit inside the decoded length.
|
|
34
|
+
loopStart is always a DOWNBEAT: of the 4 beat phases, the one whose beats carry the most low-band (< 200 Hz)
|
|
35
|
+
onset energy in the drums + bass stem.
|
|
36
|
+
Title: the full mix, same beats / loop / seam, -18 LUFS. Stings: CUT from the style's own takes (cut_stings: the
|
|
37
|
+
title's final chord = death, its biggest downbeat swell = chunk, the Pine Hollow take's brightest onset = pickup),
|
|
38
|
+
faded, -16 LUFS so they sit just above the score. MiniMax's own 6 s sting renders did not work (see v3-jobs.json).
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
from __future__ import annotations
|
|
42
|
+
|
|
43
|
+
import argparse
|
|
44
|
+
import json
|
|
45
|
+
import os
|
|
46
|
+
import re
|
|
47
|
+
import subprocess
|
|
48
|
+
import tempfile
|
|
49
|
+
from pathlib import Path
|
|
50
|
+
|
|
51
|
+
import librosa
|
|
52
|
+
import numpy as np
|
|
53
|
+
import soundfile as sf
|
|
54
|
+
|
|
55
|
+
HERE = Path(__file__).resolve().parent
|
|
56
|
+
REPO = HERE.parents[2]
|
|
57
|
+
OUT = REPO / "public/assets/music"
|
|
58
|
+
DEMUCS_DIR = Path(os.environ.get("DEMUCS_WEIGHTS", Path.home() / "projects/weights/manual/facebook/demucs"))
|
|
59
|
+
LICENCE = "MiniMax-Music3 Community (UI credit, < $20M)"
|
|
60
|
+
MAX_LOOP_S = 64.0 # loop body cap: 2 slots x 2 stems x ~66 s + title + stings at 96 kb/s stays under 5 MB
|
|
61
|
+
TITLE_MAX_S = 72.0
|
|
62
|
+
CALM_LUFS = -18.0
|
|
63
|
+
STING_LUFS = -16.0
|
|
64
|
+
PEAK_DB = -2.0 # sample-peak ceiling of the limiter before AAC (the encoder overshoots ~1 dB)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def lufs(x: np.ndarray, sr: int) -> tuple[float, float]:
|
|
68
|
+
"""integrated LUFS and true peak (dBFS) via ffmpeg ebur128"""
|
|
69
|
+
with tempfile.NamedTemporaryFile(suffix=".wav") as f:
|
|
70
|
+
sf.write(f.name, x.T, sr, subtype="FLOAT")
|
|
71
|
+
p = subprocess.run(["ffmpeg", "-nostats", "-hide_banner", "-i", f.name, "-filter_complex", "ebur128=peak=true",
|
|
72
|
+
"-f", "null", "-"], capture_output=True, text=True)
|
|
73
|
+
tail = p.stderr[p.stderr.rfind("Summary:"):]
|
|
74
|
+
i = re.search(r"I:\s+(-?[\d.]+) LUFS", tail)
|
|
75
|
+
pk = re.search(r"Peak:\s+(-?[\d.]+) dBFS", tail)
|
|
76
|
+
return (float(i.group(1)) if i else -70.0), (float(pk.group(1)) if pk else -70.0)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def encode(x: np.ndarray, sr: int, dest: Path, mono: bool = False, kbps: int | None = None) -> int:
|
|
80
|
+
"""AAC-LC in .m4a at 48 kHz; stereo 96 kb/s, or mono 64 kb/s (the tension stem: the phone keeps it decoded); `kbps` overrides"""
|
|
81
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
82
|
+
y = librosa.resample(x, orig_sr=sr, target_sr=48000, res_type="soxr_hq") if sr != 48000 else x # this ffmpeg has no soxr
|
|
83
|
+
if mono:
|
|
84
|
+
y = y.mean(0, keepdims=True)
|
|
85
|
+
with tempfile.NamedTemporaryFile(suffix=".wav") as f:
|
|
86
|
+
sf.write(f.name, y.T, 48000, subtype="FLOAT")
|
|
87
|
+
subprocess.run(["ffmpeg", "-y", "-loglevel", "error", "-i", f.name, "-ac", "1" if mono else "2", "-c:a", "aac",
|
|
88
|
+
"-b:a", f"{kbps}k" if kbps else ("64k" if mono else "96k"), "-movflags", "+faststart", str(dest)], check=True)
|
|
89
|
+
return dest.stat().st_size
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def decoded(path: Path) -> np.ndarray:
|
|
93
|
+
"""the file as a decoder sees it (ffmpeg honours the mp4 edit list, as browsers' decodeAudioData does), 48 kHz"""
|
|
94
|
+
p = subprocess.run(["ffmpeg", "-loglevel", "error", "-i", str(path), "-f", "f32le", "-ac", "1", "-ar", "48000", "-"],
|
|
95
|
+
capture_output=True, check=True)
|
|
96
|
+
return np.frombuffer(p.stdout, dtype=np.float32)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def decode_offset(path: Path, src: np.ndarray, sr: int) -> tuple[float, float]:
|
|
100
|
+
"""(lag of the decoded file vs the source in seconds - positive = decoded starts late, decoded length in seconds)"""
|
|
101
|
+
d = decoded(path)
|
|
102
|
+
ref = librosa.resample(src.mean(0), orig_sr=sr, target_sr=48000, res_type="soxr_hq") if sr != 48000 else src.mean(0)
|
|
103
|
+
n = min(len(d), len(ref), 48000 * 8)
|
|
104
|
+
a, b = d[:n], ref[:n].astype(np.float32)
|
|
105
|
+
c = np.fft.irfft(np.fft.rfft(a, 2 * n) * np.conj(np.fft.rfft(b, 2 * n)))
|
|
106
|
+
lag = int(np.argmax(np.concatenate([c[-4096:], c[:4096]]))) - 4096
|
|
107
|
+
return lag / 48000, len(d) / 48000
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def separate(x: np.ndarray, sr: int) -> dict[str, np.ndarray]:
|
|
111
|
+
import torch
|
|
112
|
+
from demucs.apply import apply_model
|
|
113
|
+
from demucs.pretrained import get_model
|
|
114
|
+
|
|
115
|
+
model = get_model("htdemucs", repo=DEMUCS_DIR).eval()
|
|
116
|
+
assert sr == model.samplerate, f"take is {sr} Hz, htdemucs wants {model.samplerate}"
|
|
117
|
+
with torch.no_grad():
|
|
118
|
+
st = apply_model(model, torch.from_numpy(x.astype(np.float32))[None], device="cpu", split=True, overlap=0.25, shifts=2)[0]
|
|
119
|
+
return {src: st[i].numpy() for i, src in enumerate(model.sources)}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def grid(x: np.ndarray, sr: int) -> dict:
|
|
123
|
+
"""the detected beats (librosa) - MiniMax does not play to a click, so the loop is cut on real beats, not on a
|
|
124
|
+
straight-line grid (which drifted ~0.1 s off the beats on these takes)"""
|
|
125
|
+
y = librosa.resample(x.mean(0), orig_sr=sr, target_sr=22050)
|
|
126
|
+
_, beats = librosa.beat.beat_track(y=y, sr=22050, units="time")
|
|
127
|
+
beats = np.asarray(beats, dtype=np.float64)
|
|
128
|
+
if 60 / np.median(np.diff(beats)) > 140: # tracked at double time: keep every other beat, the parity with more onset
|
|
129
|
+
env = librosa.onset.onset_strength(y=y, sr=22050)
|
|
130
|
+
fr = librosa.time_to_frames(beats, sr=22050)
|
|
131
|
+
fr = fr[fr < len(env)]
|
|
132
|
+
beats = beats[int(np.argmax([env[fr[0::2]].sum(), env[fr[1::2]].sum()]))::2]
|
|
133
|
+
ibi = np.diff(beats)
|
|
134
|
+
return {"beats": beats, "median_bpm": round(float(60 / np.median(ibi)), 2), "beats_found": int(len(beats)),
|
|
135
|
+
"ibi_cv": round(float(ibi.std() / ibi.mean()), 3)}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def downbeat(x_low: np.ndarray, sr: int, beats: np.ndarray) -> int:
|
|
139
|
+
"""which beat index mod 4 is the downbeat: the one carrying the most low-band (< 200 Hz) onset energy - kick and
|
|
140
|
+
bass land on 1. x_low is the drums + bass stem (loops) or the full mix (title)."""
|
|
141
|
+
y = librosa.resample(x_low.mean(0), orig_sr=sr, target_sr=22050)
|
|
142
|
+
S = np.abs(librosa.stft(y, n_fft=2048, hop_length=512))
|
|
143
|
+
low = S[librosa.fft_frequencies(sr=22050, n_fft=2048) < 200].sum(0)
|
|
144
|
+
onset = np.maximum(0, np.diff(low, prepend=low[0]))
|
|
145
|
+
fps = 22050 / 512
|
|
146
|
+
acc = np.zeros(4)
|
|
147
|
+
for i, t in enumerate(beats):
|
|
148
|
+
j = int(t * fps)
|
|
149
|
+
acc[i % 4] += onset[max(j - 2, 0):j + 3].max(initial=0.0)
|
|
150
|
+
return int(np.argmax(acc))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def find_loop(x: np.ndarray, sr: int, beats: np.ndarray, db: int, max_s: float) -> dict:
|
|
154
|
+
"""loopStart = a detected downbeat, loopEnd = the detected beat 4*N beats later; bpm := 4N beats / (loopEnd -
|
|
155
|
+
loopStart), so the loop is exactly N bars at the manifest's bpm by construction. Seam score = chroma + MFCC
|
|
156
|
+
similarity over 2 s either side of both cut points x level match; the longest loop within 0.06 of the best wins."""
|
|
157
|
+
y = librosa.resample(x.mean(0), orig_sr=sr, target_sr=22050)
|
|
158
|
+
hop = 512
|
|
159
|
+
fps = 22050 / hop
|
|
160
|
+
chroma = librosa.feature.chroma_cqt(y=y, sr=22050, hop_length=hop)
|
|
161
|
+
mfcc = librosa.feature.mfcc(y=y, sr=22050, n_mfcc=20, hop_length=hop)
|
|
162
|
+
mfcc = (mfcc - mfcc.mean(1, keepdims=True)) / (mfcc.std(1, keepdims=True) + 1e-6)
|
|
163
|
+
rms = librosa.feature.rms(y=y, hop_length=hop)[0]
|
|
164
|
+
feat = np.vstack([chroma, 0.5 * mfcc])
|
|
165
|
+
w = int(2.0 * fps)
|
|
166
|
+
dur = x.shape[1] / sr
|
|
167
|
+
|
|
168
|
+
def cos(a: np.ndarray, b: np.ndarray) -> float:
|
|
169
|
+
a, b = a.flatten(), b.flatten()
|
|
170
|
+
return float(np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b) + 1e-9))
|
|
171
|
+
|
|
172
|
+
cands = []
|
|
173
|
+
for i in range(len(beats)):
|
|
174
|
+
if i % 4 != db or beats[i] > 0.4 * dur:
|
|
175
|
+
continue
|
|
176
|
+
for nb in range(8, 64):
|
|
177
|
+
j = i + 4 * nb
|
|
178
|
+
if j >= len(beats):
|
|
179
|
+
break
|
|
180
|
+
a, b = beats[i], beats[j]
|
|
181
|
+
bar = (b - a) / nb
|
|
182
|
+
if b - a > max_s or b > dur - bar - 0.2 or a < bar + 0.02: # a bar before (seam) and after (tail)
|
|
183
|
+
if b - a > max_s or b > dur - bar - 0.2:
|
|
184
|
+
break
|
|
185
|
+
continue
|
|
186
|
+
ia, ib = int(a * fps), int(b * fps)
|
|
187
|
+
if ia - w < 0 or ib + w > feat.shape[1]:
|
|
188
|
+
continue
|
|
189
|
+
sim = 0.5 * (cos(feat[:, ia:ia + w], feat[:, ib:ib + w]) + cos(feat[:, ia - w:ia], feat[:, ib - w:ib]))
|
|
190
|
+
ra, rb = float(rms[ia - w:ia + w].mean()), float(rms[ib - w:ib + w].mean())
|
|
191
|
+
level = min(ra, rb) / (max(ra, rb) + 1e-9)
|
|
192
|
+
ib_ = np.diff(beats[i:j + 1])
|
|
193
|
+
cands.append({"score": round(sim * (0.7 + 0.3 * level), 4), "similarity": round(sim, 3), "level_match": round(level, 3),
|
|
194
|
+
"loopStart": float(a), "loopEnd": float(b), "bars": nb, "bpm": round(240.0 * nb / (b - a), 3),
|
|
195
|
+
"beat_jitter_s": round(float(np.abs(ib_ - (b - a) / (4 * nb)).max()), 3)})
|
|
196
|
+
top = max(c["score"] for c in cands)
|
|
197
|
+
near = [c for c in cands if c["score"] >= top - 0.06]
|
|
198
|
+
best = max(near, key=lambda c: (c["bars"], c["score"]))
|
|
199
|
+
best["best_seam_score"] = top
|
|
200
|
+
return best
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def seam(x: np.ndarray, sr: int, loop: dict, bar: float) -> tuple[np.ndarray, float]:
|
|
204
|
+
"""the file: [0, loopEnd) with the last bar crossfaded into the bar before loopStart, + 1 faded bar of the loop start"""
|
|
205
|
+
S, E, F = round(loop["loopStart"] * sr), round(loop["loopEnd"] * sr), round(bar * sr)
|
|
206
|
+
assert S >= F, "loopStart must leave one bar before it for the seam crossfade"
|
|
207
|
+
out = x[:, :E].copy()
|
|
208
|
+
ramp = np.linspace(0.0, 1.0, F, endpoint=False)[None]
|
|
209
|
+
out[:, E - F:E] = x[:, E - F:E] * (1 - ramp) + x[:, S - F:S] * ramp
|
|
210
|
+
tail = x[:, S:S + F].copy() * np.linspace(1.0, 0.0, F)[None]
|
|
211
|
+
return np.concatenate([out, tail], axis=1), (E + F) / sr
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def trim_sting(x: np.ndarray, sr: int) -> np.ndarray:
|
|
215
|
+
env = np.abs(x).max(0)
|
|
216
|
+
thr = env.max() * 10 ** (-40 / 20)
|
|
217
|
+
idx = np.where(env > thr)[0]
|
|
218
|
+
a, b = max(int(idx[0]) - int(0.01 * sr), 0), min(int(idx[-1]) + int(0.05 * sr), x.shape[1])
|
|
219
|
+
b = min(b, a + int(6.0 * sr))
|
|
220
|
+
y = x[:, a:b].copy()
|
|
221
|
+
n = int(0.15 * sr)
|
|
222
|
+
y[:, -n:] *= np.linspace(1.0, 0.0, n)[None]
|
|
223
|
+
return y
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _fade(y: np.ndarray, sr: int, fin: float, fout: float) -> np.ndarray:
|
|
227
|
+
y = y.copy()
|
|
228
|
+
a, b = int(fin * sr), int(fout * sr)
|
|
229
|
+
if a:
|
|
230
|
+
y[:, :a] *= np.linspace(0.0, 1.0, a)[None]
|
|
231
|
+
if b:
|
|
232
|
+
y[:, -b:] *= np.linspace(1.0, 0.0, b)[None] ** 1.5
|
|
233
|
+
return y
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def cut_stings(sources: dict[str, tuple[np.ndarray, dict]], sr: int) -> dict[str, tuple[np.ndarray, str, float, str]]:
|
|
237
|
+
"""three stings from the style's own takes (same instruments as the score):
|
|
238
|
+
death - the title's last 4.5 s of sound: the resolved final chord the title prompt asks for, ringing out
|
|
239
|
+
chunk - 3.5 s of the title from the downbeat with the biggest energy rise (a swell / an entrance)
|
|
240
|
+
pickup - 2 s of the Pine Hollow take from its brightest strong onset (spectral centroid x onset strength)"""
|
|
241
|
+
out: dict[str, tuple[np.ndarray, str, float, str]] = {}
|
|
242
|
+
x, loop = sources["title"]
|
|
243
|
+
env = np.abs(x).max(0)
|
|
244
|
+
last = int(np.where(env > env.max() * 10 ** (-40 / 20))[0][-1])
|
|
245
|
+
a = max(0, last - int(4.5 * sr))
|
|
246
|
+
out["death"] = (_fade(x[:, a:last], sr, 0.35, 0.6), "title", a / sr, "the final chord")
|
|
247
|
+
y = librosa.resample(x.mean(0), orig_sr=sr, target_sr=22050)
|
|
248
|
+
rms = librosa.feature.rms(y=y, hop_length=512)[0]
|
|
249
|
+
fps = 22050 / 512
|
|
250
|
+
bar = (loop["loopEnd"] - loop["loopStart"]) / loop["bars"]
|
|
251
|
+
best, t_best = -1.0, 1.0
|
|
252
|
+
t = loop["loopStart"] % bar
|
|
253
|
+
while t + 3.5 < x.shape[1] / sr - 5:
|
|
254
|
+
i = int(t * fps)
|
|
255
|
+
pre, post = rms[max(0, i - int(bar * fps)):i].mean() if i > 0 else 0.0, rms[i:i + int(bar * fps)].mean()
|
|
256
|
+
rise = post / (pre + 1e-6)
|
|
257
|
+
if t > 2 and rise > best:
|
|
258
|
+
best, t_best = rise, t
|
|
259
|
+
t += bar
|
|
260
|
+
a = int(max(0.0, t_best - 0.25) * sr)
|
|
261
|
+
out["chunk"] = (_fade(x[:, a:a + int(3.5 * sr)], sr, 0.25, 1.0), "title", a / sr, f"a {best:.1f}x swell on a downbeat")
|
|
262
|
+
xp, _ = sources["pine"]
|
|
263
|
+
yp = librosa.resample(xp.mean(0), orig_sr=sr, target_sr=22050)
|
|
264
|
+
on = librosa.onset.onset_strength(y=yp, sr=22050)
|
|
265
|
+
cen = librosa.feature.spectral_centroid(y=yp, sr=22050)[0][: len(on)]
|
|
266
|
+
score = on[: len(cen)] * cen
|
|
267
|
+
score[: int(3 * fps)] = 0
|
|
268
|
+
score[-int(4 * fps):] = 0
|
|
269
|
+
j = int(np.argmax(score))
|
|
270
|
+
a = max(0, int((j / fps - 0.03) * sr))
|
|
271
|
+
out["pickup"] = (_fade(xp[:, a:a + int(2.0 * sr)], sr, 0.01, 0.9), "pine", a / sr, "its brightest onset")
|
|
272
|
+
return out
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def limiter(sig: np.ndarray, sr: int, ceil_db: float, look_s: float = 0.005, hold_s: float = 0.12, smooth_s: float = 0.02) -> np.ndarray:
|
|
276
|
+
"""a gain curve r(t) <= 1 such that |sig * r| <= ceil everywhere: lookahead peak limiting as min-filter + moving
|
|
277
|
+
average (the min window is wider than the average window, so r never exceeds the per-sample need)"""
|
|
278
|
+
from scipy.ndimage import minimum_filter1d, uniform_filter1d
|
|
279
|
+
|
|
280
|
+
ceil = 10 ** (ceil_db / 20)
|
|
281
|
+
need = np.minimum(1.0, ceil / (np.abs(sig).max(0) + 1e-12))
|
|
282
|
+
a = max(1, int(smooth_s * sr)) | 1
|
|
283
|
+
held = minimum_filter1d(need, size=int(2 * look_s * sr + hold_s * sr + a) | 1)
|
|
284
|
+
return np.minimum(uniform_filter1d(held, size=a), need)
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def shipped_name(dest: Path, tmp: Path, stem: str) -> str:
|
|
288
|
+
"""content-addressed file name <stem>-<sha1[:8]>.m4a: the service worker serves audio cache-first, so a file whose
|
|
289
|
+
content changes must never keep its old name (a re-roll or a re-master lands under a new name automatically)"""
|
|
290
|
+
import hashlib
|
|
291
|
+
|
|
292
|
+
h = hashlib.sha1(tmp.read_bytes()).hexdigest()[:8]
|
|
293
|
+
name = f"{stem}-{h}.m4a"
|
|
294
|
+
tmp.replace(dest / name)
|
|
295
|
+
return name
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def build_style(raw: Path, style: str, overrides: dict[str, str]) -> None:
|
|
299
|
+
v3 = json.loads((HERE / f"v3-{style}.json").read_text())
|
|
300
|
+
dest = OUT / style
|
|
301
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
302
|
+
for old in dest.glob("*.m4a"): # this folder holds only this script's output
|
|
303
|
+
old.unlink()
|
|
304
|
+
tmpd = Path(tempfile.mkdtemp())
|
|
305
|
+
manifest: dict = {"style": style, "model": "MiniMax-Music3", "credit": "Music: MiniMax-Music3", "slots": {}, "stings": {}, "provenance": []}
|
|
306
|
+
report: dict = {"style": style, "slots": {}}
|
|
307
|
+
total = 0
|
|
308
|
+
|
|
309
|
+
def prov(file: str, take: dict, extra: dict | None = None) -> None:
|
|
310
|
+
manifest["provenance"].append({"file": file, "model": "MiniMaxAI/MiniMax-Music3", "diffusers": "0.40.0",
|
|
311
|
+
"prompt": take["prompt"], "lyrics": take["lyrics"], "seed": take["seed"],
|
|
312
|
+
"steps": take["steps"], "licence": LICENCE, **(extra or {})})
|
|
313
|
+
|
|
314
|
+
sources: dict[str, tuple[np.ndarray, dict]] = {}
|
|
315
|
+
sources_take: dict[str, dict] = {}
|
|
316
|
+
sr_src = 44100
|
|
317
|
+
for slot in ("pine", "island", "title"):
|
|
318
|
+
pid = overrides.get(f"{style}/{slot}") or v3["slots"][slot]["pick"]
|
|
319
|
+
take = next(t for t in v3["slots"][slot]["takes"] if t["id"] == pid)
|
|
320
|
+
x, sr = sf.read(str(raw / f"{style}-{slot}" / f"{pid}.wav"), always_2d=True)
|
|
321
|
+
x = x.T.astype(np.float64)
|
|
322
|
+
sr_src = sr
|
|
323
|
+
g = grid(x, sr)
|
|
324
|
+
st = separate(x, sr) if slot != "title" else None
|
|
325
|
+
db = downbeat(st["drums"] + st["bass"] if st else x, sr, g["beats"])
|
|
326
|
+
loop = find_loop(x, sr, g["beats"], db, MAX_LOOP_S if slot != "title" else TITLE_MAX_S)
|
|
327
|
+
bar = (loop["loopEnd"] - loop["loopStart"]) / loop["bars"]
|
|
328
|
+
g = {k: v for k, v in g.items() if k != "beats"} | {"downbeat_index_mod4": db}
|
|
329
|
+
rec = {"take": pid, "grid": g, "loop": loop}
|
|
330
|
+
sources[slot] = (x, loop)
|
|
331
|
+
sources_take[slot] = take
|
|
332
|
+
if slot == "title":
|
|
333
|
+
full, dur = seam(x, sr, loop, bar)
|
|
334
|
+
L, _ = lufs(full, sr)
|
|
335
|
+
k = 10 ** ((CALM_LUFS - L) / 20)
|
|
336
|
+
full = full * k * limiter(full * k, sr, PEAK_DB)[None]
|
|
337
|
+
encode(full, sr, tmpd / "t.m4a")
|
|
338
|
+
lag, dlen = decode_offset(tmpd / "t.m4a", full, sr)
|
|
339
|
+
name = shipped_name(dest, tmpd / "t.m4a", "title")
|
|
340
|
+
n = (dest / name).stat().st_size
|
|
341
|
+
total += n
|
|
342
|
+
manifest["slots"]["title"] = {"full": name, "bpm": loop["bpm"], "beatsPerBar": 4,
|
|
343
|
+
"loopStart": round(loop["loopStart"] + lag, 4), "loopEnd": round(loop["loopEnd"] + lag, 4),
|
|
344
|
+
"duration": round(dlen, 4)}
|
|
345
|
+
assert loop["loopEnd"] + lag <= dlen
|
|
346
|
+
rec.update(decode_lag_s=lag, decoded_s=dlen, file=name, gain_db=round(float(20 * np.log10(k)), 2), bytes=n)
|
|
347
|
+
prov(name, take, {"take": pid, "gain_db": rec["gain_db"], "limiter_ceiling_db": PEAK_DB})
|
|
348
|
+
else:
|
|
349
|
+
assert st is not None
|
|
350
|
+
resid = x - sum(st.values())
|
|
351
|
+
voice = float((st["vocals"] ** 2).sum() / ((x ** 2).sum() + 1e-12))
|
|
352
|
+
tension = st["drums"] + 0.5 * st["bass"]
|
|
353
|
+
calm = x - tension if voice <= 0.03 else st["other"] + resid + 0.5 * st["bass"]
|
|
354
|
+
calm_f, dur = seam(calm, sr, loop, bar)
|
|
355
|
+
ten_f, _ = seam(tension, sr, loop, bar)
|
|
356
|
+
L, _ = lufs(calm_f, sr)
|
|
357
|
+
k = 10 ** ((CALM_LUFS - L) / 20)
|
|
358
|
+
# one limiter curve for both stems (driven by the mix and by calm alone), so calm + tension stays the mix
|
|
359
|
+
r = np.minimum(limiter((calm_f + ten_f) * k, sr, PEAK_DB), limiter(calm_f * k, sr, PEAK_DB))[None]
|
|
360
|
+
calm_o, ten_o = calm_f * k * r, ten_f * k * r
|
|
361
|
+
encode(calm_o, sr, tmpd / "c.m4a")
|
|
362
|
+
encode(ten_o, sr, tmpd / "t.m4a", mono=True)
|
|
363
|
+
# loop points in DECODED time: measure the decoder's lag on both files; they must agree, and match in length
|
|
364
|
+
lag_c, len_c = decode_offset(tmpd / "c.m4a", calm_o, sr)
|
|
365
|
+
lag_t, len_t = decode_offset(tmpd / "t.m4a", ten_o, sr)
|
|
366
|
+
assert abs(len_c - len_t) < 0.05, f"calm {len_c:.3f}s vs tension {len_t:.3f}s"
|
|
367
|
+
assert abs(lag_c - lag_t) < 0.002, f"decode lag calm {lag_c} vs tension {lag_t}"
|
|
368
|
+
cn, tn = shipped_name(dest, tmpd / "c.m4a", f"{slot}-calm"), shipped_name(dest, tmpd / "t.m4a", f"{slot}-tension")
|
|
369
|
+
nc, nt = (dest / cn).stat().st_size, (dest / tn).stat().st_size
|
|
370
|
+
total += nc + nt
|
|
371
|
+
manifest["slots"][slot] = {"calm": cn, "tension": tn, "bpm": loop["bpm"], "beatsPerBar": 4,
|
|
372
|
+
"loopStart": round(loop["loopStart"] + lag_c, 4), "loopEnd": round(loop["loopEnd"] + lag_c, 4),
|
|
373
|
+
"duration": round(min(len_c, len_t), 4)}
|
|
374
|
+
assert loop["loopEnd"] + lag_c <= min(len_c, len_t)
|
|
375
|
+
gdb = round(float(20 * np.log10(k)), 2)
|
|
376
|
+
for f, part in ((cn, "calm: mix - drums - bass/2"), (tn, "tension: drums + bass/2 (htdemucs), mono")):
|
|
377
|
+
prov(f, take, {"take": pid, "stem": part, "gain_db": gdb, "limiter_ceiling_db": PEAK_DB})
|
|
378
|
+
share = {s_: round(float((a_ ** 2).sum() / ((x ** 2).sum() + 1e-12)), 4) for s_, a_ in st.items()}
|
|
379
|
+
rec.update(stem_share=share, voice_in_calm=voice <= 0.03, gain_db=gdb, limited_min_gain=round(float(r.min()), 3),
|
|
380
|
+
decode_lag_s={"calm": lag_c, "tension": lag_t}, decoded_s={"calm": len_c, "tension": len_t},
|
|
381
|
+
files={"calm": cn, "tension": tn}, bytes={"calm": nc, "tension": nt})
|
|
382
|
+
report["slots"][slot] = rec
|
|
383
|
+
print(f"{style}/{slot}: {pid} bpm {loop['bpm']:.1f} loop {loop['loopStart']:.2f}-{loop['loopEnd']:.2f} ({loop['bars']} bars, seam {loop['similarity']})", flush=True)
|
|
384
|
+
|
|
385
|
+
# stings are CUT from this style's own takes: MiniMax's 6 s "sting" renders came back as 6 s of mid-song band
|
|
386
|
+
# music (no silence after, and CLAP heard the wrong style in most) - see cut_stings()
|
|
387
|
+
for sting, (y, src_slot, t0, why) in cut_stings(sources, sr_src).items():
|
|
388
|
+
take = sources_take[src_slot]
|
|
389
|
+
L, _ = lufs(y, sr_src)
|
|
390
|
+
k = 10 ** ((STING_LUFS - L) / 20)
|
|
391
|
+
y = y * k * limiter(y * k, sr_src, PEAK_DB - 1.0)[None]
|
|
392
|
+
encode(y, sr_src, tmpd / "s.m4a")
|
|
393
|
+
name = shipped_name(dest, tmpd / "s.m4a", f"sting-{sting}")
|
|
394
|
+
n = (dest / name).stat().st_size
|
|
395
|
+
total += n
|
|
396
|
+
manifest["stings"][sting] = name
|
|
397
|
+
prov(name, take, {"take": take["id"], "cut_from": f"{src_slot} at {t0:.2f}s ({why})",
|
|
398
|
+
"seconds": round(y.shape[1] / sr_src, 2), "gain_db": round(float(20 * np.log10(k)), 2)})
|
|
399
|
+
report["slots"][f"sting-{sting}"] = {"from": src_slot, "take": take["id"], "at_s": round(t0, 2), "why": why, "file": name,
|
|
400
|
+
"seconds": round(y.shape[1] / sr_src, 2), "bytes": n}
|
|
401
|
+
|
|
402
|
+
(dest / "music.json").write_text(json.dumps(manifest, indent=2, ensure_ascii=False) + "\n")
|
|
403
|
+
report["total_bytes"] = total
|
|
404
|
+
(HERE / f"v3-{style}-build.json").write_text(json.dumps(report, indent=2) + "\n")
|
|
405
|
+
print(f"{style}: {total / 1e6:.2f} MB of audio -> {dest}", flush=True)
|
|
406
|
+
assert total <= 5_000_000, f"{style} is {total / 1e6:.2f} MB, over the 5 MB budget"
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
# ---------------------------------------------------------------- --set pine-hollow (PINE-HOLLOW-REMASTER PH-A1)
|
|
410
|
+
# Pine Hollow's own slots (ph-jobs.json, ranked by rank_v3.py --set pine-hollow into v3-ph-<style>.json), written to
|
|
411
|
+
# public/assets/music/pine-hollow-<style>/ with its own music.json: a folder the loading bar does not fetch for every shard
|
|
412
|
+
# (MUSIC_STYLES names only piano / orchestral / folk), so Driftwood's load is untouched and Pine Hollow fetches it itself.
|
|
413
|
+
# night calm + tension, exactly like the pine / island loops
|
|
414
|
+
# boss ONE take, three layers on one timeline: base = mix - drums - bass (stereo), bass, drums (mono). The manifest's
|
|
415
|
+
# `phases` are the layer gains per boss phase (I the Warden, II Lanterns Fall, III the Last Light); base + bass +
|
|
416
|
+
# drums == the take, sample for sample
|
|
417
|
+
# dawn the reward sting, cut from the dawn take: its last PH_STING_S of sound (the resolved chord ringing out and the
|
|
418
|
+
# phrase that lands on it), -16 LUFS like the other stings
|
|
419
|
+
PH_MAX_LOOP_S = 48.0 # a style's Pine Hollow set: night (2 stems) + boss (3) at <= 48 s + the sting stays ~2.5 MB
|
|
420
|
+
PH_STING_S = 8.0
|
|
421
|
+
PH_PHASES = {"1": [0.6, 0.0], "2": [1.0, 0.55], "3": [1.0, 1.0]} # [bass, drums] gain per phase; base is always 1
|
|
422
|
+
PH_PHASE_NAMES = {"1": "I - the Warden", "2": "II - Lanterns Fall", "3": "III - the Last Light"}
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
def build_ph_style(raw: Path, style: str, overrides: dict[str, str]) -> None:
|
|
426
|
+
v3 = json.loads((HERE / f"v3-ph-{style}.json").read_text())
|
|
427
|
+
dest = OUT / f"pine-hollow-{style}"
|
|
428
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
429
|
+
for old in dest.glob("*.m4a"): # this folder holds only this function's output
|
|
430
|
+
old.unlink()
|
|
431
|
+
tmpd = Path(tempfile.mkdtemp())
|
|
432
|
+
manifest: dict = {"style": style, "set": "pine-hollow", "model": "MiniMax-Music3", "credit": "Music: MiniMax-Music3",
|
|
433
|
+
"slots": {}, "stings": {}, "provenance": []}
|
|
434
|
+
report: dict = {"style": style, "set": "pine-hollow", "slots": {}}
|
|
435
|
+
total = 0
|
|
436
|
+
|
|
437
|
+
def prov(file: str, take: dict, extra: dict) -> None:
|
|
438
|
+
manifest["provenance"].append({"file": file, "model": "MiniMaxAI/MiniMax-Music3", "diffusers": "0.40.0", "prompt": take["prompt"],
|
|
439
|
+
"lyrics": take["lyrics"], "seed": take["seed"], "steps": take["steps"], "licence": LICENCE, **extra})
|
|
440
|
+
|
|
441
|
+
for slot in ("night", "boss", "dawn"):
|
|
442
|
+
pid = overrides.get(f"{style}/{slot}") or v3["slots"][slot]["pick"]
|
|
443
|
+
take = next(t for t in v3["slots"][slot]["takes"] if t["id"] == pid)
|
|
444
|
+
x, sr = sf.read(str(raw / f"{style}-{slot}" / f"{pid}.wav"), always_2d=True)
|
|
445
|
+
x = x.T.astype(np.float64)
|
|
446
|
+
if slot == "dawn":
|
|
447
|
+
env = np.abs(x).max(0)
|
|
448
|
+
last = int(np.where(env > env.max() * 10 ** (-40 / 20))[0][-1])
|
|
449
|
+
a = max(0, last - int(PH_STING_S * sr))
|
|
450
|
+
y = _fade(x[:, a:last], sr, 0.5, 1.2)
|
|
451
|
+
L, _ = lufs(y, sr)
|
|
452
|
+
k = 10 ** ((STING_LUFS - L) / 20)
|
|
453
|
+
y = y * k * limiter(y * k, sr, PEAK_DB - 1.0)[None]
|
|
454
|
+
encode(y, sr, tmpd / "s.m4a")
|
|
455
|
+
name = shipped_name(dest, tmpd / "s.m4a", "sting-dawn")
|
|
456
|
+
n = (dest / name).stat().st_size
|
|
457
|
+
total += n
|
|
458
|
+
manifest["stings"]["dawn"] = name
|
|
459
|
+
prov(name, take, {"take": pid, "cut_from": f"dawn at {a / sr:.2f}s (the last {PH_STING_S:.0f} s: the resolve)",
|
|
460
|
+
"seconds": round(y.shape[1] / sr, 2), "gain_db": round(float(20 * np.log10(k)), 2)})
|
|
461
|
+
report["slots"]["sting-dawn"] = {"take": pid, "at_s": round(a / sr, 2), "file": name, "bytes": n, "seconds": round(y.shape[1] / sr, 2)}
|
|
462
|
+
print(f"{style}/dawn sting: {pid} at {a / sr:.2f}s", flush=True)
|
|
463
|
+
continue
|
|
464
|
+
g = grid(x, sr)
|
|
465
|
+
st = separate(x, sr)
|
|
466
|
+
db = downbeat(st["drums"] + st["bass"], sr, g["beats"])
|
|
467
|
+
loop = find_loop(x, sr, g["beats"], db, PH_MAX_LOOP_S)
|
|
468
|
+
bar = (loop["loopEnd"] - loop["loopStart"]) / loop["bars"]
|
|
469
|
+
g = {k: v for k, v in g.items() if k != "beats"} | {"downbeat_index_mod4": db}
|
|
470
|
+
resid = x - sum(st.values())
|
|
471
|
+
voice = float((st["vocals"] ** 2).sum() / ((x ** 2).sum() + 1e-12))
|
|
472
|
+
if slot == "night":
|
|
473
|
+
layers = {"tension": st["drums"] + 0.5 * st["bass"]}
|
|
474
|
+
calm = x - layers["tension"] if voice <= 0.03 else st["other"] + resid + 0.5 * st["bass"]
|
|
475
|
+
else:
|
|
476
|
+
layers = {"bass": st["bass"], "drums": st["drums"]}
|
|
477
|
+
calm = x - st["drums"] - st["bass"] if voice <= 0.03 else st["other"] + resid
|
|
478
|
+
calm_f, _ = seam(calm, sr, loop, bar)
|
|
479
|
+
lay_f = {k: seam(v, sr, loop, bar)[0] for k, v in layers.items()}
|
|
480
|
+
L, _ = lufs(calm_f + sum(lay_f.values()) if slot == "boss" else calm_f, sr) # the boss is levelled on its full phase III mix
|
|
481
|
+
k = 10 ** ((CALM_LUFS - L) / 20)
|
|
482
|
+
r = np.minimum(limiter((calm_f + sum(lay_f.values())) * k, sr, PEAK_DB), limiter(calm_f * k, sr, PEAK_DB))[None]
|
|
483
|
+
calm_o = calm_f * k * r
|
|
484
|
+
encode(calm_o, sr, tmpd / "c.m4a")
|
|
485
|
+
lag_c, len_c = decode_offset(tmpd / "c.m4a", calm_o, sr)
|
|
486
|
+
stem = "night" if slot == "night" else "boss"
|
|
487
|
+
cn = shipped_name(dest, tmpd / "c.m4a", f"{stem}-{'calm' if slot == 'night' else 'base'}")
|
|
488
|
+
files, sizes = {"calm": cn}, {"calm": (dest / cn).stat().st_size}
|
|
489
|
+
for name_, v in lay_f.items():
|
|
490
|
+
o = v * k * r
|
|
491
|
+
encode(o, sr, tmpd / "l.m4a", mono=True)
|
|
492
|
+
lag_l, len_l = decode_offset(tmpd / "l.m4a", o, sr)
|
|
493
|
+
assert abs(len_c - len_l) < 0.05, f"{slot}: calm {len_c:.3f}s vs {name_} {len_l:.3f}s"
|
|
494
|
+
assert abs(lag_c - lag_l) < 0.002, f"{slot}: decode lag calm {lag_c} vs {name_} {lag_l}"
|
|
495
|
+
fn = shipped_name(dest, tmpd / "l.m4a", f"{stem}-{name_}")
|
|
496
|
+
files[name_], sizes[name_] = fn, (dest / fn).stat().st_size
|
|
497
|
+
total += sum(sizes.values())
|
|
498
|
+
spec = {"calm": cn, "bpm": loop["bpm"], "beatsPerBar": 4, "loopStart": round(loop["loopStart"] + lag_c, 4),
|
|
499
|
+
"loopEnd": round(loop["loopEnd"] + lag_c, 4), "duration": round(len_c, 4)}
|
|
500
|
+
assert loop["loopEnd"] + lag_c <= len_c
|
|
501
|
+
gdb = round(float(20 * np.log10(k)), 2)
|
|
502
|
+
if slot == "night":
|
|
503
|
+
spec["tension"] = files["tension"]
|
|
504
|
+
prov(cn, take, {"take": pid, "stem": "calm: mix - drums - bass/2", "gain_db": gdb})
|
|
505
|
+
prov(files["tension"], take, {"take": pid, "stem": "tension: drums + bass/2 (htdemucs), mono", "gain_db": gdb})
|
|
506
|
+
else:
|
|
507
|
+
spec["layers"] = [files["bass"], files["drums"]]
|
|
508
|
+
spec["phases"] = PH_PHASES
|
|
509
|
+
spec["phaseNames"] = PH_PHASE_NAMES
|
|
510
|
+
prov(cn, take, {"take": pid, "stem": "base: mix - drums - bass", "gain_db": gdb})
|
|
511
|
+
prov(files["bass"], take, {"take": pid, "stem": "bass (htdemucs), mono", "gain_db": gdb})
|
|
512
|
+
prov(files["drums"], take, {"take": pid, "stem": "drums (htdemucs), mono", "gain_db": gdb})
|
|
513
|
+
manifest["slots"][slot] = spec
|
|
514
|
+
share = {s_: round(float((a_ ** 2).sum() / ((x ** 2).sum() + 1e-12)), 4) for s_, a_ in st.items()}
|
|
515
|
+
report["slots"][slot] = {"take": pid, "grid": g, "loop": loop, "stem_share": share, "voice_in_calm": voice <= 0.03, "gain_db": gdb,
|
|
516
|
+
"limited_min_gain": round(float(r.min()), 3), "decode_lag_s": lag_c, "decoded_s": len_c, "files": files, "bytes": sizes}
|
|
517
|
+
print(f"{style}/{slot}: {pid} bpm {loop['bpm']:.1f} loop {loop['loopStart']:.2f}-{loop['loopEnd']:.2f} ({loop['bars']} bars, seam {loop['similarity']})", flush=True)
|
|
518
|
+
|
|
519
|
+
(dest / "music.json").write_text(json.dumps(manifest, indent=2, ensure_ascii=False) + "\n")
|
|
520
|
+
report["total_bytes"] = total
|
|
521
|
+
(HERE / f"v3-ph-{style}-build.json").write_text(json.dumps(report, indent=2) + "\n")
|
|
522
|
+
print(f"pine-hollow-{style}: {total / 1e6:.2f} MB of audio -> {dest}", flush=True)
|
|
523
|
+
assert total <= 5_000_000, f"pine-hollow-{style} is {total / 1e6:.2f} MB, over the 5 MB budget"
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
def main() -> None:
|
|
527
|
+
ap = argparse.ArgumentParser()
|
|
528
|
+
ap.add_argument("raw")
|
|
529
|
+
ap.add_argument("--style", default="piano,orchestral,folk")
|
|
530
|
+
ap.add_argument("--pick", nargs="*", default=[], help="style/slot=take-id overrides, e.g. piano/pine=minimax3-303")
|
|
531
|
+
ap.add_argument("--set", default=None, choices=["pine-hollow"], help="pine-hollow: Pine Hollow's night / boss / dawn (ph-jobs.json)")
|
|
532
|
+
args = ap.parse_args()
|
|
533
|
+
overrides = dict(p.split("=", 1) for p in args.pick)
|
|
534
|
+
for style in args.style.split(","):
|
|
535
|
+
(build_ph_style if args.set == "pine-hollow" else build_style)(Path(args.raw), style, overrides)
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
if __name__ == "__main__":
|
|
539
|
+
main()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Exercise real seam analysis for the fairground's triple meter."""
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
from analyze import loop_seam
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class LoopMeterTest(unittest.TestCase):
|
|
10
|
+
def test_waltz_and_existing_common_time(self) -> None:
|
|
11
|
+
sr = 22050
|
|
12
|
+
t = np.arange(32 * sr) / sr
|
|
13
|
+
audio = (0.1 * np.sin(2 * np.pi * 440 * t)).astype(np.float32)
|
|
14
|
+
waltz = loop_seam(audio, sr, 120, 32, 3)
|
|
15
|
+
common = loop_seam(audio, sr, 120, 32)
|
|
16
|
+
explicit = loop_seam(audio, sr, 120, 32, 4)
|
|
17
|
+
self.assertGreater(waltz["score"], 0)
|
|
18
|
+
self.assertAlmostEqual(waltz["loop_s"], waltz["bars"] * 1.5, places=2)
|
|
19
|
+
self.assertAlmostEqual(common["loop_s"], common["bars"] * 2, places=2)
|
|
20
|
+
self.assertEqual(common, explicit)
|
|
21
|
+
|
|
22
|
+
def test_invalid_meter_refuses(self) -> None:
|
|
23
|
+
for meter in (0, -1, 13, 3.5, True):
|
|
24
|
+
with self.assertRaisesRegex(ValueError, "Loop meter"):
|
|
25
|
+
loop_seam(np.zeros(1), 22050, 120, 0, meter)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
unittest.main()
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""A later valid source edit must not inherit an earlier model comparison."""
|
|
2
|
+
import hashlib
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import tempfile
|
|
6
|
+
import unittest
|
|
7
|
+
import wave
|
|
8
|
+
|
|
9
|
+
from ob7_build import REPO, read_compared_take, shared_bed, replace_output_row, publication_fit
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ComparedTakeTest(unittest.TestCase):
|
|
13
|
+
def test_below_top_five_requires_the_exact_reviewed_source_and_measurement(self) -> None:
|
|
14
|
+
match = {"rank": 6, "p": .02, "seed": "701", "sourceWaveSha256": "a" * 64,
|
|
15
|
+
"sourceMetadataSha256": "b" * 64}
|
|
16
|
+
family = 'bed.fixture.ambience'
|
|
17
|
+
decisions = {"ruling": "G872 2026-11-04", "label": "best measured, below top-5",
|
|
18
|
+
"families": {family: {"engine": "moss", **match}}}
|
|
19
|
+
self.assertEqual(publication_fit(family, 'moss', match, decisions)['label'], decisions['label'])
|
|
20
|
+
self.assertIsNone(publication_fit(family, 'moss', {**match, 'rank': 5}, {}))
|
|
21
|
+
for field, value in [('rank', 7), ('p', .03), ('seed', '702'),
|
|
22
|
+
('sourceWaveSha256', 'c' * 64), ('sourceMetadataSha256', 'd' * 64)]:
|
|
23
|
+
with self.subTest(field=field), self.assertRaisesRegex(ValueError, 'no exact fit decision'):
|
|
24
|
+
publication_fit(family, 'moss', {**match, field: value}, decisions)
|
|
25
|
+
for name, engine, decision in [('other', 'moss', decisions), (family, 'medium', decisions), (family, 'moss', {})]:
|
|
26
|
+
with self.assertRaisesRegex(ValueError, 'no exact fit decision'):
|
|
27
|
+
publication_fit(name, engine, match, decision)
|
|
28
|
+
|
|
29
|
+
def test_activation_preserves_literal_peer_keys_and_only_changes_its_row(self) -> None:
|
|
30
|
+
before = '{\n "outputs": [\n {"idea":"peer","pois":[],"pois":[1]},\n {"idea":"own","manifest":{}},\n {"idea":"later","value":2}\n ]\n}\n'
|
|
31
|
+
after = replace_output_row(before, 'own', {'idea': 'own', 'manifest': {'audio': True}})
|
|
32
|
+
self.assertIn('{"idea":"peer","pois":[],"pois":[1]}', after)
|
|
33
|
+
self.assertIn('{"idea":"later","value":2}', after)
|
|
34
|
+
self.assertEqual(json.loads(after)['outputs'][1], {'idea': 'own', 'manifest': {'audio': True}})
|
|
35
|
+
with self.assertRaisesRegex(ValueError, 'one literal output row'):
|
|
36
|
+
replace_output_row(before, 'missing', {})
|
|
37
|
+
|
|
38
|
+
def test_shared_bed_keeps_the_canonical_file_and_qualified_provenance(self) -> None:
|
|
39
|
+
source = REPO / 'public/assets/sfx/coral-drift/sfx.json'
|
|
40
|
+
data = json.loads(source.read_text())
|
|
41
|
+
original = data['beds']['coral-drift.ambience']
|
|
42
|
+
asset = source.parent / original['file']
|
|
43
|
+
entry, proof, size = shared_bed({'set': 'coral-drift', 'bed': 'coral-drift.ambience', 'gap': 'No rain'})
|
|
44
|
+
self.assertEqual(entry['file'], {'set': 'coral-drift', 'file': asset.name})
|
|
45
|
+
self.assertEqual(entry['loopStart'], original['loopStart'])
|
|
46
|
+
self.assertEqual(entry['loopEnd'], original['loopEnd'])
|
|
47
|
+
self.assertEqual(proof['reuse']['recordingSha256'], hashlib.sha256(asset.read_bytes()).hexdigest())
|
|
48
|
+
self.assertEqual(size, asset.stat().st_size)
|
|
49
|
+
self.assertLessEqual(proof['comparison'][proof['winner']]['rank'], 5)
|
|
50
|
+
with self.assertRaisesRegex(ValueError, 'confined catalogue'):
|
|
51
|
+
shared_bed({'set': '../coral-drift', 'bed': 'coral-drift.ambience', 'gap': 'No rain'})
|
|
52
|
+
with self.assertRaisesRegex(ValueError, 'direct existing recording'):
|
|
53
|
+
shared_bed({'set': 'coral-drift', 'bed': 'missing', 'gap': 'No rain'})
|
|
54
|
+
|
|
55
|
+
def test_changed_wave_or_metadata_refuses(self) -> None:
|
|
56
|
+
with tempfile.TemporaryDirectory(dir=REPO / "tmp", prefix="ob7-source-control-") as folder:
|
|
57
|
+
wav = Path(folder) / "701.wav"
|
|
58
|
+
with wave.open(str(wav), "wb") as stream:
|
|
59
|
+
stream.setparams((1, 2, 48000, 0, "NONE", "not compressed"))
|
|
60
|
+
stream.writeframes(b"\x01\x00" * 480)
|
|
61
|
+
side = wav.with_suffix(".json")
|
|
62
|
+
side.write_text(json.dumps({"seed": 701, "model": "MOSS-SoundEffect v2"}))
|
|
63
|
+
original = wav.read_bytes()
|
|
64
|
+
comparison = {"sourceWaveSha256": hashlib.sha256(original).hexdigest(),
|
|
65
|
+
"sourceMetadataSha256": hashlib.sha256(side.read_bytes()).hexdigest()}
|
|
66
|
+
self.assertEqual(read_compared_take(wav, comparison)["source"]["seed"], 701)
|
|
67
|
+
wav.write_bytes(original[:-2] + b"\x02\x00")
|
|
68
|
+
with self.assertRaisesRegex(ValueError, "source changed"):
|
|
69
|
+
read_compared_take(wav, comparison)
|
|
70
|
+
wav.write_bytes(original)
|
|
71
|
+
side.write_text(json.dumps({"seed": 702, "model": "MOSS-SoundEffect v2"}))
|
|
72
|
+
with self.assertRaisesRegex(ValueError, "source changed"):
|
|
73
|
+
read_compared_take(wav, comparison)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
unittest.main()
|