@vfrey/vfrey 0.0.1 → 1.0.0-beta.1
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/LICENSE +33 -0
- package/README.md +78 -3
- package/accounts.example.json +61 -0
- package/accounts.first-run.json +41 -0
- package/bin/vfrey.mjs +36 -0
- package/integration-tools/README.md +43 -0
- package/integration-tools/image/pillow.md +32 -0
- package/integration-tools/image/playwright.md +33 -0
- package/integration-tools/image/resvg.md +36 -0
- package/integration-tools/image/satori.md +36 -0
- package/integration-tools/image/sharp.md +38 -0
- package/integration-tools/video/blender.md +34 -0
- package/integration-tools/video/ffmpeg.md +41 -0
- package/integration-tools/video/manim.md +37 -0
- package/integration-tools/video/motion-canvas.md +37 -0
- package/integration-tools/video/remotion.md +50 -0
- package/integration-tools/video/revideo.md +32 -0
- package/package.json +74 -6
- package/skills/vfrey-orchestrator/SKILL.md +15 -0
- package/skills/vfrey-orchestrator/channel-video/SKILL.md +41 -0
- package/skills/vfrey-product/SKILL.md +63 -0
- package/skills/vfrey-product/examples/concurrency-vs-parallelism/framey/cook-one.svg +14 -0
- package/skills/vfrey-product/examples/concurrency-vs-parallelism/framey/cook-two.svg +22 -0
- package/skills/vfrey-product/examples/concurrency-vs-parallelism/framey/index.html +70 -0
- package/skills/vfrey-product/examples/concurrency-vs-parallelism/remotion/cook-one.svg +14 -0
- package/skills/vfrey-product/examples/concurrency-vs-parallelism/remotion/cook-two.svg +22 -0
- package/skills/vfrey-product/examples/concurrency-vs-parallelism/remotion/index.tsx +49 -0
- package/skills/vfrey-product/examples/concurrency-vs-parallelism/script.json +15 -0
- package/skills/vfrey-product/examples/octopus-facts/index.html +60 -0
- package/skills/vfrey-product/examples/octopus-facts/octopus.svg +8 -0
- package/skills/vfrey-product/examples/octopus-facts/script.json +14 -0
- package/skills/vfrey-product/push/SKILL.md +15 -0
- package/skills/vfrey-product/scenes/NOTICE +5 -0
- package/skills/vfrey-product/scenes/blocks.md +57 -0
- package/skills/vfrey-product/scenes/craft.md +118 -0
- package/skills/vfrey-product/scenes/motion.md +88 -0
- package/src/analytics/dashboard.ts +109 -0
- package/src/analytics/index.ts +260 -0
- package/src/api/client.ts +361 -0
- package/src/api/cloud-files.ts +197 -0
- package/src/api/cloud-runs.ts +75 -0
- package/src/api/cloud.ts +413 -0
- package/src/api/commands.ts +330 -0
- package/src/api/config.ts +34 -0
- package/src/api/creators.ts +463 -0
- package/src/api/credentials.ts +152 -0
- package/src/api/mail.ts +333 -0
- package/src/api/topics.ts +207 -0
- package/src/api/types.ts +273 -0
- package/src/cli.ts +468 -0
- package/src/cloud/bundle.ts +70 -0
- package/src/cloud/cloudrun-executor.ts +237 -0
- package/src/cloud/executor.ts +281 -0
- package/src/cloud/gcs-sign.ts +76 -0
- package/src/cloud/job.ts +106 -0
- package/src/cloud/remote-job.ts +67 -0
- package/src/cloud/render-job.ts +191 -0
- package/src/config.ts +309 -0
- package/src/dashboard-link.ts +180 -0
- package/src/dashboard-start.ts +103 -0
- package/src/desk/channel.ts +64 -0
- package/src/desk/cli.ts +216 -0
- package/src/desk/creators-route.ts +129 -0
- package/src/desk/fonts/JetBrainsMono-OFL.txt +93 -0
- package/src/desk/fonts/google-sans-flex-latin.woff2 +0 -0
- package/src/desk/fonts/jetbrains-mono-medium.woff2 +0 -0
- package/src/desk/http.ts +460 -0
- package/src/desk/mail-route.ts +103 -0
- package/src/desk/overlay.ts +112 -0
- package/src/desk/preview.ts +422 -0
- package/src/desk/screens.ts +149 -0
- package/src/desk/secrets.ts +143 -0
- package/src/desk/series.ts +127 -0
- package/src/desk/state.ts +77 -0
- package/src/desk/studio-route.ts +119 -0
- package/src/desk/tick-runner.ts +66 -0
- package/src/desk/tick.ts +56 -0
- package/src/desk/topics-route.ts +41 -0
- package/src/desk/ui/app.css +505 -0
- package/src/desk/ui/app.js +185 -0
- package/src/desk/ui/apple-icon.png +0 -0
- package/src/desk/ui/components.js +79 -0
- package/src/desk/ui/core.js +156 -0
- package/src/desk/ui/favicon.ico +0 -0
- package/src/desk/ui/icon.svg +1 -0
- package/src/desk/ui/icons.js +49 -0
- package/src/desk/ui/index.html +41 -0
- package/src/desk/ui/metrics-math.d.ts +22 -0
- package/src/desk/ui/metrics-math.js +135 -0
- package/src/desk/ui/theme.js +5 -0
- package/src/desk/ui/views-creators.js +209 -0
- package/src/desk/ui/views-keys.js +114 -0
- package/src/desk/ui/views-mail.js +188 -0
- package/src/desk/ui/views-misc.js +123 -0
- package/src/desk/ui/views-review.js +119 -0
- package/src/desk/ui/views-runs.js +350 -0
- package/src/desk/ui/views-screens.js +163 -0
- package/src/desk/ui/views-series.js +318 -0
- package/src/desk/ui/views-topics.js +87 -0
- package/src/desk/verbs.ts +361 -0
- package/src/doctor.ts +212 -0
- package/src/drain.ts +14 -0
- package/src/engage/index.ts +217 -0
- package/src/generate/index.ts +110 -0
- package/src/generate/script.ts +152 -0
- package/src/generate/title.ts +78 -0
- package/src/help.ts +252 -0
- package/src/home.ts +45 -0
- package/src/llm/client.ts +177 -0
- package/src/log.ts +7 -0
- package/src/oauth/tokens.ts +189 -0
- package/src/oauth/vault.ts +72 -0
- package/src/pipeline/review.ts +642 -0
- package/src/pipeline/run.ts +443 -0
- package/src/pipeline/series-guard.ts +26 -0
- package/src/pipeline/source-fetch.ts +69 -0
- package/src/pipeline/stages.ts +728 -0
- package/src/pipeline/topics-source.ts +90 -0
- package/src/product/commands.ts +296 -0
- package/src/product/config-file.ts +38 -0
- package/src/product/engine-choice.ts +89 -0
- package/src/product/engines.ts +103 -0
- package/src/product/insights.ts +50 -0
- package/src/product/keys.ts +67 -0
- package/src/product/paths.ts +18 -0
- package/src/product/probes.ts +88 -0
- package/src/product/push-flow.ts +90 -0
- package/src/product/render-video.ts +21 -0
- package/src/product/short.ts +62 -0
- package/src/product/update.ts +32 -0
- package/src/project/canonical.ts +14 -0
- package/src/project/commands.ts +177 -0
- package/src/project/dashboard-status.ts +28 -0
- package/src/project/discover.ts +19 -0
- package/src/project/index-file.ts +73 -0
- package/src/project/marker.ts +92 -0
- package/src/project/migrate.ts +201 -0
- package/src/project/names.ts +27 -0
- package/src/project/notice.ts +16 -0
- package/src/project/open.ts +88 -0
- package/src/project/scaffold.ts +112 -0
- package/src/project/templates.ts +42 -0
- package/src/project/videos.ts +64 -0
- package/src/publish/facebook.ts +91 -0
- package/src/publish/index.ts +12 -0
- package/src/publish/instagram.ts +97 -0
- package/src/publish/rate.ts +62 -0
- package/src/publish/session.ts +242 -0
- package/src/publish/tiktok.ts +202 -0
- package/src/publish/youtube.ts +177 -0
- package/src/queue/desk-ops.ts +1170 -0
- package/src/queue/seal.ts +3 -0
- package/src/queue/store.ts +1006 -0
- package/src/remotion/AiLabel.tsx +26 -0
- package/src/remotion/Root.tsx +73 -0
- package/src/remotion/defaults.ts +26 -0
- package/src/remotion/films/claude/ClaudeFilm.tsx +1014 -0
- package/src/remotion/films/engine/EngineMark.tsx +17 -0
- package/src/remotion/films/rea/ReaShort.tsx +552 -0
- package/src/remotion/films/rea/drawings.tsx +907 -0
- package/src/remotion/films/rea/timing.ts +144 -0
- package/src/remotion/index.ts +4 -0
- package/src/remotion/templates/EditorialSplit.tsx +39 -0
- package/src/remotion/templates/KineticType.tsx +39 -0
- package/src/remotion/templates/SignalBoard.tsx +50 -0
- package/src/remotion/timing.ts +22 -0
- package/src/render/chrome.ts +78 -0
- package/src/render/engine-mark.ts +29 -0
- package/src/render/framey-template.ts +130 -0
- package/src/render/html-engine.ts +149 -0
- package/src/render/node-crypto-stub.ts +11 -0
- package/src/render/probe.ts +29 -0
- package/src/render/props.ts +17 -0
- package/src/render/vertical-short.ts +35 -0
- package/src/render/webpack.ts +33 -0
- package/src/render/worker.ts +65 -0
- package/src/scene/assets/fonts/TitanOne-OFL.txt +94 -0
- package/src/scene/assets/fonts/titan-one.woff2 +0 -0
- package/src/scene/assets/gsap/LICENSE.txt +8 -0
- package/src/scene/assets/gsap/gsap.min.js +11 -0
- package/src/scene/audio.ts +54 -0
- package/src/scene/blocks/LICENSE +190 -0
- package/src/scene/blocks/NOTICE +5 -0
- package/src/scene/blocks/bar-chart-race/bar-chart-race.html +585 -0
- package/src/scene/blocks/beat-freeze-cut/beat-freeze-cut.html +874 -0
- package/src/scene/blocks/camcorder-hud/camcorder-hud.html +164 -0
- package/src/scene/blocks/camera-dolly-zoom/camera-dolly-zoom.html +355 -0
- package/src/scene/blocks/code-diff/code-diff.html +817 -0
- package/src/scene/blocks/code-snippet-apple-terminal-pro/code-snippet-apple-terminal-pro.html +248 -0
- package/src/scene/blocks/code-typing/code-typing.html +764 -0
- package/src/scene/blocks/data-chart/data-chart.html +452 -0
- package/src/scene/blocks/flowchart-vertical/flowchart-vertical.html +454 -0
- package/src/scene/blocks/hw-scribble-transition/hw-scribble-transition.html +153 -0
- package/src/scene/blocks/index.json +824 -0
- package/src/scene/blocks/lt-accent-underline/lt-accent-underline.html +107 -0
- package/src/scene/blocks/lt-bold-block/lt-bold-block.html +109 -0
- package/src/scene/blocks/lt-clean-bar/lt-clean-bar.html +112 -0
- package/src/scene/blocks/lt-dark-card/lt-dark-card.html +111 -0
- package/src/scene/blocks/lt-kicker-name/lt-kicker-name.html +114 -0
- package/src/scene/blocks/lt-mask-reveal/lt-mask-reveal.html +120 -0
- package/src/scene/blocks/lt-neon-border/lt-neon-border.html +391 -0
- package/src/scene/blocks/lt-stack-bars/lt-stack-bars.html +109 -0
- package/src/scene/blocks/macos-notification/macos-notification.html +194 -0
- package/src/scene/blocks/mk-background/mk-background.html +236 -0
- package/src/scene/blocks/mk-callout-highlight/mk-callout-highlight.html +183 -0
- package/src/scene/blocks/mk-clone-wall-transition/mk-clone-wall-transition.html +226 -0
- package/src/scene/blocks/mk-line-graph/mk-line-graph.html +293 -0
- package/src/scene/blocks/mk-progress-stat/mk-progress-stat.html +186 -0
- package/src/scene/blocks/mk-specs-list/mk-specs-list.html +223 -0
- package/src/scene/blocks/news-ticker/news-ticker.html +409 -0
- package/src/scene/blocks/organic-light-leak-overlay/organic-light-leak-overlay.html +126 -0
- package/src/scene/blocks/oscilloscope-trace/oscilloscope-trace.html +519 -0
- package/src/scene/blocks/snow/snow.html +205 -0
- package/src/scene/blocks/split-flap-board/split-flap-board.html +347 -0
- package/src/scene/blocks/spotify-card/spotify-card.html +294 -0
- package/src/scene/blocks/starfield/starfield.html +188 -0
- package/src/scene/blocks/thread-message-stack/thread-message-stack.html +239 -0
- package/src/scene/blocks/week-in-merges/week-in-merges.html +470 -0
- package/src/scene/blocks/x-post/x-post.html +437 -0
- package/src/scene/blocks/yt-comment-card/yt-comment-card.html +319 -0
- package/src/scene/blocks/yt-lcd-background/yt-lcd-background.html +307 -0
- package/src/scene/blocks/yt-prism-title/yt-prism-title.html +205 -0
- package/src/scene/blocks.ts +229 -0
- package/src/scene/command.ts +272 -0
- package/src/scene/figure.ts +181 -0
- package/src/scene/glyphs.ts +107 -0
- package/src/scene/init.ts +86 -0
- package/src/scene/inspect/css-tree.d.ts +6 -0
- package/src/scene/inspect/page-scripts.ts +272 -0
- package/src/scene/inspect/report.ts +405 -0
- package/src/scene/inspect/run.ts +200 -0
- package/src/scene/inspect/source.ts +236 -0
- package/src/scene/label.ts +131 -0
- package/src/scene/net-guard.ts +74 -0
- package/src/scene/render.ts +292 -0
- package/src/scene/runtime/browser.ts +199 -0
- package/src/scene/runtime/core.ts +181 -0
- package/src/scene/runtime/react.tsx +115 -0
- package/src/scene/runtime/transitions.ts +133 -0
- package/src/scene/sanitize.ts +181 -0
- package/src/scene/scene.ts +152 -0
- package/src/scene/studio-command.ts +48 -0
- package/src/scene/studio-skin.ts +59 -0
- package/src/scene/studio.ts +337 -0
- package/src/scene/supply.ts +111 -0
- package/src/scene/timing.ts +288 -0
- package/src/scene/transitions/LICENSE +190 -0
- package/src/scene/transitions/NOTICE +5 -0
- package/src/scene/transitions/SOURCE.json +24 -0
- package/src/scene/transitions/transitions.global.js +38 -0
- package/src/scene/transitions.ts +26 -0
- package/src/service/all-projects.ts +153 -0
- package/src/service/commands.ts +256 -0
- package/src/service/due.ts +82 -0
- package/src/service/lock.ts +101 -0
- package/src/service/log-file.ts +56 -0
- package/src/service/state.ts +41 -0
- package/src/service/units.ts +90 -0
- package/src/service/worker.ts +51 -0
- package/src/skill-agents.ts +74 -0
- package/src/skill-install.ts +334 -0
- package/src/sync-write.ts +21 -0
- package/src/tick-report.ts +205 -0
- package/src/tts.ts +124 -0
- package/vendor/@vfrey/contracts/dist/account.d.ts +97 -0
- package/vendor/@vfrey/contracts/dist/account.js +27 -0
- package/vendor/@vfrey/contracts/dist/checks.d.ts +8 -0
- package/vendor/@vfrey/contracts/dist/checks.js +1 -0
- package/vendor/@vfrey/contracts/dist/credentials/crypto.d.ts +4 -0
- package/vendor/@vfrey/contracts/dist/credentials/crypto.js +38 -0
- package/vendor/@vfrey/contracts/dist/domain/advice-persona.d.ts +10 -0
- package/vendor/@vfrey/contracts/dist/domain/advice-persona.js +24 -0
- package/vendor/@vfrey/contracts/dist/domain/backoff.d.ts +13 -0
- package/vendor/@vfrey/contracts/dist/domain/backoff.js +27 -0
- package/vendor/@vfrey/contracts/dist/domain/cadence.d.ts +29 -0
- package/vendor/@vfrey/contracts/dist/domain/cadence.js +95 -0
- package/vendor/@vfrey/contracts/dist/domain/creators.d.ts +146 -0
- package/vendor/@vfrey/contracts/dist/domain/creators.js +2 -0
- package/vendor/@vfrey/contracts/dist/domain/disclosure.d.ts +127 -0
- package/vendor/@vfrey/contracts/dist/domain/disclosure.js +250 -0
- package/vendor/@vfrey/contracts/dist/domain/errors.d.ts +34 -0
- package/vendor/@vfrey/contracts/dist/domain/errors.js +68 -0
- package/vendor/@vfrey/contracts/dist/domain/redact.d.ts +1 -0
- package/vendor/@vfrey/contracts/dist/domain/redact.js +21 -0
- package/vendor/@vfrey/contracts/dist/domain/revenue.d.ts +13 -0
- package/vendor/@vfrey/contracts/dist/domain/revenue.js +16 -0
- package/vendor/@vfrey/contracts/dist/domain/safety.d.ts +20 -0
- package/vendor/@vfrey/contracts/dist/domain/safety.js +61 -0
- package/vendor/@vfrey/contracts/dist/domain/similarity.d.ts +13 -0
- package/vendor/@vfrey/contracts/dist/domain/similarity.js +100 -0
- package/vendor/@vfrey/contracts/dist/domain/templates.d.ts +18 -0
- package/vendor/@vfrey/contracts/dist/domain/templates.js +67 -0
- package/vendor/@vfrey/contracts/dist/domain/tiktok-chunks.d.ts +19 -0
- package/vendor/@vfrey/contracts/dist/domain/tiktok-chunks.js +52 -0
- package/vendor/@vfrey/contracts/dist/domain/topics.d.ts +78 -0
- package/vendor/@vfrey/contracts/dist/domain/topics.js +4 -0
- package/vendor/@vfrey/contracts/dist/domain/types.d.ts +216 -0
- package/vendor/@vfrey/contracts/dist/domain/types.js +1 -0
- package/vendor/@vfrey/contracts/dist/domain/variation.d.ts +57 -0
- package/vendor/@vfrey/contracts/dist/domain/variation.js +278 -0
- package/vendor/@vfrey/contracts/dist/events.d.ts +20 -0
- package/vendor/@vfrey/contracts/dist/events.js +1 -0
- package/vendor/@vfrey/contracts/dist/http.d.ts +11 -0
- package/vendor/@vfrey/contracts/dist/http.js +37 -0
- package/vendor/@vfrey/contracts/dist/index.d.ts +22 -0
- package/vendor/@vfrey/contracts/dist/index.js +22 -0
- package/vendor/@vfrey/contracts/dist/log.d.ts +2 -0
- package/vendor/@vfrey/contracts/dist/log.js +10 -0
- package/vendor/@vfrey/contracts/dist/mail.d.ts +55 -0
- package/vendor/@vfrey/contracts/dist/mail.js +1 -0
- package/vendor/@vfrey/contracts/package.json +18 -0
- package/vendor/@vfrey/ingest/dist/index.d.ts +41 -0
- package/vendor/@vfrey/ingest/dist/index.js +221 -0
- package/vendor/@vfrey/ingest/dist/parse.d.ts +5 -0
- package/vendor/@vfrey/ingest/dist/parse.js +165 -0
- package/vendor/@vfrey/ingest/package.json +21 -0
- package/vendor/framey/LICENSE +190 -0
- package/vendor/framey/NOTICE +15 -0
- package/vendor/framey/SOURCE.json +24 -0
- package/vendor/framey/STUDIO-SOURCE.json +9 -0
- package/vendor/framey/bin/framey-localize-fonts.mjs +12 -0
- package/vendor/framey/bin/framey.mjs +16 -0
- package/vendor/framey/dist/add-VMJD5KBS.js +75 -0
- package/vendor/framey/dist/animatedGifPrep-QPKGJ6PM.js +43 -0
- package/vendor/framey/dist/api.d.ts +211 -0
- package/vendor/framey/dist/api.js +76 -0
- package/vendor/framey/dist/appHistory-WW56FZTT.js +31 -0
- package/vendor/framey/dist/asset-WQKGOELE.js +26 -0
- package/vendor/framey/dist/audio-RSJWVWRA.js +1936 -0
- package/vendor/framey/dist/batchRender-3HPICDCT.js +366 -0
- package/vendor/framey/dist/beats-HL2BDUZI.js +273 -0
- package/vendor/framey/dist/benchmark-RWCWHI5Z.js +230 -0
- package/vendor/framey/dist/browser-ECYET3Q2.js +206 -0
- package/vendor/framey/dist/bundleWithLocalizedFonts-ALYBQEQT.js +52 -0
- package/vendor/framey/dist/captureCompositionFrame-4DA6SEH2.js +94 -0
- package/vendor/framey/dist/catalog-5JVDEUWK.js +979 -0
- package/vendor/framey/dist/catch-up-NEBCL5NO.js +106 -0
- package/vendor/framey/dist/check-F5N544ML.js +111 -0
- package/vendor/framey/dist/checkBrowser-LZ66CMJG.js +110 -0
- package/vendor/framey/dist/chunk-2K7Z2HVP.js +372 -0
- package/vendor/framey/dist/chunk-2UZQHDM7.js +323 -0
- package/vendor/framey/dist/chunk-2X4PQEYM.js +34 -0
- package/vendor/framey/dist/chunk-3422KMTD.js +168 -0
- package/vendor/framey/dist/chunk-3FYD4YEK.js +72 -0
- package/vendor/framey/dist/chunk-3GXQPCJC.js +682 -0
- package/vendor/framey/dist/chunk-3LM6YPBR.js +179 -0
- package/vendor/framey/dist/chunk-442JNXRM.js +20 -0
- package/vendor/framey/dist/chunk-4BNN5FGX.js +182 -0
- package/vendor/framey/dist/chunk-4P7NX5BM.js +11532 -0
- package/vendor/framey/dist/chunk-4UMPIPCQ.js +88 -0
- package/vendor/framey/dist/chunk-4YYJOFKS.js +28 -0
- package/vendor/framey/dist/chunk-54HJ63Q2.js +29 -0
- package/vendor/framey/dist/chunk-5ETJX6WM.js +89 -0
- package/vendor/framey/dist/chunk-5SG54JRS.js +68 -0
- package/vendor/framey/dist/chunk-634HSJ3J.js +58 -0
- package/vendor/framey/dist/chunk-66LREXGS.js +48 -0
- package/vendor/framey/dist/chunk-6BEFEWFB.js +25 -0
- package/vendor/framey/dist/chunk-6BNTGNGD.js +286 -0
- package/vendor/framey/dist/chunk-6DDPOHMK.js +140 -0
- package/vendor/framey/dist/chunk-6GV5XSOR.js +214 -0
- package/vendor/framey/dist/chunk-6JR2XUEE.js +127 -0
- package/vendor/framey/dist/chunk-73QVATIM.js +362 -0
- package/vendor/framey/dist/chunk-7FMUTGOH.js +279 -0
- package/vendor/framey/dist/chunk-7JQFJ6JJ.js +291 -0
- package/vendor/framey/dist/chunk-AHPGAESX.js +113 -0
- package/vendor/framey/dist/chunk-AHX34EFP.js +15 -0
- package/vendor/framey/dist/chunk-AJ5CSAEZ.js +487 -0
- package/vendor/framey/dist/chunk-B7RJV74O.js +5047 -0
- package/vendor/framey/dist/chunk-BL4U6U52.js +254 -0
- package/vendor/framey/dist/chunk-BSQ7XANM.js +210 -0
- package/vendor/framey/dist/chunk-BZ56MTDX.js +6 -0
- package/vendor/framey/dist/chunk-C5BO7PMT.js +282 -0
- package/vendor/framey/dist/chunk-CFUCHO4T.js +358 -0
- package/vendor/framey/dist/chunk-CZGHFATT.js +31 -0
- package/vendor/framey/dist/chunk-DLA44CMS.js +5649 -0
- package/vendor/framey/dist/chunk-DPVXBVLL.js +31292 -0
- package/vendor/framey/dist/chunk-DQBY7FRR.js +397 -0
- package/vendor/framey/dist/chunk-EAMLBAHA.js +154 -0
- package/vendor/framey/dist/chunk-EOVYQ3IG.js +143 -0
- package/vendor/framey/dist/chunk-EVMY7IPL.js +612 -0
- package/vendor/framey/dist/chunk-FG4BBFZI.js +122 -0
- package/vendor/framey/dist/chunk-FI4I7CME.js +56 -0
- package/vendor/framey/dist/chunk-FLREUEHW.js +2081 -0
- package/vendor/framey/dist/chunk-FUFP7A7S.js +1126 -0
- package/vendor/framey/dist/chunk-FV3PIKGH.js +56 -0
- package/vendor/framey/dist/chunk-FXMKHHPO.js +123 -0
- package/vendor/framey/dist/chunk-GGZAM5VH.js +1187 -0
- package/vendor/framey/dist/chunk-GKZEVJIB.js +39 -0
- package/vendor/framey/dist/chunk-GMECXFAN.js +57 -0
- package/vendor/framey/dist/chunk-GNEFDLFB.js +621 -0
- package/vendor/framey/dist/chunk-GPMLSOEG.js +19274 -0
- package/vendor/framey/dist/chunk-GPYVT5EE.js +59 -0
- package/vendor/framey/dist/chunk-H6IEMZEV.js +40 -0
- package/vendor/framey/dist/chunk-HEFQCIXR.js +170 -0
- package/vendor/framey/dist/chunk-HFQ4CWHA.js +118 -0
- package/vendor/framey/dist/chunk-HPDTCOKE.js +304 -0
- package/vendor/framey/dist/chunk-HTUHQKDB.js +548 -0
- package/vendor/framey/dist/chunk-HU2SPFNG.js +103 -0
- package/vendor/framey/dist/chunk-HVW7ABXD.js +19 -0
- package/vendor/framey/dist/chunk-IG7NDKXO.js +26 -0
- package/vendor/framey/dist/chunk-II3J3WXK.js +246 -0
- package/vendor/framey/dist/chunk-IR35BCLK.js +13 -0
- package/vendor/framey/dist/chunk-ISN5GRYI.js +20 -0
- package/vendor/framey/dist/chunk-IUONB55J.js +669 -0
- package/vendor/framey/dist/chunk-IVSUQR2B.js +161 -0
- package/vendor/framey/dist/chunk-IXU6PQSW.js +259 -0
- package/vendor/framey/dist/chunk-IZCW2NKT.js +29 -0
- package/vendor/framey/dist/chunk-JGXJU5PF.js +68 -0
- package/vendor/framey/dist/chunk-JHOCK3DG.js +27 -0
- package/vendor/framey/dist/chunk-JVBRJMOP.js +121 -0
- package/vendor/framey/dist/chunk-K4MJX7SR.js +17 -0
- package/vendor/framey/dist/chunk-K4WKGXRC.js +18 -0
- package/vendor/framey/dist/chunk-KGPLIH7B.js +127 -0
- package/vendor/framey/dist/chunk-KLIKCX6Q.js +63 -0
- package/vendor/framey/dist/chunk-KXTKKBOC.js +61 -0
- package/vendor/framey/dist/chunk-KZI44OPA.js +185 -0
- package/vendor/framey/dist/chunk-LEKZNRKI.js +45 -0
- package/vendor/framey/dist/chunk-LFGJWOVA.js +61 -0
- package/vendor/framey/dist/chunk-LLMSX6V6.js +17 -0
- package/vendor/framey/dist/chunk-LTGTN2TH.js +195 -0
- package/vendor/framey/dist/chunk-M2WBOQ2Q.js +54 -0
- package/vendor/framey/dist/chunk-MI5FTLYK.js +399 -0
- package/vendor/framey/dist/chunk-MLQP2QUF.js +1809 -0
- package/vendor/framey/dist/chunk-MMQ52NIZ.js +956 -0
- package/vendor/framey/dist/chunk-ND46XKK3.js +742 -0
- package/vendor/framey/dist/chunk-NYEXNSHM.js +504 -0
- package/vendor/framey/dist/chunk-O4YRB27L.js +57 -0
- package/vendor/framey/dist/chunk-O7BGSQ5F.js +92 -0
- package/vendor/framey/dist/chunk-OFQWTKPW.js +117 -0
- package/vendor/framey/dist/chunk-P5ZBLXJ6.js +91 -0
- package/vendor/framey/dist/chunk-P6LJ4Y32.js +4662 -0
- package/vendor/framey/dist/chunk-PKZ7RK5N.js +281 -0
- package/vendor/framey/dist/chunk-PURHAXFL.js +15 -0
- package/vendor/framey/dist/chunk-Q5X2B5WT.js +29 -0
- package/vendor/framey/dist/chunk-QAMKOG67.js +248 -0
- package/vendor/framey/dist/chunk-R6YBK4XX.js +514 -0
- package/vendor/framey/dist/chunk-RGLQURIX.js +2997 -0
- package/vendor/framey/dist/chunk-RNV3DM4S.js +3573 -0
- package/vendor/framey/dist/chunk-ROEW726S.js +4638 -0
- package/vendor/framey/dist/chunk-RQVDTPGD.js +6 -0
- package/vendor/framey/dist/chunk-RVZHGOGR.js +26 -0
- package/vendor/framey/dist/chunk-RXATE6FZ.js +385 -0
- package/vendor/framey/dist/chunk-S3S4TGEH.js +424 -0
- package/vendor/framey/dist/chunk-SDYDNHEE.js +11202 -0
- package/vendor/framey/dist/chunk-SSWBU67I.js +173 -0
- package/vendor/framey/dist/chunk-ST35C4K6.js +28 -0
- package/vendor/framey/dist/chunk-SZNTYTIV.js +990 -0
- package/vendor/framey/dist/chunk-T2EUWCJE.js +29 -0
- package/vendor/framey/dist/chunk-T6AGUTZJ.js +444 -0
- package/vendor/framey/dist/chunk-THJALHFJ.js +11131 -0
- package/vendor/framey/dist/chunk-TIQB63MX.js +18128 -0
- package/vendor/framey/dist/chunk-U242RTCT.js +134 -0
- package/vendor/framey/dist/chunk-UJZREAV6.js +3901 -0
- package/vendor/framey/dist/chunk-UMD3V7CU.js +264 -0
- package/vendor/framey/dist/chunk-UOFAE5RF.js +42 -0
- package/vendor/framey/dist/chunk-UTEIUGAZ.js +29 -0
- package/vendor/framey/dist/chunk-VAS6HQX3.js +138 -0
- package/vendor/framey/dist/chunk-VC76R6W2.js +27 -0
- package/vendor/framey/dist/chunk-VFZ7W5W7.js +226 -0
- package/vendor/framey/dist/chunk-VHNLZAE2.js +348 -0
- package/vendor/framey/dist/chunk-VMC4WSH5.js +278 -0
- package/vendor/framey/dist/chunk-VORQIH64.js +108 -0
- package/vendor/framey/dist/chunk-VTXFRIHO.js +186 -0
- package/vendor/framey/dist/chunk-W2LGJSEN.js +182 -0
- package/vendor/framey/dist/chunk-WKBM7NDG.js +32 -0
- package/vendor/framey/dist/chunk-WMQNIQDJ.js +2057 -0
- package/vendor/framey/dist/chunk-WN4XZC5F.js +504 -0
- package/vendor/framey/dist/chunk-WQ6ZXHFQ.js +133 -0
- package/vendor/framey/dist/chunk-X7HBSTCZ.js +53 -0
- package/vendor/framey/dist/chunk-X7MTZ4T2.js +6 -0
- package/vendor/framey/dist/chunk-XPTOJZJF.js +308 -0
- package/vendor/framey/dist/chunk-XT6MXC7A.js +6 -0
- package/vendor/framey/dist/chunk-XT7X6QCP.js +6 -0
- package/vendor/framey/dist/chunk-XTMDWNEC.js +2820 -0
- package/vendor/framey/dist/chunk-XUHOIDKG.js +6 -0
- package/vendor/framey/dist/chunk-XX7LTW5Y.js +138 -0
- package/vendor/framey/dist/chunk-Y3YGTZEG.js +382 -0
- package/vendor/framey/dist/chunk-Y5SBSGN7.js +346 -0
- package/vendor/framey/dist/chunk-YCMVI4MZ.js +625 -0
- package/vendor/framey/dist/chunk-YOR4CTCE.js +261 -0
- package/vendor/framey/dist/chunk-YPRBGITP.js +2748 -0
- package/vendor/framey/dist/chunk-ZKDMAOFU.js +32 -0
- package/vendor/framey/dist/chunk-ZW6DURPF.js +1318 -0
- package/vendor/framey/dist/clean-ZJOGDKDM.js +336 -0
- package/vendor/framey/dist/cli.js +439 -0
- package/vendor/framey/dist/cloudrun-HGJ3B6ZV.js +767 -0
- package/vendor/framey/dist/commands/contrast-audit.browser.js +643 -0
- package/vendor/framey/dist/commands/layout-audit.browser.js +2914 -0
- package/vendor/framey/dist/commands/motion-sample.browser.js +74 -0
- package/vendor/framey/dist/commands/motion-signature.browser.js +475 -0
- package/vendor/framey/dist/compare-W7UY3BAZ.js +463 -0
- package/vendor/framey/dist/compiler-TM3W6GYF.js +136 -0
- package/vendor/framey/dist/component-QF5VGYMU.js +176 -0
- package/vendor/framey/dist/compositions-XT3PMNDF.js +238 -0
- package/vendor/framey/dist/contactSheet-7W6GYHBQ.js +24 -0
- package/vendor/framey/dist/deploy-6FJPWKF2.js +299 -0
- package/vendor/framey/dist/destroy-HE2RIPKZ.js +57 -0
- package/vendor/framey/dist/deterministicFonts-RADD3BSX.js +50 -0
- package/vendor/framey/dist/dist-4S2FGGVY.js +422 -0
- package/vendor/framey/dist/dist-BE4B2EZE.js +32 -0
- package/vendor/framey/dist/dist-EWXJGN63.js +129 -0
- package/vendor/framey/dist/docs-VKIRFEEX.js +131 -0
- package/vendor/framey/dist/doctor-2UNJ2G7U.js +74 -0
- package/vendor/framey/dist/dom-37K6YOH4.js +14 -0
- package/vendor/framey/dist/dotEnv-7PZQTVIM.js +54 -0
- package/vendor/framey/dist/events-ACY3P2PA.js +76 -0
- package/vendor/framey/dist/events-IHB3B2MK.js +69 -0
- package/vendor/framey/dist/ffmpeg-DR5LGGSK.js +63 -0
- package/vendor/framey/dist/figma-BODVUPHB.js +63 -0
- package/vendor/framey/dist/fontData.generated-NXAOI4GH.js +13 -0
- package/vendor/framey/dist/fontLocalizeCli.js +142 -0
- package/vendor/framey/dist/gpuPolicy-XLEXORZY.js +49 -0
- package/vendor/framey/dist/grade-compare-GAXFQ74C.js +661 -0
- package/vendor/framey/dist/gsapParser-IEUSLYDJ.js +2885 -0
- package/vendor/framey/dist/gsapParserAcorn-LZJKCFQI.js +30 -0
- package/vendor/framey/dist/help-VCB5X2HS.js +184 -0
- package/vendor/framey/dist/history-ENGZEVFT.js +471 -0
- package/vendor/framey/dist/hyperframe.manifest.json +22 -0
- package/vendor/framey/dist/hyperframe.runtime.iife.js +1132 -0
- package/vendor/framey/dist/hyperframes-player.global.js +478 -0
- package/vendor/framey/dist/hyperframes-slideshow.global.js +148 -0
- package/vendor/framey/dist/info-WPCJHBMU.js +182 -0
- package/vendor/framey/dist/init-G4WGLYGD.js +1176 -0
- package/vendor/framey/dist/inspect-5IQ6CNEQ.js +106 -0
- package/vendor/framey/dist/installer-ML4HWUV7.js +40 -0
- package/vendor/framey/dist/keyframes-Q6XJO7VW.js +2755 -0
- package/vendor/framey/dist/lambda-A7JC74JF.js +468 -0
- package/vendor/framey/dist/layout-YET6XNXA.js +95 -0
- package/vendor/framey/dist/lint-I7FZN2VJ.js +162 -0
- package/vendor/framey/dist/lintProject-PDB3UN72.js +30 -0
- package/vendor/framey/dist/manager-CD6LJ7ZN.js +45 -0
- package/vendor/framey/dist/manager-WA4F2GST.js +67 -0
- package/vendor/framey/dist/media-treatment-BXYS4WVA.js +1030 -0
- package/vendor/framey/dist/media-use-LWH3MANK.js +113 -0
- package/vendor/framey/dist/models-K363FYM4.js +195 -0
- package/vendor/framey/dist/motionShot-GPAVWXLH.js +640 -0
- package/vendor/framey/dist/normalize-FASIPBUM.js +24 -0
- package/vendor/framey/dist/normalize-audio-VDWYRHN6.js +268 -0
- package/vendor/framey/dist/open-E3TB6P6J.js +128 -0
- package/vendor/framey/dist/parakeetRunner-UP34UOI2.js +58 -0
- package/vendor/framey/dist/pipeline-VXIUYEBU.js +64 -0
- package/vendor/framey/dist/play-BUTDQ4DV.js +353 -0
- package/vendor/framey/dist/policies-OLDYGFK5.js +309 -0
- package/vendor/framey/dist/preflight-2KZ2GWAZ.js +55 -0
- package/vendor/framey/dist/present-GXYSM7NX.js +353 -0
- package/vendor/framey/dist/preview-EKZ33JOJ.js +1910 -0
- package/vendor/framey/dist/producer-SKU5EV3J.js +13 -0
- package/vendor/framey/dist/progress-ZWB4Z4ET.js +76 -0
- package/vendor/framey/dist/projectConfig-3MZAYVTS.js +60 -0
- package/vendor/framey/dist/publication-DTKWNF74.js +33 -0
- package/vendor/framey/dist/remove-background-OY5L7XN2.js +265 -0
- package/vendor/framey/dist/render-CDV4GDFX.js +187 -0
- package/vendor/framey/dist/render-YE5YAMOD.js +2620 -0
- package/vendor/framey/dist/render-batch-ZAMFPCLL.js +274 -0
- package/vendor/framey/dist/renderSetupWorker.js +120 -0
- package/vendor/framey/dist/resolver-D5BIPSEW.js +42 -0
- package/vendor/framey/dist/runtimeVersion.js +18 -0
- package/vendor/framey/dist/sam-WFZXI4F7.js +23 -0
- package/vendor/framey/dist/shaderTransitionWorker.js +44 -0
- package/vendor/framey/dist/sherpa-RQWLV7I3.js +79 -0
- package/vendor/framey/dist/sherpaWorker.js +84 -0
- package/vendor/framey/dist/sites-AMOVABTK.js +54 -0
- package/vendor/framey/dist/skill-ZHVLH7KX.js +15 -0
- package/vendor/framey/dist/slideshow-SJGK4RQS.js +24 -0
- package/vendor/framey/dist/snapshot-TUXL6LBQ.js +1515 -0
- package/vendor/framey/dist/src-JHQGB2S6.js +215 -0
- package/vendor/framey/dist/src-Z5PGEMXB.js +532 -0
- package/vendor/framey/dist/state-B6H3WHCF.js +28 -0
- package/vendor/framey/dist/staticProjectServer-DFVZOUGI.js +63 -0
- package/vendor/framey/dist/studio/assets/hyperframes-player-DLaKjw0L.js +478 -0
- package/vendor/framey/dist/studio/assets/index-BX3KHhGX.js +71 -0
- package/vendor/framey/dist/studio/assets/index-CYbvOVp-.css +1 -0
- package/vendor/framey/dist/studio/assets/index-Dp3QEUGL.js +402 -0
- package/vendor/framey/dist/studio/assets/index-qrTAXbqc.js +531 -0
- package/vendor/framey/dist/studio/favicon.svg +14 -0
- package/vendor/framey/dist/studio/icons/timeline/audio.svg +7 -0
- package/vendor/framey/dist/studio/icons/timeline/captions.svg +5 -0
- package/vendor/framey/dist/studio/icons/timeline/composition.svg +12 -0
- package/vendor/framey/dist/studio/icons/timeline/image.svg +18 -0
- package/vendor/framey/dist/studio/icons/timeline/music.svg +10 -0
- package/vendor/framey/dist/studio/icons/timeline/text.svg +3 -0
- package/vendor/framey/dist/studio/index.html +23 -0
- package/vendor/framey/dist/studio-api-2NECGRMB.js +179 -0
- package/vendor/framey/dist/studioSelectionClient-IUUPKUHZ.js +25 -0
- package/vendor/framey/dist/studioServer-N2OPUMOQ.js +1569 -0
- package/vendor/framey/dist/synthesize-PKTB5ATG.js +183 -0
- package/vendor/framey/dist/system-7F3UEHQT.js +27 -0
- package/vendor/framey/dist/telemetry-DQGPEKM6.js +145 -0
- package/vendor/framey/dist/telemetry-UN55N6U6.js +77 -0
- package/vendor/framey/dist/timeline-LHUUMK63.js +1295 -0
- package/vendor/framey/dist/tokens-OLECWDFK.js +92 -0
- package/vendor/framey/dist/transcribe-O7HQKMIV.js +331 -0
- package/vendor/framey/dist/transcribe-UJESPBT5.js +76 -0
- package/vendor/framey/dist/tts-YCCQHZD4.js +234 -0
- package/vendor/framey/dist/urlDownloader-H2LXLG4U.js +48 -0
- package/vendor/framey/dist/usage-HG4WMM7A.js +2167 -0
- package/vendor/framey/dist/validate-F2XMN6EV.js +87 -0
- package/vendor/framey/dist/vendor/npm/gsap@3.15.0/GSAP-LICENSE.txt +8 -0
- package/vendor/framey/dist/vendor/npm/gsap@3.15.0/dist/CustomEase.min.js +11 -0
- package/vendor/framey/dist/vendor/npm/gsap@3.15.0/dist/MotionPathPlugin.min.js +11 -0
- package/vendor/framey/dist/vendor/npm/gsap@3.15.0/dist/gsap.min.js +11 -0
- package/vendor/framey/dist/warmCheck.js +220 -0
- package/vendor/framey/dist/warmCheckClient.js +139 -0
- package/vendor/framey/dist/workspaceBuildCheck-XYD2YTFW.js +133 -0
- package/vendor/framey-player/LICENSE +190 -0
- package/vendor/framey-player/NOTICE +16 -0
- package/vendor/framey-player/SOURCE.json +6 -0
- package/vendor/framey-player/hyperframes-player.global.js +478 -0
- package/vendor/framey.pin +1 -0
- package/bin/index.js +0 -3
|
@@ -0,0 +1,1187 @@
|
|
|
1
|
+
import { createRequire as __hf_createRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __hf_fileURLToPath } from "node:url";
|
|
3
|
+
import { dirname as __hf_dirname } from "node:path";
|
|
4
|
+
var require = __hf_createRequire(import.meta.url);
|
|
5
|
+
var __filename = __hf_fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = __hf_dirname(__filename);
|
|
7
|
+
import {
|
|
8
|
+
findFfBinary
|
|
9
|
+
} from "./chunk-VAS6HQX3.js";
|
|
10
|
+
|
|
11
|
+
// src/audio/analysis/decode.ts
|
|
12
|
+
import { execFile } from "child_process";
|
|
13
|
+
import { promisify } from "util";
|
|
14
|
+
var run = promisify(execFile);
|
|
15
|
+
function requiredBinary(name) {
|
|
16
|
+
const path = findFfBinary(name, { configuredMustExist: true });
|
|
17
|
+
if (!path) throw new Error(`${name} is required to analyze audio; run: framey doctor`);
|
|
18
|
+
return path;
|
|
19
|
+
}
|
|
20
|
+
async function probeAudio(file) {
|
|
21
|
+
const { stdout } = await run(
|
|
22
|
+
requiredBinary("ffprobe"),
|
|
23
|
+
[
|
|
24
|
+
"-v",
|
|
25
|
+
"error",
|
|
26
|
+
"-select_streams",
|
|
27
|
+
"a:0",
|
|
28
|
+
"-show_streams",
|
|
29
|
+
"-show_format",
|
|
30
|
+
"-of",
|
|
31
|
+
"json",
|
|
32
|
+
"--",
|
|
33
|
+
file
|
|
34
|
+
],
|
|
35
|
+
{ maxBuffer: 8 * 1024 * 1024, windowsHide: true }
|
|
36
|
+
);
|
|
37
|
+
const parsed = JSON.parse(stdout);
|
|
38
|
+
const stream = parsed.streams?.[0];
|
|
39
|
+
if (!stream) return null;
|
|
40
|
+
return {
|
|
41
|
+
sampleRate: Number(stream.sample_rate),
|
|
42
|
+
channels: stream.channels ?? 1,
|
|
43
|
+
duration: Number(stream.duration ?? parsed.format?.duration ?? 0)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function decodeAudio(file, window = {}, probed, format = {}) {
|
|
47
|
+
const probedInfo = probed ?? await probeAudio(file);
|
|
48
|
+
if (!probedInfo) return null;
|
|
49
|
+
const info = {
|
|
50
|
+
...probedInfo,
|
|
51
|
+
sampleRate: format.sampleRate ?? probedInfo.sampleRate,
|
|
52
|
+
channels: format.mono ? 1 : probedInfo.channels
|
|
53
|
+
};
|
|
54
|
+
const seek = window.from ? ["-ss", String(window.from)] : [];
|
|
55
|
+
const length = window.seconds === void 0 ? [] : ["-t", String(window.seconds)];
|
|
56
|
+
const { stdout } = await run(
|
|
57
|
+
requiredBinary("ffmpeg"),
|
|
58
|
+
[
|
|
59
|
+
"-v",
|
|
60
|
+
"error",
|
|
61
|
+
...seek,
|
|
62
|
+
"-i",
|
|
63
|
+
file,
|
|
64
|
+
...length,
|
|
65
|
+
"-map",
|
|
66
|
+
"0:a:0",
|
|
67
|
+
...format.mono ? ["-ac", "1"] : [],
|
|
68
|
+
...format.sampleRate ? ["-ar", String(format.sampleRate)] : [],
|
|
69
|
+
"-f",
|
|
70
|
+
"f32le",
|
|
71
|
+
"-acodec",
|
|
72
|
+
"pcm_f32le",
|
|
73
|
+
"-"
|
|
74
|
+
],
|
|
75
|
+
{ encoding: "buffer", maxBuffer: 2 * 1024 * 1024 * 1024, windowsHide: true }
|
|
76
|
+
);
|
|
77
|
+
const bytes = stdout.byteLength - stdout.byteLength % 4;
|
|
78
|
+
const interleaved = new Float32Array(
|
|
79
|
+
stdout.buffer.slice(stdout.byteOffset, stdout.byteOffset + bytes)
|
|
80
|
+
);
|
|
81
|
+
const frames = Math.floor(interleaved.length / info.channels);
|
|
82
|
+
const channels = Array.from({ length: info.channels }, (_, c) => {
|
|
83
|
+
const samples = new Float32Array(frames);
|
|
84
|
+
for (let i = 0; i < frames; i++) samples[i] = interleaved[i * info.channels + c];
|
|
85
|
+
return samples;
|
|
86
|
+
});
|
|
87
|
+
return { signal: { sampleRate: info.sampleRate, channels }, stream: info };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ../core/dist/audioResample.js
|
|
91
|
+
var ZERO_CROSSINGS = 8;
|
|
92
|
+
var STEPS_PER_CROSSING = 256;
|
|
93
|
+
var CUTOFF = 0.95;
|
|
94
|
+
var KERNEL = Float64Array.from({ length: ZERO_CROSSINGS * STEPS_PER_CROSSING + 2 }, (_, i) => {
|
|
95
|
+
const x = i / STEPS_PER_CROSSING;
|
|
96
|
+
if (x >= ZERO_CROSSINGS)
|
|
97
|
+
return 0;
|
|
98
|
+
const sinc = x === 0 ? 1 : Math.sin(Math.PI * x) / (Math.PI * x);
|
|
99
|
+
return sinc * (0.5 + 0.5 * Math.cos(Math.PI * x / ZERO_CROSSINGS));
|
|
100
|
+
});
|
|
101
|
+
function kernelAt(x) {
|
|
102
|
+
const at = Math.abs(x) * STEPS_PER_CROSSING;
|
|
103
|
+
const i = Math.floor(at);
|
|
104
|
+
if (i + 1 >= KERNEL.length)
|
|
105
|
+
return 0;
|
|
106
|
+
const frac = at - i;
|
|
107
|
+
return KERNEL[i] * (1 - frac) + KERNEL[i + 1] * frac;
|
|
108
|
+
}
|
|
109
|
+
function resample(samples, from, to) {
|
|
110
|
+
if (from === to)
|
|
111
|
+
return samples;
|
|
112
|
+
const ratio = to / from;
|
|
113
|
+
const scale = Math.min(1, ratio) * CUTOFF;
|
|
114
|
+
const reach = ZERO_CROSSINGS / scale;
|
|
115
|
+
const out = new Float32Array(Math.floor(samples.length * ratio));
|
|
116
|
+
for (let n = 0; n < out.length; n++) {
|
|
117
|
+
const t = n / ratio;
|
|
118
|
+
const last = Math.min(samples.length - 1, Math.floor(t + reach));
|
|
119
|
+
let sum = 0;
|
|
120
|
+
for (let k = Math.max(0, Math.ceil(t - reach)); k <= last; k++)
|
|
121
|
+
sum += samples[k] * kernelAt((t - k) * scale);
|
|
122
|
+
out[n] = sum * scale;
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ../core/dist/fft.js
|
|
128
|
+
function fft(re, im) {
|
|
129
|
+
const n = re.length;
|
|
130
|
+
for (let i = 1, j = 0; i < n; i++) {
|
|
131
|
+
let bit = n >> 1;
|
|
132
|
+
for (; j & bit; bit >>= 1)
|
|
133
|
+
j ^= bit;
|
|
134
|
+
j ^= bit;
|
|
135
|
+
if (i < j) {
|
|
136
|
+
[re[i], re[j]] = [re[j], re[i]];
|
|
137
|
+
[im[i], im[j]] = [im[j], im[i]];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (let len = 2; len <= n; len <<= 1) {
|
|
141
|
+
const ang = -2 * Math.PI / len;
|
|
142
|
+
const wr = Math.cos(ang);
|
|
143
|
+
const wi = Math.sin(ang);
|
|
144
|
+
for (let i = 0; i < n; i += len) {
|
|
145
|
+
let cr = 1;
|
|
146
|
+
let ci = 0;
|
|
147
|
+
for (let k = 0; k < len / 2; k++) {
|
|
148
|
+
const ur = re[i + k];
|
|
149
|
+
const ui = im[i + k];
|
|
150
|
+
const vr = re[i + k + len / 2] * cr - im[i + k + len / 2] * ci;
|
|
151
|
+
const vi = re[i + k + len / 2] * ci + im[i + k + len / 2] * cr;
|
|
152
|
+
re[i + k] = ur + vr;
|
|
153
|
+
im[i + k] = ui + vi;
|
|
154
|
+
re[i + k + len / 2] = ur - vr;
|
|
155
|
+
im[i + k + len / 2] = ui - vi;
|
|
156
|
+
const ncr = cr * wr - ci * wi;
|
|
157
|
+
ci = cr * wi + ci * wr;
|
|
158
|
+
cr = ncr;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ../core/dist/audioRhythm.js
|
|
165
|
+
var ANALYSIS_RATE = 22050;
|
|
166
|
+
var FRAME_SIZE = 1024;
|
|
167
|
+
var CHROMA_SIZE = 4096;
|
|
168
|
+
var CHROMA_FPS = 10;
|
|
169
|
+
var FRAMES_PER_SECOND = 100;
|
|
170
|
+
var LOW_BAND_HZ = 150;
|
|
171
|
+
var SLOWEST_BPM = 40;
|
|
172
|
+
var FASTEST_BPM = 240;
|
|
173
|
+
var TIGHTNESS = 100;
|
|
174
|
+
var ONSET_LAG_SECONDS = 0.015;
|
|
175
|
+
var round = (t) => Math.round(t * 1e3) / 1e3;
|
|
176
|
+
function bandEdges() {
|
|
177
|
+
const binHz = ANALYSIS_RATE / FRAME_SIZE;
|
|
178
|
+
const edges = [];
|
|
179
|
+
for (let hz = 30; hz < 9e3; hz *= 2 ** (1 / 5))
|
|
180
|
+
edges.push(Math.max(1, Math.round(hz / binHz)));
|
|
181
|
+
return edges;
|
|
182
|
+
}
|
|
183
|
+
var hann = (size) => Float64Array.from({ length: size }, (_, i) => 0.5 - 0.5 * Math.cos(2 * Math.PI * i / size));
|
|
184
|
+
function addFramePower(samples, center, window, edges, into) {
|
|
185
|
+
const size = window.length;
|
|
186
|
+
const re = new Float64Array(size);
|
|
187
|
+
const im = new Float64Array(size);
|
|
188
|
+
const first = center - size / 2;
|
|
189
|
+
for (let i = 0; i < size; i++) {
|
|
190
|
+
const at = first + i;
|
|
191
|
+
re[i] = at >= 0 && at < samples.length ? samples[at] * window[i] : 0;
|
|
192
|
+
}
|
|
193
|
+
fft(re, im);
|
|
194
|
+
for (let b = 0; b + 1 < edges.length; b++) {
|
|
195
|
+
const end = Math.max(edges[b] + 1, edges[b + 1]);
|
|
196
|
+
let power = 0;
|
|
197
|
+
for (let k = edges[b]; k < end; k++)
|
|
198
|
+
power += re[k] * re[k] + im[k] * im[k];
|
|
199
|
+
into[b] += power / (size * size * (end - edges[b]));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function bandPower(channels) {
|
|
203
|
+
const window = hann(FRAME_SIZE);
|
|
204
|
+
const edges = bandEdges();
|
|
205
|
+
const hop = ANALYSIS_RATE / FRAMES_PER_SECOND;
|
|
206
|
+
const bands = [];
|
|
207
|
+
for (let f = 0; Math.round(f * hop) < (channels[0]?.length ?? 0); f++) {
|
|
208
|
+
const power = new Float64Array(edges.length - 1);
|
|
209
|
+
for (const channel of channels)
|
|
210
|
+
addFramePower(channel, Math.round(f * hop), window, edges, power);
|
|
211
|
+
bands.push(power.map((p) => Math.log1p(1e9 * p / channels.length)));
|
|
212
|
+
}
|
|
213
|
+
return bands;
|
|
214
|
+
}
|
|
215
|
+
var PITCH_CLASS = Array.from({ length: CHROMA_SIZE / 2 }, (_, bin) => {
|
|
216
|
+
const hz = bin * ANALYSIS_RATE / CHROMA_SIZE;
|
|
217
|
+
if (hz < 55 || hz > 2e3)
|
|
218
|
+
return -1;
|
|
219
|
+
return ((Math.round(12 * Math.log2(hz / 440)) + 9) % 12 + 12) % 12;
|
|
220
|
+
});
|
|
221
|
+
function chromaFrames(channels) {
|
|
222
|
+
const window = hann(CHROMA_SIZE);
|
|
223
|
+
const hop = ANALYSIS_RATE / CHROMA_FPS;
|
|
224
|
+
const re = new Float64Array(CHROMA_SIZE);
|
|
225
|
+
const im = new Float64Array(CHROMA_SIZE);
|
|
226
|
+
const frames = [];
|
|
227
|
+
for (let f = 0; Math.round(f * hop) < (channels[0]?.length ?? 0); f++) {
|
|
228
|
+
const chroma = new Float64Array(12);
|
|
229
|
+
const first = Math.round(f * hop) - CHROMA_SIZE / 2;
|
|
230
|
+
for (const channel of channels) {
|
|
231
|
+
for (let i = 0; i < CHROMA_SIZE; i++) {
|
|
232
|
+
const at = first + i;
|
|
233
|
+
re[i] = at >= 0 && at < channel.length ? channel[at] * window[i] : 0;
|
|
234
|
+
im[i] = 0;
|
|
235
|
+
}
|
|
236
|
+
fft(re, im);
|
|
237
|
+
PITCH_CLASS.forEach((pc, bin) => {
|
|
238
|
+
if (pc >= 0)
|
|
239
|
+
chroma[pc] += Math.hypot(re[bin], im[bin]);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
frames.push(chroma);
|
|
243
|
+
}
|
|
244
|
+
return frames;
|
|
245
|
+
}
|
|
246
|
+
function bandFrames(signal) {
|
|
247
|
+
const channels = signal.channels.map((c) => resample(c, signal.sampleRate, ANALYSIS_RATE));
|
|
248
|
+
return {
|
|
249
|
+
fps: FRAMES_PER_SECOND,
|
|
250
|
+
bands: bandPower(channels),
|
|
251
|
+
chroma: chromaFrames(channels),
|
|
252
|
+
chromaFps: CHROMA_FPS
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function aboveLocalMean(curve, radius) {
|
|
256
|
+
const sums = new Float64Array(curve.length + 1);
|
|
257
|
+
for (let i = 0; i < curve.length; i++)
|
|
258
|
+
sums[i + 1] = sums[i] + curve[i];
|
|
259
|
+
return curve.map((value, i) => {
|
|
260
|
+
const from = Math.max(0, i - radius);
|
|
261
|
+
const to = Math.min(curve.length, i + radius + 1);
|
|
262
|
+
return Math.max(0, value - (sums[to] - sums[from]) / (to - from));
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
function standardized(curve) {
|
|
266
|
+
const mean2 = curve.reduce((a, b) => a + b, 0) / (curve.length || 1);
|
|
267
|
+
const spread = Math.sqrt(curve.reduce((a, v) => a + (v - mean2) ** 2, 0) / (curve.length || 1));
|
|
268
|
+
return spread > 0 ? curve.map((v) => v / spread) : curve.map(() => 0);
|
|
269
|
+
}
|
|
270
|
+
function onsetCurves({ fps, bands }) {
|
|
271
|
+
const lowBands = bandEdges().filter((bin) => bin * ANALYSIS_RATE / FRAME_SIZE < LOW_BAND_HZ).length;
|
|
272
|
+
const broad = new Float64Array(bands.length);
|
|
273
|
+
const low = new Float64Array(bands.length);
|
|
274
|
+
for (let f = 1; f < bands.length; f++) {
|
|
275
|
+
const frame = bands[f];
|
|
276
|
+
const previous = bands[f - 1];
|
|
277
|
+
for (let b = 0; b < frame.length; b++) {
|
|
278
|
+
const rise = Math.max(0, frame[b] - previous[b]);
|
|
279
|
+
broad[f] += rise;
|
|
280
|
+
if (b < lowBands)
|
|
281
|
+
low[f] += rise;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const radius = Math.round(0.4 * fps);
|
|
285
|
+
return {
|
|
286
|
+
fps,
|
|
287
|
+
broad: standardized(aboveLocalMean(broad, radius)),
|
|
288
|
+
low: standardized(aboveLocalMean(low, radius))
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
function autocorrelation(curve, maxLag) {
|
|
292
|
+
const mean2 = curve.reduce((a, b) => a + b, 0) / (curve.length || 1);
|
|
293
|
+
const centred = curve.map((v) => v - mean2);
|
|
294
|
+
const ac = new Float64Array(maxLag + 1);
|
|
295
|
+
for (let lag = 0; lag <= maxLag && lag < centred.length; lag++) {
|
|
296
|
+
let sum = 0;
|
|
297
|
+
for (let i = lag; i < centred.length; i++)
|
|
298
|
+
sum += centred[i] * centred[i - lag];
|
|
299
|
+
ac[lag] = sum;
|
|
300
|
+
}
|
|
301
|
+
const zero = ac[0] || 1;
|
|
302
|
+
return ac.map((v) => v / zero);
|
|
303
|
+
}
|
|
304
|
+
var tempoPrior = (lag, fps) => Math.exp(-0.5 * (Math.log2(60 / (lag / fps) / 120) / 0.8) ** 2);
|
|
305
|
+
var fullRange = (fps) => ({
|
|
306
|
+
shortest: Math.max(1, Math.floor(60 / FASTEST_BPM * fps)),
|
|
307
|
+
longest: Math.ceil(60 / SLOWEST_BPM * fps)
|
|
308
|
+
});
|
|
309
|
+
function beatPeriod(curve, fps, { shortest, longest } = fullRange(fps)) {
|
|
310
|
+
const ac = autocorrelation(curve, 2 * longest + 1);
|
|
311
|
+
const at = (lag) => ac[Math.min(ac.length - 1, Math.max(0, lag))];
|
|
312
|
+
const score = (lag) => tempoPrior(lag, fps) * (at(lag) + 0.5 * at(2 * lag) + 0.25 * (at(2 * lag - 1) + at(2 * lag + 1)));
|
|
313
|
+
let best = shortest;
|
|
314
|
+
for (let lag = shortest; lag <= longest; lag++)
|
|
315
|
+
if (score(lag) > score(best))
|
|
316
|
+
best = lag;
|
|
317
|
+
const [a, b, c] = [score(best - 1), score(best), score(best + 1)];
|
|
318
|
+
const curvature = a - 2 * b + c;
|
|
319
|
+
const shift = curvature ? Math.max(-0.5, Math.min(0.5, 0.5 * (a - c) / curvature)) : 0;
|
|
320
|
+
return { period: best + shift, clarity: Math.max(0, Math.min(1, at(best))) };
|
|
321
|
+
}
|
|
322
|
+
function smoothed(curve, period) {
|
|
323
|
+
const half = Math.max(1, Math.round(period / 8));
|
|
324
|
+
const kernel = Array.from({ length: 2 * half + 1 }, (_, i) => Math.exp(-0.5 * ((i - half) * 32 / period) ** 2));
|
|
325
|
+
return curve.map((_, i) => {
|
|
326
|
+
let sum = 0;
|
|
327
|
+
for (let j = 0; j < kernel.length; j++)
|
|
328
|
+
sum += kernel[j] * (curve[i + j - half] ?? 0);
|
|
329
|
+
return sum;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
function cumulativeScore(local, periodAt) {
|
|
333
|
+
const score = new Float64Array(local.length);
|
|
334
|
+
const back = new Int32Array(local.length).fill(-1);
|
|
335
|
+
for (let i = 0; i < local.length; i++) {
|
|
336
|
+
const period = periodAt(i);
|
|
337
|
+
let best = -Infinity;
|
|
338
|
+
let from = -1;
|
|
339
|
+
for (let j = Math.max(0, Math.round(i - 2 * period)); j <= i - Math.round(period / 2); j++) {
|
|
340
|
+
const candidate = score[j] - TIGHTNESS * Math.log((i - j) / period) ** 2;
|
|
341
|
+
if (candidate > best)
|
|
342
|
+
[best, from] = [candidate, j];
|
|
343
|
+
}
|
|
344
|
+
score[i] = local[i] + Math.max(0, best);
|
|
345
|
+
back[i] = best > 0 ? from : -1;
|
|
346
|
+
}
|
|
347
|
+
return { score, back };
|
|
348
|
+
}
|
|
349
|
+
function lastBeat(score) {
|
|
350
|
+
const maxima = [];
|
|
351
|
+
for (let i = 1; i + 1 < score.length; i++)
|
|
352
|
+
if (score[i] > score[i - 1] && score[i] >= score[i + 1])
|
|
353
|
+
maxima.push(i);
|
|
354
|
+
if (!maxima.length)
|
|
355
|
+
return score.length - 1;
|
|
356
|
+
const median = maxima.map((i) => score[i]).sort((a, b) => a - b)[maxima.length >> 1];
|
|
357
|
+
for (let k = maxima.length - 1; k >= 0; k--)
|
|
358
|
+
if (score[maxima[k]] >= 0.5 * median)
|
|
359
|
+
return maxima[k];
|
|
360
|
+
return maxima[maxima.length - 1];
|
|
361
|
+
}
|
|
362
|
+
function trimmed(beats, local) {
|
|
363
|
+
const rms = Math.sqrt(beats.reduce((a, b) => a + local[b] ** 2, 0) / (beats.length || 1));
|
|
364
|
+
let first = 0;
|
|
365
|
+
let end = beats.length;
|
|
366
|
+
while (first < end && local[beats[first]] < 0.5 * rms)
|
|
367
|
+
first++;
|
|
368
|
+
while (end > first && local[beats[end - 1]] < 0.5 * rms)
|
|
369
|
+
end--;
|
|
370
|
+
return beats.slice(first, end);
|
|
371
|
+
}
|
|
372
|
+
var LOCAL_WINDOW_SECONDS = 8;
|
|
373
|
+
function localPeriods(curve, fps, period) {
|
|
374
|
+
const window = Math.round(LOCAL_WINDOW_SECONDS * fps);
|
|
375
|
+
const hop = Math.round(fps);
|
|
376
|
+
const range = {
|
|
377
|
+
shortest: Math.max(fullRange(fps).shortest, Math.floor(period * 0.9)),
|
|
378
|
+
longest: Math.min(fullRange(fps).longest, Math.ceil(period * 1.1))
|
|
379
|
+
};
|
|
380
|
+
const centres = [];
|
|
381
|
+
const periods = [];
|
|
382
|
+
for (let start = 0; start === 0 || start + window <= curve.length; start += hop) {
|
|
383
|
+
const end = Math.min(curve.length, start + window);
|
|
384
|
+
periods.push(beatPeriod(curve.subarray(start, end), fps, range).period);
|
|
385
|
+
centres.push((start + end) / 2);
|
|
386
|
+
}
|
|
387
|
+
const median = periods.map((_, i) => {
|
|
388
|
+
const near = periods.slice(Math.max(0, i - 2), i + 3).sort((a, b) => a - b);
|
|
389
|
+
return near[near.length >> 1];
|
|
390
|
+
});
|
|
391
|
+
return (frame) => interpolate(centres, median, frame);
|
|
392
|
+
}
|
|
393
|
+
function interpolate(xs, ys, x) {
|
|
394
|
+
if (x <= xs[0])
|
|
395
|
+
return ys[0];
|
|
396
|
+
for (let i = 1; i < xs.length; i++)
|
|
397
|
+
if (x <= xs[i]) {
|
|
398
|
+
const t = (x - xs[i - 1]) / (xs[i] - xs[i - 1]);
|
|
399
|
+
return ys[i - 1] * (1 - t) + ys[i] * t;
|
|
400
|
+
}
|
|
401
|
+
return ys[ys.length - 1];
|
|
402
|
+
}
|
|
403
|
+
function beatFrames(curve, fps, period) {
|
|
404
|
+
const local = smoothed(curve, period);
|
|
405
|
+
const { score, back } = cumulativeScore(local, localPeriods(curve, fps, period));
|
|
406
|
+
const beats = [];
|
|
407
|
+
for (let i = lastBeat(score); i >= 0; i = back[i])
|
|
408
|
+
beats.push(i);
|
|
409
|
+
return { frames: trimmed(beats.reverse(), local), local };
|
|
410
|
+
}
|
|
411
|
+
function onsetLift(frames, local) {
|
|
412
|
+
const overall = local.reduce((a, b) => a + b, 0) / (local.length || 1);
|
|
413
|
+
const onBeats = frames.reduce((a, f) => a + local[f], 0) / (frames.length || 1);
|
|
414
|
+
return overall > 0 ? onBeats / overall - 1 : 0;
|
|
415
|
+
}
|
|
416
|
+
var mean = (values) => values.reduce((a, b) => a + b, 0) / (values.length || 1);
|
|
417
|
+
function zScored(values) {
|
|
418
|
+
const centre = mean(values);
|
|
419
|
+
const spread = Math.sqrt(mean(values.map((v) => (v - centre) ** 2))) || 1;
|
|
420
|
+
return values.map((v) => (v - centre) / spread);
|
|
421
|
+
}
|
|
422
|
+
var CHROMA_REACH_SECONDS = CHROMA_SIZE / 2 / ANALYSIS_RATE;
|
|
423
|
+
function chromaBetween({ chroma, chromaFps }, from, to) {
|
|
424
|
+
const middle = Math.round((from + to) / 2 * chromaFps);
|
|
425
|
+
let first = Math.ceil(from * chromaFps);
|
|
426
|
+
let end = Math.floor((to - CHROMA_REACH_SECONDS) * chromaFps) + 1;
|
|
427
|
+
if (end <= first)
|
|
428
|
+
[first, end] = [middle, middle + 1];
|
|
429
|
+
const sum = new Array(12).fill(0);
|
|
430
|
+
for (let f = first; f < end; f++)
|
|
431
|
+
for (let c = 0; c < 12; c++)
|
|
432
|
+
sum[c] += chroma[f]?.[c] ?? 0;
|
|
433
|
+
const length = Math.hypot(...sum) || 1;
|
|
434
|
+
return sum.map((v) => v / length);
|
|
435
|
+
}
|
|
436
|
+
var cosine = (a, b) => a.reduce((sum, v, i) => sum + v * b[i], 0);
|
|
437
|
+
function harmonicChange(beats, fps, frames, span) {
|
|
438
|
+
return beats.map((f, k) => {
|
|
439
|
+
if (k < span || k + span >= beats.length)
|
|
440
|
+
return 0;
|
|
441
|
+
const before = chromaBetween(frames, beats[k - span] / fps, f / fps);
|
|
442
|
+
return 1 - cosine(before, chromaBetween(frames, f / fps, beats[k + span] / fps));
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
function barStartEvidence(beats, curves, frames) {
|
|
446
|
+
const lowHit = (f) => Math.max(...[-1, 0, 1, 2].map((d) => curves.low[f + d] ?? 0));
|
|
447
|
+
const cues = [
|
|
448
|
+
zScored(beats.map(lowHit)),
|
|
449
|
+
zScored(harmonicChange(beats, curves.fps, frames, 1)),
|
|
450
|
+
zScored(harmonicChange(beats, curves.fps, frames, 2))
|
|
451
|
+
];
|
|
452
|
+
return beats.map((_, k) => cues.reduce((sum, cue) => sum + cue[k], 0));
|
|
453
|
+
}
|
|
454
|
+
var TRIPLE_METER_HANDICAP = 0.7;
|
|
455
|
+
function barPhase(beats, curves, frames) {
|
|
456
|
+
const evidence = barStartEvidence(beats, curves, frames);
|
|
457
|
+
let best = { meter: 4, phase: 0, contrast: -Infinity };
|
|
458
|
+
for (const meter of [4, 3])
|
|
459
|
+
for (let phase = 0; phase < meter; phase++) {
|
|
460
|
+
const on = evidence.filter((_, k) => (k - phase) % meter === 0);
|
|
461
|
+
const off = evidence.filter((_, k) => (k - phase) % meter !== 0);
|
|
462
|
+
const contrast = (mean(on) - mean(off)) * (meter === 3 ? TRIPLE_METER_HANDICAP : 1);
|
|
463
|
+
if (contrast > best.contrast)
|
|
464
|
+
best = { meter, phase, contrast };
|
|
465
|
+
}
|
|
466
|
+
return best;
|
|
467
|
+
}
|
|
468
|
+
function downbeatsOf(beatList, times, curves, frames) {
|
|
469
|
+
const bar = beatList.length >= 6 ? barPhase(beatList, curves, frames) : null;
|
|
470
|
+
return {
|
|
471
|
+
times: bar ? times.filter((_, k) => (k - bar.phase) % bar.meter === 0) : [],
|
|
472
|
+
meter: bar?.meter ?? null,
|
|
473
|
+
confidence: "low"
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
function medianInterval(times) {
|
|
477
|
+
const gaps = times.slice(1).map((t, i) => t - times[i]).sort((a, b) => a - b);
|
|
478
|
+
return gaps.length ? gaps[gaps.length >> 1] : null;
|
|
479
|
+
}
|
|
480
|
+
var noRhythm = (confidence, reason = "no steady beat") => ({
|
|
481
|
+
beats: { times: [], confidence, reason },
|
|
482
|
+
downbeats: { times: [], meter: null, confidence: "low" }
|
|
483
|
+
});
|
|
484
|
+
var SHORTEST_SECONDS = 6;
|
|
485
|
+
var STEADY_BEAT_CONFIDENCE = 0.15;
|
|
486
|
+
var beatConfidence = (clarity, lift) => round(Math.max(0, Math.min(1, clarity)) * Math.max(0, Math.min(1, lift / 3)));
|
|
487
|
+
function rhythmOf(frames) {
|
|
488
|
+
const curves = onsetCurves(frames);
|
|
489
|
+
const { period, clarity } = beatPeriod(curves.broad, curves.fps);
|
|
490
|
+
if (curves.broad.length < SHORTEST_SECONDS * curves.fps)
|
|
491
|
+
return noRhythm(0, "too short for a steady beat");
|
|
492
|
+
if (!curves.broad.some((v) => v > 0) || curves.broad.length < 2 * period)
|
|
493
|
+
return noRhythm(0);
|
|
494
|
+
const { frames: beatList, local } = beatFrames(curves.broad, curves.fps, period);
|
|
495
|
+
const confidence = beatConfidence(clarity, onsetLift(beatList, local));
|
|
496
|
+
if (beatList.length < 4 || confidence < STEADY_BEAT_CONFIDENCE)
|
|
497
|
+
return noRhythm(confidence);
|
|
498
|
+
const times = beatList.map((f) => round(f / curves.fps + ONSET_LAG_SECONDS));
|
|
499
|
+
return { beats: { times, confidence }, downbeats: downbeatsOf(beatList, times, curves, frames) };
|
|
500
|
+
}
|
|
501
|
+
var TEMPO_STEP_SECONDS = 4;
|
|
502
|
+
function steadyInterval(times) {
|
|
503
|
+
const median = medianInterval(times);
|
|
504
|
+
if (!median)
|
|
505
|
+
return null;
|
|
506
|
+
const near = times.slice(1).map((t, i) => t - times[i]).filter((gap) => Math.abs(gap - median) <= 0.1 * median);
|
|
507
|
+
return near.reduce((a, b) => a + b, 0) / near.length;
|
|
508
|
+
}
|
|
509
|
+
function tempoOf(times) {
|
|
510
|
+
const interval = steadyInterval(times);
|
|
511
|
+
if (!interval)
|
|
512
|
+
return { value: null, curve: [] };
|
|
513
|
+
const bpm = (gap) => Math.round(600 / gap) / 10;
|
|
514
|
+
const curve = [];
|
|
515
|
+
const last = times[times.length - 1];
|
|
516
|
+
for (let t = times[0]; t <= last; t += TEMPO_STEP_SECONDS) {
|
|
517
|
+
const gap = steadyInterval(times.filter((b) => Math.abs(b - t) <= TEMPO_STEP_SECONDS));
|
|
518
|
+
if (gap)
|
|
519
|
+
curve.push({ t: round(t), bpm: bpm(gap) });
|
|
520
|
+
}
|
|
521
|
+
return { value: bpm(interval), curve };
|
|
522
|
+
}
|
|
523
|
+
var measured = /* @__PURE__ */ new WeakMap();
|
|
524
|
+
function bandFramesOf(signal) {
|
|
525
|
+
let entry = measured.get(signal);
|
|
526
|
+
if (!entry)
|
|
527
|
+
measured.set(signal, entry = { frames: bandFrames(signal) });
|
|
528
|
+
return entry.frames;
|
|
529
|
+
}
|
|
530
|
+
function rhythm(signal) {
|
|
531
|
+
const frames = bandFramesOf(signal);
|
|
532
|
+
const entry = measured.get(signal);
|
|
533
|
+
return entry.rhythm ??= rhythmOf(frames);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// ../core/dist/audioAnalysisLadder.js
|
|
537
|
+
function defaultLadder(capability, providers) {
|
|
538
|
+
return providers.filter((p) => p.capabilities.includes(capability)).map((p) => p.id);
|
|
539
|
+
}
|
|
540
|
+
function exclusion(provider, quality) {
|
|
541
|
+
if (quality === "fast" && !provider.signal)
|
|
542
|
+
return "quality fast allows signal processing only";
|
|
543
|
+
if (quality === "local" && !provider.local)
|
|
544
|
+
return "quality local keeps audio on this machine";
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
var message = (error) => error instanceof Error ? error.message : String(error);
|
|
548
|
+
async function availabilityOf(provider) {
|
|
549
|
+
try {
|
|
550
|
+
return provider.available ? await provider.available() : { ok: true };
|
|
551
|
+
} catch (error) {
|
|
552
|
+
return { ok: false, reason: message(error) };
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
async function blocked(id, candidate, capability, quality) {
|
|
556
|
+
if (!candidate?.capabilities.includes(capability))
|
|
557
|
+
return { provider: id, outcome: "unavailable", reason: `no provider ${id} for ${capability}` };
|
|
558
|
+
const excluded = exclusion(candidate, quality);
|
|
559
|
+
if (excluded)
|
|
560
|
+
return { provider: id, outcome: "excluded", reason: excluded };
|
|
561
|
+
const availability = await availabilityOf(candidate);
|
|
562
|
+
if (!availability.ok)
|
|
563
|
+
return { provider: id, outcome: "unavailable", reason: availability.reason };
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
function passedOver(capability, steps, answered) {
|
|
567
|
+
const skipped = steps.filter((s) => s.outcome === "unavailable" || s.outcome === "failed");
|
|
568
|
+
if (!skipped.length)
|
|
569
|
+
return null;
|
|
570
|
+
const why = skipped.map((s) => `${s.provider} ${s.outcome}${s.reason ? ` (${s.reason})` : ""}`).join("; ");
|
|
571
|
+
return answered ? `${capability}: used ${answered}; ${why}` : `${capability}: ${why}`;
|
|
572
|
+
}
|
|
573
|
+
async function runLadder(capability, input, providers, { quality = "best", ladder, provider, options = {} } = {}) {
|
|
574
|
+
const byId = new Map(providers.map((p) => [p.id, p]));
|
|
575
|
+
const order = provider ? [provider] : ladder ?? defaultLadder(capability, providers);
|
|
576
|
+
const steps = [];
|
|
577
|
+
for (const id of order) {
|
|
578
|
+
const candidate = byId.get(id);
|
|
579
|
+
const skip = await blocked(id, candidate, capability, quality);
|
|
580
|
+
if (skip) {
|
|
581
|
+
steps.push(skip);
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
const value = await candidate.analyze(capability, input, options);
|
|
586
|
+
const warning = passedOver(capability, steps, id);
|
|
587
|
+
steps.push({ provider: id, outcome: "answered" });
|
|
588
|
+
return { value, provenance: id, steps, warnings: warning ? [warning] : [] };
|
|
589
|
+
} catch (error) {
|
|
590
|
+
steps.push({ provider: id, outcome: "failed", reason: message(error) });
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
const none = order.length ? "" : " (none offers it)";
|
|
594
|
+
const why = passedOver(capability, steps, null)?.slice(capability.length + 2);
|
|
595
|
+
return {
|
|
596
|
+
value: null,
|
|
597
|
+
provenance: null,
|
|
598
|
+
steps,
|
|
599
|
+
warnings: [`${capability}: no provider answered${none}${why ? `; ${why}` : ""}`]
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// ../core/dist/audioSnap.js
|
|
604
|
+
function nearestIndex(sorted, t) {
|
|
605
|
+
let low = 0;
|
|
606
|
+
let high = sorted.length - 1;
|
|
607
|
+
while (low < high) {
|
|
608
|
+
const mid = low + high >> 1;
|
|
609
|
+
if (sorted[mid] < t)
|
|
610
|
+
low = mid + 1;
|
|
611
|
+
else
|
|
612
|
+
high = mid;
|
|
613
|
+
}
|
|
614
|
+
return low > 0 && t - sorted[low - 1] <= sorted[low] - t ? low - 1 : low;
|
|
615
|
+
}
|
|
616
|
+
function snapper(measured2, toleranceSeconds, reference) {
|
|
617
|
+
const shifts = [];
|
|
618
|
+
const unsnapped = [];
|
|
619
|
+
return {
|
|
620
|
+
snap(t) {
|
|
621
|
+
const nearest = measured2.length ? measured2[nearestIndex(measured2, t)] : null;
|
|
622
|
+
if (nearest === null || Math.abs(nearest - t) > toleranceSeconds) {
|
|
623
|
+
unsnapped.push(t);
|
|
624
|
+
return t;
|
|
625
|
+
}
|
|
626
|
+
shifts.push(Math.abs(nearest - t));
|
|
627
|
+
return nearest;
|
|
628
|
+
},
|
|
629
|
+
report() {
|
|
630
|
+
const sorted = [...shifts].sort((a, b) => a - b);
|
|
631
|
+
const median = sorted.length ? sorted[sorted.length >> 1] : null;
|
|
632
|
+
return {
|
|
633
|
+
reference,
|
|
634
|
+
toleranceMs: Math.round(toleranceSeconds * 1e3),
|
|
635
|
+
snapped: shifts.length,
|
|
636
|
+
unsnapped: [...unsnapped],
|
|
637
|
+
medianShiftMs: median === null ? null : Math.round(median * 1e3)
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// ../core/dist/audioSections.js
|
|
644
|
+
var BLOCK_SECONDS = 0.5;
|
|
645
|
+
var KERNEL_BLOCKS = 16;
|
|
646
|
+
var SAME_SECTION = 0.9;
|
|
647
|
+
var round2 = (t) => Math.round(t * 1e3) / 1e3;
|
|
648
|
+
function meanOf(frames) {
|
|
649
|
+
const sum = new Array(frames[0]?.length ?? 0).fill(0);
|
|
650
|
+
for (const frame of frames)
|
|
651
|
+
for (let b = 0; b < sum.length; b++)
|
|
652
|
+
sum[b] += frame[b];
|
|
653
|
+
return sum.map((v) => v / (frames.length || 1));
|
|
654
|
+
}
|
|
655
|
+
function standardizeBands(blocks) {
|
|
656
|
+
for (let b = 0; b < (blocks[0]?.length ?? 0); b++) {
|
|
657
|
+
const column = blocks.map((block) => block[b]);
|
|
658
|
+
const mean2 = column.reduce((a, v) => a + v, 0) / column.length;
|
|
659
|
+
const spread = Math.sqrt(column.reduce((a, v) => a + (v - mean2) ** 2, 0) / column.length);
|
|
660
|
+
for (const block of blocks)
|
|
661
|
+
block[b] = (block[b] - mean2) / (spread || 1);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
function blockParts({ fps, bands, chroma, chromaFps }) {
|
|
665
|
+
const per = Math.max(1, Math.round(BLOCK_SECONDS * fps));
|
|
666
|
+
const chromaPer = Math.max(1, Math.round(BLOCK_SECONDS * chromaFps));
|
|
667
|
+
const blocks = [];
|
|
668
|
+
for (let start = 0, b = 0; start + per <= bands.length; start += per, b++) {
|
|
669
|
+
const pitch = meanOf(chroma.slice(b * chromaPer, (b + 1) * chromaPer)).map(Math.log1p);
|
|
670
|
+
blocks.push([...meanOf(bands.slice(start, start + per)), ...unit(pitch)]);
|
|
671
|
+
}
|
|
672
|
+
return blocks;
|
|
673
|
+
}
|
|
674
|
+
function blockFeatures(frames) {
|
|
675
|
+
const blocks = blockParts(frames);
|
|
676
|
+
standardizeBands(blocks);
|
|
677
|
+
const split = frames.bands[0]?.length ?? 0;
|
|
678
|
+
return blocks.map((block) => [...unit(block.slice(0, split)), ...unit(block.slice(split))].map((v) => v * Math.SQRT1_2));
|
|
679
|
+
}
|
|
680
|
+
function unit(vector) {
|
|
681
|
+
const length = Math.hypot(...vector) || 1;
|
|
682
|
+
return vector.map((v) => v / length);
|
|
683
|
+
}
|
|
684
|
+
var dot = (a, b) => a.reduce((sum, v, i) => sum + v * b[i], 0);
|
|
685
|
+
var CHECKERBOARD = (() => {
|
|
686
|
+
const offsets = Array.from({ length: 2 * KERNEL_BLOCKS }, (_, k) => k - KERNEL_BLOCKS);
|
|
687
|
+
const taper = (k) => Math.exp(-0.5 * (((k < 0 ? -k - 1 : k) + 0.5) / (KERNEL_BLOCKS / 2)) ** 2);
|
|
688
|
+
return offsets.map((a) => offsets.map((b) => (a < 0 === b < 0 ? 1 : -1) * taper(a) * taper(b)));
|
|
689
|
+
})();
|
|
690
|
+
function noveltyAt(blocks, i) {
|
|
691
|
+
let sum = 0;
|
|
692
|
+
CHECKERBOARD.forEach((row, a) => {
|
|
693
|
+
const x = blocks[i + a - KERNEL_BLOCKS];
|
|
694
|
+
if (!x)
|
|
695
|
+
return;
|
|
696
|
+
row.forEach((weight, b) => {
|
|
697
|
+
const y = blocks[i + b - KERNEL_BLOCKS];
|
|
698
|
+
if (y)
|
|
699
|
+
sum += weight * dot(x, y);
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
return sum;
|
|
703
|
+
}
|
|
704
|
+
var novelty = (blocks) => blocks.map((_, i) => noveltyAt(blocks, i));
|
|
705
|
+
function boundaryBlocks(curve, minBlocks) {
|
|
706
|
+
const mean2 = curve.reduce((a, b) => a + b, 0) / (curve.length || 1);
|
|
707
|
+
const spread = Math.sqrt(curve.reduce((a, v) => a + (v - mean2) ** 2, 0) / (curve.length || 1));
|
|
708
|
+
const peaks = [];
|
|
709
|
+
for (let i = minBlocks; i <= curve.length - minBlocks; i++) {
|
|
710
|
+
const neighbourhood = curve.slice(Math.max(0, i - minBlocks), i + minBlocks + 1);
|
|
711
|
+
if (curve[i] < Math.max(...neighbourhood) || curve[i] <= mean2 + spread)
|
|
712
|
+
continue;
|
|
713
|
+
if (!peaks.length || i - peaks[peaks.length - 1] >= minBlocks)
|
|
714
|
+
peaks.push(i);
|
|
715
|
+
}
|
|
716
|
+
return peaks;
|
|
717
|
+
}
|
|
718
|
+
function labels(blocks, edges) {
|
|
719
|
+
const means = [];
|
|
720
|
+
const letters = [];
|
|
721
|
+
for (let s = 0; s + 1 < edges.length; s++) {
|
|
722
|
+
const part = blocks.slice(edges[s], edges[s + 1]);
|
|
723
|
+
const mean2 = unit(part[0].map((_, b) => part.reduce((a, block) => a + block[b], 0)));
|
|
724
|
+
const match = means.findIndex((other) => dot(other, mean2) >= SAME_SECTION);
|
|
725
|
+
letters.push(match >= 0 ? letters[match] : String.fromCharCode(65 + new Set(letters).size % 26));
|
|
726
|
+
means.push(mean2);
|
|
727
|
+
}
|
|
728
|
+
return letters;
|
|
729
|
+
}
|
|
730
|
+
var beatTolerance = (beats) => (medianInterval(beats) ?? 0) / 2;
|
|
731
|
+
function sections(signal, options = {}) {
|
|
732
|
+
const duration = round2((signal.channels[0]?.length ?? 0) / signal.sampleRate);
|
|
733
|
+
const blocks = blockFeatures(bandFramesOf(signal));
|
|
734
|
+
const minBlocks = Math.max(1, Math.round((options.minSeconds ?? 4) / BLOCK_SECONDS));
|
|
735
|
+
if (blocks.length < 2 * minBlocks)
|
|
736
|
+
return { spans: [{ start: 0, end: duration, label: "A" }] };
|
|
737
|
+
const edges = [0, ...boundaryBlocks(novelty(blocks), minBlocks), blocks.length];
|
|
738
|
+
const letters = labels(blocks, edges);
|
|
739
|
+
const beats = rhythm(signal).beats.times;
|
|
740
|
+
const onBeat = snapper(beats, beatTolerance(beats), "signal beats");
|
|
741
|
+
const times = edges.map((e, i) => i === 0 ? 0 : i === edges.length - 1 ? duration : round2(onBeat.snap(e * BLOCK_SECONDS)));
|
|
742
|
+
return {
|
|
743
|
+
spans: letters.map((label, s) => ({ start: times[s], end: times[s + 1], label })),
|
|
744
|
+
snap: onBeat.report()
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// ../core/dist/audioAnalysis.js
|
|
749
|
+
var DB_FLOOR = -120;
|
|
750
|
+
var signalDuration = (signal) => (signal.channels[0]?.length ?? 0) / signal.sampleRate;
|
|
751
|
+
function energyMix(signal) {
|
|
752
|
+
const [first, ...rest] = signal.channels;
|
|
753
|
+
if (!first)
|
|
754
|
+
return new Float32Array(0);
|
|
755
|
+
if (!rest.length)
|
|
756
|
+
return first;
|
|
757
|
+
const mixed = new Float32Array(first.length);
|
|
758
|
+
for (const channel of signal.channels)
|
|
759
|
+
for (let i = 0; i < mixed.length; i++)
|
|
760
|
+
mixed[i] += channel[i] * channel[i];
|
|
761
|
+
const scale = 1 / signal.channels.length;
|
|
762
|
+
for (let i = 0; i < mixed.length; i++)
|
|
763
|
+
mixed[i] = Math.sqrt(mixed[i] * scale);
|
|
764
|
+
return mixed;
|
|
765
|
+
}
|
|
766
|
+
var toDb = (amplitude) => amplitude > 0 ? Math.max(DB_FLOOR, 20 * Math.log10(amplitude)) : DB_FLOOR;
|
|
767
|
+
var hopSamples = (sampleRate, hopMs) => Math.max(1, Math.round(sampleRate * hopMs / 1e3));
|
|
768
|
+
var round3 = (t) => Math.round(t * 1e4) / 1e4;
|
|
769
|
+
function rmsFrames(samples, sampleRate, hopMs, windowMs) {
|
|
770
|
+
const hop = hopSamples(sampleRate, hopMs);
|
|
771
|
+
const half = Math.max(1, Math.round(sampleRate * windowMs / 2e3));
|
|
772
|
+
const frames = [];
|
|
773
|
+
for (let center = 0; center < samples.length; center += hop) {
|
|
774
|
+
const from = Math.max(0, center - half);
|
|
775
|
+
const to = Math.min(samples.length, center + half);
|
|
776
|
+
let sum = 0;
|
|
777
|
+
for (let i = from; i < to; i++)
|
|
778
|
+
sum += samples[i] * samples[i];
|
|
779
|
+
frames.push(to > from ? Math.sqrt(sum / (to - from)) : 0);
|
|
780
|
+
}
|
|
781
|
+
return frames;
|
|
782
|
+
}
|
|
783
|
+
var fftSizeFor = (sampleRate) => 2 ** Math.round(Math.log2(sampleRate * 0.023));
|
|
784
|
+
function bandBins(sampleRate, size, band) {
|
|
785
|
+
const binHz = sampleRate / size;
|
|
786
|
+
const low = Math.max(1, Math.floor((band?.[0] ?? 0) / binHz));
|
|
787
|
+
return [low, Math.max(low, Math.min(size / 2, Math.ceil((band?.[1] ?? sampleRate / 2) / binHz)))];
|
|
788
|
+
}
|
|
789
|
+
function loadFrame(samples, center, window, re, im) {
|
|
790
|
+
const first = center - window.length / 2;
|
|
791
|
+
for (let i = 0; i < window.length; i++) {
|
|
792
|
+
const at = first + i;
|
|
793
|
+
re[i] = at >= 0 && at < samples.length ? samples[at] * window[i] : 0;
|
|
794
|
+
im[i] = 0;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
function spectra(samples, sampleRate, hopMs, band) {
|
|
798
|
+
const size = fftSizeFor(sampleRate);
|
|
799
|
+
const hop = hopSamples(sampleRate, hopMs);
|
|
800
|
+
const window = Float64Array.from({ length: size }, (_, i) => 0.5 - 0.5 * Math.cos(2 * Math.PI * i / size));
|
|
801
|
+
const [low, high] = bandBins(sampleRate, size, band);
|
|
802
|
+
const frames = [];
|
|
803
|
+
const re = new Float64Array(size);
|
|
804
|
+
const im = new Float64Array(size);
|
|
805
|
+
for (let center = 0; center < samples.length; center += hop) {
|
|
806
|
+
loadFrame(samples, center, window, re, im);
|
|
807
|
+
fft(re, im);
|
|
808
|
+
const magnitudes = new Float64Array(high - low);
|
|
809
|
+
for (let k = low; k < high; k++)
|
|
810
|
+
magnitudes[k - low] = Math.hypot(re[k], im[k]);
|
|
811
|
+
frames.push(magnitudes);
|
|
812
|
+
}
|
|
813
|
+
return frames;
|
|
814
|
+
}
|
|
815
|
+
function averageMagnitudes(frames) {
|
|
816
|
+
const mixed = new Float64Array(frames[0]?.length ?? 0);
|
|
817
|
+
for (const frame of frames)
|
|
818
|
+
for (let bin = 0; bin < mixed.length; bin++)
|
|
819
|
+
mixed[bin] += frame[bin];
|
|
820
|
+
const scale = frames.length || 1;
|
|
821
|
+
for (let bin = 0; bin < mixed.length; bin++)
|
|
822
|
+
mixed[bin] /= scale;
|
|
823
|
+
return mixed;
|
|
824
|
+
}
|
|
825
|
+
function meanSpectra(signal, hopMs, band) {
|
|
826
|
+
const stacked = signal.channels.map((channel) => spectra(channel, signal.sampleRate, hopMs, band));
|
|
827
|
+
const count = stacked[0]?.length ?? 0;
|
|
828
|
+
const mixed = [];
|
|
829
|
+
for (let frame = 0; frame < count; frame++)
|
|
830
|
+
mixed.push(averageMagnitudes(stacked.map((channel) => channel[frame])));
|
|
831
|
+
return mixed;
|
|
832
|
+
}
|
|
833
|
+
function envelope(signal, options = {}) {
|
|
834
|
+
const { hopMs = 5, scale = "db", band } = options;
|
|
835
|
+
const windowMs = options.windowMs ?? hopMs * 2;
|
|
836
|
+
const size = fftSizeFor(signal.sampleRate);
|
|
837
|
+
const amplitudes = band ? meanSpectra(signal, hopMs, band).map((frame) => {
|
|
838
|
+
let sum = 0;
|
|
839
|
+
for (const magnitude of frame)
|
|
840
|
+
sum += magnitude * magnitude;
|
|
841
|
+
return Math.sqrt(2 * sum / (size * size * 0.375));
|
|
842
|
+
}) : rmsFrames(energyMix(signal), signal.sampleRate, hopMs, windowMs);
|
|
843
|
+
return { hopMs, scale, values: amplitudes.map((a) => scale === "db" ? toDb(a) : a) };
|
|
844
|
+
}
|
|
845
|
+
function noveltyCurve(signal, method, hopMs, band) {
|
|
846
|
+
const samples = energyMix(signal);
|
|
847
|
+
if (method === "energy") {
|
|
848
|
+
const rms = rmsFrames(samples, signal.sampleRate, hopMs, hopMs * 2);
|
|
849
|
+
return rms.map((value, i) => Math.max(0, value - (rms[i - 1] ?? 0)));
|
|
850
|
+
}
|
|
851
|
+
const frames = meanSpectra(signal, hopMs, band).map((frame) => frame.map((m) => Math.log1p(100 * m)));
|
|
852
|
+
const lastWhole = Math.floor((samples.length - fftSizeFor(signal.sampleRate) / 2) / hopSamples(signal.sampleRate, hopMs));
|
|
853
|
+
return frames.map((frame, i) => {
|
|
854
|
+
const previous = frames[i - 1];
|
|
855
|
+
if (!previous || i > lastWhole)
|
|
856
|
+
return 0;
|
|
857
|
+
let flux = 0;
|
|
858
|
+
for (let k = 0; k < frame.length; k++)
|
|
859
|
+
flux += Math.max(0, frame[k] - previous[k]);
|
|
860
|
+
return flux;
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
function isOnsetPeak(curve, i, gap, context, top) {
|
|
864
|
+
const value = curve[i];
|
|
865
|
+
let sum = 0;
|
|
866
|
+
let count = 0;
|
|
867
|
+
for (let j = Math.max(0, i - context); j <= Math.min(curve.length - 1, i + context); j++) {
|
|
868
|
+
if (Math.abs(j - i) <= gap && curve[j] > value)
|
|
869
|
+
return false;
|
|
870
|
+
sum += curve[j];
|
|
871
|
+
count++;
|
|
872
|
+
}
|
|
873
|
+
return value >= sum / count + 0.05 * top;
|
|
874
|
+
}
|
|
875
|
+
function onsets(signal, options = {}) {
|
|
876
|
+
const { method = "spectral-flux", band, threshold = 0.1, minGapMs = 30, hopMs = 5 } = options;
|
|
877
|
+
const curve = noveltyCurve(signal, method, hopMs, band);
|
|
878
|
+
const top = Math.max(0, ...curve);
|
|
879
|
+
if (top <= 0)
|
|
880
|
+
return { method, events: [] };
|
|
881
|
+
const gap = Math.max(1, Math.round(minGapMs / hopMs));
|
|
882
|
+
const context = Math.max(gap, Math.round(100 / hopMs));
|
|
883
|
+
const hopSeconds = hopSamples(signal.sampleRate, hopMs) / signal.sampleRate;
|
|
884
|
+
const events = [];
|
|
885
|
+
for (let i = 0; i < curve.length; i++) {
|
|
886
|
+
const strength = curve[i] / top;
|
|
887
|
+
if (strength < threshold || !isOnsetPeak(curve, i, gap, context, top))
|
|
888
|
+
continue;
|
|
889
|
+
const onset = { t: round3(i * hopSeconds), strength: round3(strength) };
|
|
890
|
+
const last = events[events.length - 1];
|
|
891
|
+
if (!last || onset.t - last.t >= minGapMs / 1e3)
|
|
892
|
+
events.push(onset);
|
|
893
|
+
else if (onset.strength > last.strength)
|
|
894
|
+
events[events.length - 1] = onset;
|
|
895
|
+
}
|
|
896
|
+
return { method, events };
|
|
897
|
+
}
|
|
898
|
+
function moments(signal, options = {}) {
|
|
899
|
+
const { onsetRatio = 0.2, tailDb = -40, hopMs = 1 } = options;
|
|
900
|
+
const rms = rmsFrames(energyMix(signal), signal.sampleRate, hopMs, Math.max(4, hopMs * 4));
|
|
901
|
+
const hopSeconds = hopSamples(signal.sampleRate, hopMs) / signal.sampleRate;
|
|
902
|
+
let peakIndex = 0;
|
|
903
|
+
for (let i = 1; i < rms.length; i++)
|
|
904
|
+
if (rms[i] > rms[peakIndex])
|
|
905
|
+
peakIndex = i;
|
|
906
|
+
const peak = rms[peakIndex] ?? 0;
|
|
907
|
+
if (peak <= 0)
|
|
908
|
+
return null;
|
|
909
|
+
let onsetIndex = rms.findIndex((value) => value >= peak * onsetRatio);
|
|
910
|
+
if (onsetIndex < 0)
|
|
911
|
+
onsetIndex = peakIndex;
|
|
912
|
+
let steepestIndex = onsetIndex;
|
|
913
|
+
let steepestRise = -Infinity;
|
|
914
|
+
for (let i = 1; i <= peakIndex; i++) {
|
|
915
|
+
const rise = rms[i] - rms[i - 1];
|
|
916
|
+
if (rise > steepestRise)
|
|
917
|
+
[steepestRise, steepestIndex] = [rise, i];
|
|
918
|
+
}
|
|
919
|
+
const floor = peak * 10 ** (tailDb / 20);
|
|
920
|
+
let tailIndex = peakIndex;
|
|
921
|
+
for (let i = rms.length - 1; i > peakIndex; i--)
|
|
922
|
+
if (rms[i] >= floor) {
|
|
923
|
+
tailIndex = i;
|
|
924
|
+
break;
|
|
925
|
+
}
|
|
926
|
+
return {
|
|
927
|
+
onset: round3(onsetIndex * hopSeconds),
|
|
928
|
+
steepest: round3(steepestIndex * hopSeconds),
|
|
929
|
+
peak: round3(peakIndex * hopSeconds),
|
|
930
|
+
tailEnd: round3(tailIndex * hopSeconds)
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
function kWeighting(sampleRate) {
|
|
934
|
+
let k = Math.tan(Math.PI * 1681.974450955533 / sampleRate);
|
|
935
|
+
const q = 0.7071752369554196;
|
|
936
|
+
const vh = 10 ** (3.999843853973347 / 20);
|
|
937
|
+
const vb = vh ** 0.4996667741545416;
|
|
938
|
+
let a0 = 1 + k / q + k * k;
|
|
939
|
+
const shelf = [
|
|
940
|
+
(vh + vb * k / q + k * k) / a0,
|
|
941
|
+
2 * (k * k - vh) / a0,
|
|
942
|
+
(vh - vb * k / q + k * k) / a0,
|
|
943
|
+
2 * (k * k - 1) / a0,
|
|
944
|
+
(1 - k / q + k * k) / a0
|
|
945
|
+
];
|
|
946
|
+
k = Math.tan(Math.PI * 38.13547087602444 / sampleRate);
|
|
947
|
+
const q2 = 0.5003270373238773;
|
|
948
|
+
a0 = 1 + k / q2 + k * k;
|
|
949
|
+
const highPass = [1, -2, 1, 2 * (k * k - 1) / a0, (1 - k / q2 + k * k) / a0];
|
|
950
|
+
return [shelf, highPass];
|
|
951
|
+
}
|
|
952
|
+
function filtered(samples, [b0, b1, b2, a1, a2]) {
|
|
953
|
+
const out = new Float64Array(samples.length);
|
|
954
|
+
let x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
|
955
|
+
for (let i = 0; i < samples.length; i++) {
|
|
956
|
+
const x = samples[i];
|
|
957
|
+
const y = b0 * x + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
|
|
958
|
+
x2 = x1;
|
|
959
|
+
x1 = x;
|
|
960
|
+
y2 = y1;
|
|
961
|
+
y1 = y;
|
|
962
|
+
out[i] = y;
|
|
963
|
+
}
|
|
964
|
+
return out;
|
|
965
|
+
}
|
|
966
|
+
var blockLoudness = (meanSquare) => meanSquare > 0 ? -0.691 + 10 * Math.log10(meanSquare) : -Infinity;
|
|
967
|
+
function squareSums(channel) {
|
|
968
|
+
const sums = new Float64Array(channel.length + 1);
|
|
969
|
+
for (let i = 0; i < channel.length; i++)
|
|
970
|
+
sums[i + 1] = sums[i] + channel[i] * channel[i];
|
|
971
|
+
return sums;
|
|
972
|
+
}
|
|
973
|
+
function blockPowers(sums, sampleRate, blockSeconds, stepSeconds) {
|
|
974
|
+
const length = (sums[0]?.length ?? 1) - 1;
|
|
975
|
+
if (!length)
|
|
976
|
+
return [];
|
|
977
|
+
const block = Math.min(length, Math.round(blockSeconds * sampleRate));
|
|
978
|
+
const step = Math.round(stepSeconds * sampleRate);
|
|
979
|
+
const powers = [];
|
|
980
|
+
for (let start = 0; start + block <= length; start += step)
|
|
981
|
+
powers.push(sums.reduce((power, sum) => power + (sum[start + block] - sum[start]) / block, 0));
|
|
982
|
+
return powers;
|
|
983
|
+
}
|
|
984
|
+
var TRUE_PEAK_OVERSAMPLE = 4;
|
|
985
|
+
var TRUE_PEAK_TAPS = 12;
|
|
986
|
+
var TRUE_PEAK_KERNELS = Array.from({ length: TRUE_PEAK_OVERSAMPLE - 1 }, (_, phase) => {
|
|
987
|
+
const offset = (phase + 1) / TRUE_PEAK_OVERSAMPLE;
|
|
988
|
+
return Float64Array.from({ length: 2 * TRUE_PEAK_TAPS }, (_2, tap) => {
|
|
989
|
+
const x = tap - TRUE_PEAK_TAPS + 1 - offset;
|
|
990
|
+
const sinc = x === 0 ? 1 : Math.sin(Math.PI * x) / (Math.PI * x);
|
|
991
|
+
return sinc * (0.5 + 0.5 * Math.cos(Math.PI * x / TRUE_PEAK_TAPS));
|
|
992
|
+
});
|
|
993
|
+
});
|
|
994
|
+
function truePeak(channel) {
|
|
995
|
+
let samplePeak = 0;
|
|
996
|
+
for (let i = 0; i < channel.length; i++)
|
|
997
|
+
samplePeak = Math.max(samplePeak, Math.abs(channel[i]));
|
|
998
|
+
const floor = samplePeak / 2;
|
|
999
|
+
const taps = 2 * TRUE_PEAK_TAPS;
|
|
1000
|
+
let peak = samplePeak;
|
|
1001
|
+
for (let n = 0; n + taps <= channel.length; n++) {
|
|
1002
|
+
if (Math.abs(channel[n + TRUE_PEAK_TAPS - 1]) < floor && Math.abs(channel[n + TRUE_PEAK_TAPS]) < floor)
|
|
1003
|
+
continue;
|
|
1004
|
+
for (const kernel of TRUE_PEAK_KERNELS) {
|
|
1005
|
+
let y = 0;
|
|
1006
|
+
for (let tap = 0; tap < taps; tap++)
|
|
1007
|
+
y += channel[n + tap] * kernel[tap];
|
|
1008
|
+
if (y > peak)
|
|
1009
|
+
peak = y;
|
|
1010
|
+
else if (-y > peak)
|
|
1011
|
+
peak = -y;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
return peak;
|
|
1015
|
+
}
|
|
1016
|
+
function loudness(signal) {
|
|
1017
|
+
const [shelf, highPass] = kWeighting(signal.sampleRate);
|
|
1018
|
+
const sums = signal.channels.map((channel) => squareSums(filtered(filtered(channel, shelf), highPass)));
|
|
1019
|
+
const momentary = blockPowers(sums, signal.sampleRate, 0.4, 0.1);
|
|
1020
|
+
const audible = momentary.filter((power) => blockLoudness(power) > -70);
|
|
1021
|
+
let lufsIntegrated = null;
|
|
1022
|
+
if (audible.length) {
|
|
1023
|
+
const relative = blockLoudness(audible.reduce((a, b) => a + b, 0) / audible.length) - 10;
|
|
1024
|
+
const gated = audible.filter((power) => blockLoudness(power) > relative);
|
|
1025
|
+
if (gated.length)
|
|
1026
|
+
lufsIntegrated = Math.round(blockLoudness(gated.reduce((a, b) => a + b, 0) / gated.length) * 10) / 10;
|
|
1027
|
+
}
|
|
1028
|
+
const shortTerm = blockPowers(sums, signal.sampleRate, 3, 0.1).map(blockLoudness).filter(Number.isFinite);
|
|
1029
|
+
let samplePeak = 0;
|
|
1030
|
+
let count = 0;
|
|
1031
|
+
let firstAt = null;
|
|
1032
|
+
for (const channel of signal.channels)
|
|
1033
|
+
for (let i = 0; i < channel.length; i++) {
|
|
1034
|
+
const magnitude = Math.abs(channel[i]);
|
|
1035
|
+
samplePeak = Math.max(samplePeak, magnitude);
|
|
1036
|
+
if (magnitude >= 0.999) {
|
|
1037
|
+
count++;
|
|
1038
|
+
const t = i / signal.sampleRate;
|
|
1039
|
+
if (firstAt === null || t < firstAt)
|
|
1040
|
+
firstAt = round3(t);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
return {
|
|
1044
|
+
lufsIntegrated,
|
|
1045
|
+
lufsShortTermMax: shortTerm.length ? Math.round(Math.max(...shortTerm) * 10) / 10 : null,
|
|
1046
|
+
samplePeakDb: Math.round(toDb(samplePeak) * 10) / 10,
|
|
1047
|
+
truePeakDb: Math.round(toDb(Math.max(0, ...signal.channels.map(truePeak))) * 10) / 10,
|
|
1048
|
+
clipping: { count, firstAt }
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
function silence(signal, options = {}) {
|
|
1052
|
+
const { thresholdDb = -50, minMs = 200, hopMs = 5 } = options;
|
|
1053
|
+
const db = rmsFrames(energyMix(signal), signal.sampleRate, hopMs, hopMs * 2).map(toDb);
|
|
1054
|
+
const hopSeconds = hopSamples(signal.sampleRate, hopMs) / signal.sampleRate;
|
|
1055
|
+
const spans = [];
|
|
1056
|
+
let from = null;
|
|
1057
|
+
for (let i = 0; i <= db.length; i++) {
|
|
1058
|
+
const quiet = i < db.length && db[i] < thresholdDb;
|
|
1059
|
+
if (quiet && from === null)
|
|
1060
|
+
from = i;
|
|
1061
|
+
if (!quiet && from !== null) {
|
|
1062
|
+
if ((i - from) * hopSeconds * 1e3 >= minMs)
|
|
1063
|
+
spans.push({
|
|
1064
|
+
start: round3(from * hopSeconds),
|
|
1065
|
+
end: round3(Math.min(i * hopSeconds, signalDuration(signal)))
|
|
1066
|
+
});
|
|
1067
|
+
from = null;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
return spans;
|
|
1071
|
+
}
|
|
1072
|
+
function periodicity(curve, hopMs) {
|
|
1073
|
+
const mean2 = curve.reduce((a, b) => a + b, 0) / (curve.length || 1);
|
|
1074
|
+
const centred = curve.map((v) => v - mean2);
|
|
1075
|
+
const energy = centred.reduce((a, v) => a + v * v, 0);
|
|
1076
|
+
if (!energy)
|
|
1077
|
+
return 0;
|
|
1078
|
+
let best = 0;
|
|
1079
|
+
for (let lag = Math.round(300 / hopMs); lag <= Math.round(1500 / hopMs) && lag < centred.length; lag++) {
|
|
1080
|
+
let sum = 0;
|
|
1081
|
+
for (let i = lag; i < centred.length; i++)
|
|
1082
|
+
sum += centred[i] * centred[i - lag];
|
|
1083
|
+
best = Math.max(best, sum / energy);
|
|
1084
|
+
}
|
|
1085
|
+
return best;
|
|
1086
|
+
}
|
|
1087
|
+
function syllableModulation(signal) {
|
|
1088
|
+
const hopMs = 10;
|
|
1089
|
+
const rms = rmsFrames(energyMix(signal), signal.sampleRate, hopMs, 25);
|
|
1090
|
+
const size = 2 ** Math.floor(Math.log2(Math.min(rms.length, 1024)));
|
|
1091
|
+
if (size < 64)
|
|
1092
|
+
return 0;
|
|
1093
|
+
const re = Float64Array.from(rms.slice(0, size));
|
|
1094
|
+
const mean2 = re.reduce((a, b) => a + b, 0) / size;
|
|
1095
|
+
for (let i = 0; i < size; i++)
|
|
1096
|
+
re[i] = re[i] - mean2;
|
|
1097
|
+
const im = new Float64Array(size);
|
|
1098
|
+
fft(re, im);
|
|
1099
|
+
const rate = 1e3 / hopMs;
|
|
1100
|
+
let inBand = 0;
|
|
1101
|
+
let total = 0;
|
|
1102
|
+
for (let k = 1; k < size / 2; k++) {
|
|
1103
|
+
const power = re[k] * re[k] + im[k] * im[k];
|
|
1104
|
+
const hz = k * rate / size;
|
|
1105
|
+
total += power;
|
|
1106
|
+
if (hz >= 3 && hz <= 8)
|
|
1107
|
+
inBand += power;
|
|
1108
|
+
}
|
|
1109
|
+
return total ? inBand / total : 0;
|
|
1110
|
+
}
|
|
1111
|
+
function sustainShare(signal) {
|
|
1112
|
+
const levels = rmsFrames(energyMix(signal), signal.sampleRate, 50, 100).map(toDb);
|
|
1113
|
+
if (!levels.length)
|
|
1114
|
+
return 0;
|
|
1115
|
+
const loud = [...levels].sort((a, b) => a - b)[Math.floor((levels.length - 1) * 0.95)];
|
|
1116
|
+
return levels.filter((level) => level > loud - 20).length / levels.length;
|
|
1117
|
+
}
|
|
1118
|
+
function kindFeatures(signal) {
|
|
1119
|
+
return {
|
|
1120
|
+
duration: round3(signalDuration(signal)),
|
|
1121
|
+
regularity: round3(periodicity(noveltyCurve(signal, "spectral-flux", 10), 10)),
|
|
1122
|
+
syllables: round3(syllableModulation(signal)),
|
|
1123
|
+
sustain: round3(sustainShare(signal))
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
function classify(signal) {
|
|
1127
|
+
const features = kindFeatures(signal);
|
|
1128
|
+
const { duration, regularity, syllables, sustain } = features;
|
|
1129
|
+
const speechLike = syllables >= 0.35 && regularity < 0.35;
|
|
1130
|
+
if (duration >= 8) {
|
|
1131
|
+
if (sustain < 0.4)
|
|
1132
|
+
return { value: "sfx", confidence: 0.6, features };
|
|
1133
|
+
if (speechLike)
|
|
1134
|
+
return { value: "voice", confidence: round3(Math.min(0.9, 0.4 + syllables)), features };
|
|
1135
|
+
return { value: "music", confidence: round3(Math.min(0.9, 0.5 + regularity)), features };
|
|
1136
|
+
}
|
|
1137
|
+
if (duration >= 1.5 && syllables >= 0.17 && regularity < 0.3 && sustain >= 0.7)
|
|
1138
|
+
return { value: "voice", confidence: speechLike ? 0.8 : 0.6, features };
|
|
1139
|
+
return { value: "sfx", confidence: duration <= 2 ? 0.85 : 0.65, features };
|
|
1140
|
+
}
|
|
1141
|
+
var SIGNAL_MEASURES = {
|
|
1142
|
+
beats: (input) => rhythm(input).beats,
|
|
1143
|
+
downbeats: (input) => rhythm(input).downbeats,
|
|
1144
|
+
sections: (input, options) => sections(input, options),
|
|
1145
|
+
envelope: (input, options) => envelope(input, options),
|
|
1146
|
+
onsets: (input, options) => onsets(input, options),
|
|
1147
|
+
moments: (input, options) => moments(input, options),
|
|
1148
|
+
loudness: (input) => loudness(input),
|
|
1149
|
+
silence: (input, options) => silence(input, options),
|
|
1150
|
+
kind: (input) => classify(input)
|
|
1151
|
+
};
|
|
1152
|
+
var signalProvider = {
|
|
1153
|
+
id: "signal",
|
|
1154
|
+
local: true,
|
|
1155
|
+
signal: true,
|
|
1156
|
+
capabilities: [
|
|
1157
|
+
"envelope",
|
|
1158
|
+
"onsets",
|
|
1159
|
+
"moments",
|
|
1160
|
+
"loudness",
|
|
1161
|
+
"silence",
|
|
1162
|
+
"kind",
|
|
1163
|
+
"beats",
|
|
1164
|
+
"downbeats",
|
|
1165
|
+
"sections"
|
|
1166
|
+
],
|
|
1167
|
+
async analyze(capability, input, options) {
|
|
1168
|
+
const measure = SIGNAL_MEASURES[capability];
|
|
1169
|
+
if (!measure)
|
|
1170
|
+
throw new Error(`signal processing does not measure ${capability}`);
|
|
1171
|
+
return measure(input, options);
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
export {
|
|
1176
|
+
medianInterval,
|
|
1177
|
+
tempoOf,
|
|
1178
|
+
bandFramesOf,
|
|
1179
|
+
rhythm,
|
|
1180
|
+
runLadder,
|
|
1181
|
+
signalDuration,
|
|
1182
|
+
energyMix,
|
|
1183
|
+
envelope,
|
|
1184
|
+
signalProvider,
|
|
1185
|
+
probeAudio,
|
|
1186
|
+
decodeAudio
|
|
1187
|
+
};
|