@despia-native/kernel 0.0.0-stage → 0.3.0
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 +202 -0
- package/NOTICE +1414 -0
- package/README.md +17 -2
- package/dist/.dsx-build-stamp.json +7 -0
- package/dist/api-cohort.d.ts +27 -0
- package/dist/api-cohort.d.ts.map +1 -0
- package/dist/api-cohort.js +94 -0
- package/dist/api-cohort.js.map +1 -0
- package/dist/api.d.ts +454 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +2442 -0
- package/dist/api.js.map +1 -0
- package/dist/app-consts.d.ts +10 -0
- package/dist/app-consts.d.ts.map +1 -0
- package/dist/app-consts.js +39 -0
- package/dist/app-consts.js.map +1 -0
- package/dist/app-update.d.ts +12 -0
- package/dist/app-update.d.ts.map +1 -0
- package/dist/app-update.js +32 -0
- package/dist/app-update.js.map +1 -0
- package/dist/aria.d.ts +152 -0
- package/dist/aria.d.ts.map +1 -0
- package/dist/aria.js +524 -0
- package/dist/aria.js.map +1 -0
- package/dist/audio-core.d.ts +260 -0
- package/dist/audio-core.d.ts.map +1 -0
- package/dist/audio-core.js +1440 -0
- package/dist/audio-core.js.map +1 -0
- package/dist/audio-edit.d.ts +100 -0
- package/dist/audio-edit.d.ts.map +1 -0
- package/dist/audio-edit.js +489 -0
- package/dist/audio-edit.js.map +1 -0
- package/dist/audio-mix.d.ts +84 -0
- package/dist/audio-mix.d.ts.map +1 -0
- package/dist/audio-mix.js +393 -0
- package/dist/audio-mix.js.map +1 -0
- package/dist/auth-proof.d.ts +145 -0
- package/dist/auth-proof.d.ts.map +1 -0
- package/dist/auth-proof.js +644 -0
- package/dist/auth-proof.js.map +1 -0
- package/dist/availability-explain.d.ts +3 -0
- package/dist/availability-explain.d.ts.map +1 -0
- package/dist/availability-explain.js +322 -0
- package/dist/availability-explain.js.map +1 -0
- package/dist/availability.d.ts +246 -0
- package/dist/availability.d.ts.map +1 -0
- package/dist/availability.js +615 -0
- package/dist/availability.js.map +1 -0
- package/dist/background.d.ts +116 -0
- package/dist/background.d.ts.map +1 -0
- package/dist/background.js +235 -0
- package/dist/background.js.map +1 -0
- package/dist/boot-tables-flag.d.ts +2 -0
- package/dist/boot-tables-flag.d.ts.map +1 -0
- package/dist/boot-tables-flag.js +16 -0
- package/dist/boot-tables-flag.js.map +1 -0
- package/dist/boot-tables.d.ts +40 -0
- package/dist/boot-tables.d.ts.map +1 -0
- package/dist/boot-tables.js +102 -0
- package/dist/boot-tables.js.map +1 -0
- package/dist/border-edges.d.ts +5 -0
- package/dist/border-edges.d.ts.map +1 -0
- package/dist/border-edges.js +47 -0
- package/dist/border-edges.js.map +1 -0
- package/dist/bus.d.ts +1203 -0
- package/dist/bus.d.ts.map +1 -0
- package/dist/bus.js +2647 -0
- package/dist/bus.js.map +1 -0
- package/dist/calendar-core.d.ts +143 -0
- package/dist/calendar-core.d.ts.map +1 -0
- package/dist/calendar-core.js +372 -0
- package/dist/calendar-core.js.map +1 -0
- package/dist/call-value.d.ts +16 -0
- package/dist/call-value.d.ts.map +1 -0
- package/dist/call-value.js +54 -0
- package/dist/call-value.js.map +1 -0
- package/dist/camera-core.d.ts +222 -0
- package/dist/camera-core.d.ts.map +1 -0
- package/dist/camera-core.js +980 -0
- package/dist/camera-core.js.map +1 -0
- package/dist/canvas-core.d.ts +404 -0
- package/dist/canvas-core.d.ts.map +1 -0
- package/dist/canvas-core.js +2186 -0
- package/dist/canvas-core.js.map +1 -0
- package/dist/capture-core.d.ts +74 -0
- package/dist/capture-core.d.ts.map +1 -0
- package/dist/capture-core.js +158 -0
- package/dist/capture-core.js.map +1 -0
- package/dist/compile/codegen.d.ts +146 -0
- package/dist/compile/codegen.d.ts.map +1 -0
- package/dist/compile/codegen.js +1949 -0
- package/dist/compile/codegen.js.map +1 -0
- package/dist/compile/jstier.d.ts +44 -0
- package/dist/compile/jstier.d.ts.map +1 -0
- package/dist/compile/jstier.js +181 -0
- package/dist/compile/jstier.js.map +1 -0
- package/dist/compile/tier-door.d.ts +41 -0
- package/dist/compile/tier-door.d.ts.map +1 -0
- package/dist/compile/tier-door.js +167 -0
- package/dist/compile/tier-door.js.map +1 -0
- package/dist/compile/tier-realm.d.ts +49 -0
- package/dist/compile/tier-realm.d.ts.map +1 -0
- package/dist/compile/tier-realm.js +368 -0
- package/dist/compile/tier-realm.js.map +1 -0
- package/dist/compile/tier.d.ts +23 -0
- package/dist/compile/tier.d.ts.map +1 -0
- package/dist/compile/tier.js +157 -0
- package/dist/compile/tier.js.map +1 -0
- package/dist/compose-core.d.ts +86 -0
- package/dist/compose-core.d.ts.map +1 -0
- package/dist/compose-core.js +112 -0
- package/dist/compose-core.js.map +1 -0
- package/dist/config-validate.d.ts +31 -0
- package/dist/config-validate.d.ts.map +1 -0
- package/dist/config-validate.js +147 -0
- package/dist/config-validate.js.map +1 -0
- package/dist/config-values.d.ts +106 -0
- package/dist/config-values.d.ts.map +1 -0
- package/dist/config-values.js +340 -0
- package/dist/config-values.js.map +1 -0
- package/dist/contacts-core.d.ts +127 -0
- package/dist/contacts-core.d.ts.map +1 -0
- package/dist/contacts-core.js +211 -0
- package/dist/contacts-core.js.map +1 -0
- package/dist/content-transition.d.ts +58 -0
- package/dist/content-transition.d.ts.map +1 -0
- package/dist/content-transition.js +94 -0
- package/dist/content-transition.js.map +1 -0
- package/dist/controls-core.d.ts +227 -0
- package/dist/controls-core.d.ts.map +1 -0
- package/dist/controls-core.js +652 -0
- package/dist/controls-core.js.map +1 -0
- package/dist/cookies.d.ts +78 -0
- package/dist/cookies.d.ts.map +1 -0
- package/dist/cookies.js +265 -0
- package/dist/cookies.js.map +1 -0
- package/dist/corner-shape-core.d.ts +69 -0
- package/dist/corner-shape-core.d.ts.map +1 -0
- package/dist/corner-shape-core.js +261 -0
- package/dist/corner-shape-core.js.map +1 -0
- package/dist/crypto-core.d.ts +57 -0
- package/dist/crypto-core.d.ts.map +1 -0
- package/dist/crypto-core.js +128 -0
- package/dist/crypto-core.js.map +1 -0
- package/dist/dataviz.d.ts +436 -0
- package/dist/dataviz.d.ts.map +1 -0
- package/dist/dataviz.js +956 -0
- package/dist/dataviz.js.map +1 -0
- package/dist/debug.d.ts +293 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +767 -0
- package/dist/debug.js.map +1 -0
- package/dist/device-ownership.d.ts +50 -0
- package/dist/device-ownership.d.ts.map +1 -0
- package/dist/device-ownership.js +105 -0
- package/dist/device-ownership.js.map +1 -0
- package/dist/effects.d.ts +86 -0
- package/dist/effects.d.ts.map +1 -0
- package/dist/effects.js +98 -0
- package/dist/effects.js.map +1 -0
- package/dist/element.d.ts +108 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +63 -0
- package/dist/element.js.map +1 -0
- package/dist/file-watch.d.ts +16 -0
- package/dist/file-watch.d.ts.map +1 -0
- package/dist/file-watch.js +49 -0
- package/dist/file-watch.js.map +1 -0
- package/dist/filepaths.d.ts +72 -0
- package/dist/filepaths.d.ts.map +1 -0
- package/dist/filepaths.js +271 -0
- package/dist/filepaths.js.map +1 -0
- package/dist/film.d.ts +264 -0
- package/dist/film.d.ts.map +1 -0
- package/dist/film.js +313 -0
- package/dist/film.js.map +1 -0
- package/dist/fonts.d.ts +66 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +135 -0
- package/dist/fonts.js.map +1 -0
- package/dist/forms.d.ts +191 -0
- package/dist/forms.d.ts.map +1 -0
- package/dist/forms.js +663 -0
- package/dist/forms.js.map +1 -0
- package/dist/geo.d.ts +289 -0
- package/dist/geo.d.ts.map +1 -0
- package/dist/geo.js +460 -0
- package/dist/geo.js.map +1 -0
- package/dist/handler-announce.d.ts +46 -0
- package/dist/handler-announce.d.ts.map +1 -0
- package/dist/handler-announce.js +96 -0
- package/dist/handler-announce.js.map +1 -0
- package/dist/handoff.d.ts +71 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +250 -0
- package/dist/handoff.js.map +1 -0
- package/dist/identity-durability.d.ts +76 -0
- package/dist/identity-durability.d.ts.map +1 -0
- package/dist/identity-durability.js +150 -0
- package/dist/identity-durability.js.map +1 -0
- package/dist/image-core.d.ts +240 -0
- package/dist/image-core.d.ts.map +1 -0
- package/dist/image-core.js +618 -0
- package/dist/image-core.js.map +1 -0
- package/dist/image-schemes.d.ts +10 -0
- package/dist/image-schemes.d.ts.map +1 -0
- package/dist/image-schemes.js +28 -0
- package/dist/image-schemes.js.map +1 -0
- package/dist/index.d.ts +143 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +299 -0
- package/dist/index.js.map +1 -0
- package/dist/ink-core.d.ts +53 -0
- package/dist/ink-core.d.ts.map +1 -0
- package/dist/ink-core.js +119 -0
- package/dist/ink-core.js.map +1 -0
- package/dist/input.d.ts +148 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +358 -0
- package/dist/input.js.map +1 -0
- package/dist/integrity.d.ts +63 -0
- package/dist/integrity.d.ts.map +1 -0
- package/dist/integrity.js +150 -0
- package/dist/integrity.js.map +1 -0
- package/dist/intents.d.ts +95 -0
- package/dist/intents.d.ts.map +1 -0
- package/dist/intents.js +282 -0
- package/dist/intents.js.map +1 -0
- package/dist/interpolate-core.d.ts +37 -0
- package/dist/interpolate-core.d.ts.map +1 -0
- package/dist/interpolate-core.js +443 -0
- package/dist/interpolate-core.js.map +1 -0
- package/dist/jse/color.d.ts +12 -0
- package/dist/jse/color.d.ts.map +1 -0
- package/dist/jse/color.js +196 -0
- package/dist/jse/color.js.map +1 -0
- package/dist/jse/core.d.ts +54 -0
- package/dist/jse/core.d.ts.map +1 -0
- package/dist/jse/core.js +1519 -0
- package/dist/jse/core.js.map +1 -0
- package/dist/jse/dispatch.d.ts +28 -0
- package/dist/jse/dispatch.d.ts.map +1 -0
- package/dist/jse/dispatch.js +116 -0
- package/dist/jse/dispatch.js.map +1 -0
- package/dist/jse/highlight-grammar.d.ts +15 -0
- package/dist/jse/highlight-grammar.d.ts.map +1 -0
- package/dist/jse/highlight-grammar.js +161 -0
- package/dist/jse/highlight-grammar.js.map +1 -0
- package/dist/jse/highlight-grammars.generated.d.ts +2 -0
- package/dist/jse/highlight-grammars.generated.d.ts.map +1 -0
- package/dist/jse/highlight-grammars.generated.js +4 -0
- package/dist/jse/highlight-grammars.generated.js.map +1 -0
- package/dist/jse/highlight.d.ts +37 -0
- package/dist/jse/highlight.d.ts.map +1 -0
- package/dist/jse/highlight.js +323 -0
- package/dist/jse/highlight.js.map +1 -0
- package/dist/jse/jse.d.ts +674 -0
- package/dist/jse/jse.d.ts.map +1 -0
- package/dist/jse/jse.js +5841 -0
- package/dist/jse/jse.js.map +1 -0
- package/dist/jse/pathmatch.d.ts +10 -0
- package/dist/jse/pathmatch.d.ts.map +1 -0
- package/dist/jse/pathmatch.js +73 -0
- package/dist/jse/pathmatch.js.map +1 -0
- package/dist/jse/regex.d.ts +33 -0
- package/dist/jse/regex.d.ts.map +1 -0
- package/dist/jse/regex.js +375 -0
- package/dist/jse/regex.js.map +1 -0
- package/dist/jse/stdlib.d.ts +8 -0
- package/dist/jse/stdlib.d.ts.map +1 -0
- package/dist/jse/stdlib.js +765 -0
- package/dist/jse/stdlib.js.map +1 -0
- package/dist/jse/tokens.d.ts +102 -0
- package/dist/jse/tokens.d.ts.map +1 -0
- package/dist/jse/tokens.js +982 -0
- package/dist/jse/tokens.js.map +1 -0
- package/dist/jse/values.d.ts +206 -0
- package/dist/jse/values.d.ts.map +1 -0
- package/dist/jse/values.js +846 -0
- package/dist/jse/values.js.map +1 -0
- package/dist/keyboard.d.ts +196 -0
- package/dist/keyboard.d.ts.map +1 -0
- package/dist/keyboard.js +186 -0
- package/dist/keyboard.js.map +1 -0
- package/dist/label-choices.d.ts +3 -0
- package/dist/label-choices.d.ts.map +1 -0
- package/dist/label-choices.js +168 -0
- package/dist/label-choices.js.map +1 -0
- package/dist/language.d.ts +33 -0
- package/dist/language.d.ts.map +1 -0
- package/dist/language.js +50 -0
- package/dist/language.js.map +1 -0
- package/dist/length-units.d.ts +30 -0
- package/dist/length-units.d.ts.map +1 -0
- package/dist/length-units.js +83 -0
- package/dist/length-units.js.map +1 -0
- package/dist/lightsensor.d.ts +48 -0
- package/dist/lightsensor.d.ts.map +1 -0
- package/dist/lightsensor.js +97 -0
- package/dist/lightsensor.js.map +1 -0
- package/dist/link-refresh.d.ts +27 -0
- package/dist/link-refresh.d.ts.map +1 -0
- package/dist/link-refresh.js +166 -0
- package/dist/link-refresh.js.map +1 -0
- package/dist/link.d.ts +57 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +333 -0
- package/dist/link.js.map +1 -0
- package/dist/linkpreview.d.ts +114 -0
- package/dist/linkpreview.d.ts.map +1 -0
- package/dist/linkpreview.js +439 -0
- package/dist/linkpreview.js.map +1 -0
- package/dist/list-presence.d.ts +32 -0
- package/dist/list-presence.d.ts.map +1 -0
- package/dist/list-presence.js +48 -0
- package/dist/list-presence.js.map +1 -0
- package/dist/live-stream.d.ts +27 -0
- package/dist/live-stream.d.ts.map +1 -0
- package/dist/live-stream.js +274 -0
- package/dist/live-stream.js.map +1 -0
- package/dist/livelogs.d.ts +134 -0
- package/dist/livelogs.d.ts.map +1 -0
- package/dist/livelogs.js +409 -0
- package/dist/livelogs.js.map +1 -0
- package/dist/logs.d.ts +80 -0
- package/dist/logs.d.ts.map +1 -0
- package/dist/logs.js +206 -0
- package/dist/logs.js.map +1 -0
- package/dist/mcp/apps.d.ts +82 -0
- package/dist/mcp/apps.d.ts.map +1 -0
- package/dist/mcp/apps.js +219 -0
- package/dist/mcp/apps.js.map +1 -0
- package/dist/mcp/entities.d.ts +25 -0
- package/dist/mcp/entities.d.ts.map +1 -0
- package/dist/mcp/entities.js +71 -0
- package/dist/mcp/entities.js.map +1 -0
- package/dist/mcp/result.d.ts +73 -0
- package/dist/mcp/result.d.ts.map +1 -0
- package/dist/mcp/result.js +119 -0
- package/dist/mcp/result.js.map +1 -0
- package/dist/mcp/webmcp.d.ts +162 -0
- package/dist/mcp/webmcp.d.ts.map +1 -0
- package/dist/mcp/webmcp.js +214 -0
- package/dist/mcp/webmcp.js.map +1 -0
- package/dist/mcp.d.ts +5 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +14 -0
- package/dist/mcp.js.map +1 -0
- package/dist/media-core.d.ts +191 -0
- package/dist/media-core.d.ts.map +1 -0
- package/dist/media-core.js +446 -0
- package/dist/media-core.js.map +1 -0
- package/dist/media-timeline-core.d.ts +94 -0
- package/dist/media-timeline-core.d.ts.map +1 -0
- package/dist/media-timeline-core.js +620 -0
- package/dist/media-timeline-core.js.map +1 -0
- package/dist/message.d.ts +42 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +582 -0
- package/dist/message.js.map +1 -0
- package/dist/missing-element.d.ts +29 -0
- package/dist/missing-element.d.ts.map +1 -0
- package/dist/missing-element.js +76 -0
- package/dist/missing-element.js.map +1 -0
- package/dist/motion-core.d.ts +160 -0
- package/dist/motion-core.d.ts.map +1 -0
- package/dist/motion-core.js +752 -0
- package/dist/motion-core.js.map +1 -0
- package/dist/motion-pose.d.ts +65 -0
- package/dist/motion-pose.d.ts.map +1 -0
- package/dist/motion-pose.js +143 -0
- package/dist/motion-pose.js.map +1 -0
- package/dist/motion.d.ts +132 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +260 -0
- package/dist/motion.js.map +1 -0
- package/dist/mount-core.d.ts +203 -0
- package/dist/mount-core.d.ts.map +1 -0
- package/dist/mount-core.js +437 -0
- package/dist/mount-core.js.map +1 -0
- package/dist/net-core.d.ts +110 -0
- package/dist/net-core.d.ts.map +1 -0
- package/dist/net-core.js +225 -0
- package/dist/net-core.js.map +1 -0
- package/dist/notify.d.ts +399 -0
- package/dist/notify.d.ts.map +1 -0
- package/dist/notify.js +964 -0
- package/dist/notify.js.map +1 -0
- package/dist/orientation-binding.d.ts +39 -0
- package/dist/orientation-binding.d.ts.map +1 -0
- package/dist/orientation-binding.js +64 -0
- package/dist/orientation-binding.js.map +1 -0
- package/dist/orientation.d.ts +55 -0
- package/dist/orientation.d.ts.map +1 -0
- package/dist/orientation.js +89 -0
- package/dist/orientation.js.map +1 -0
- package/dist/ota.d.ts +52 -0
- package/dist/ota.d.ts.map +1 -0
- package/dist/ota.js +122 -0
- package/dist/ota.js.map +1 -0
- package/dist/passkeys.d.ts +91 -0
- package/dist/passkeys.d.ts.map +1 -0
- package/dist/passkeys.js +307 -0
- package/dist/passkeys.js.map +1 -0
- package/dist/payment.d.ts +85 -0
- package/dist/payment.d.ts.map +1 -0
- package/dist/payment.js +270 -0
- package/dist/payment.js.map +1 -0
- package/dist/pending-presenter.d.ts +31 -0
- package/dist/pending-presenter.d.ts.map +1 -0
- package/dist/pending-presenter.js +119 -0
- package/dist/pending-presenter.js.map +1 -0
- package/dist/permission-core.d.ts +59 -0
- package/dist/permission-core.d.ts.map +1 -0
- package/dist/permission-core.js +102 -0
- package/dist/permission-core.js.map +1 -0
- package/dist/persist.d.ts +169 -0
- package/dist/persist.d.ts.map +1 -0
- package/dist/persist.js +361 -0
- package/dist/persist.js.map +1 -0
- package/dist/phase-plan.d.ts +114 -0
- package/dist/phase-plan.d.ts.map +1 -0
- package/dist/phase-plan.js +837 -0
- package/dist/phase-plan.js.map +1 -0
- package/dist/playback-core.d.ts +64 -0
- package/dist/playback-core.d.ts.map +1 -0
- package/dist/playback-core.js +176 -0
- package/dist/playback-core.js.map +1 -0
- package/dist/player-sources.d.ts +12 -0
- package/dist/player-sources.d.ts.map +1 -0
- package/dist/player-sources.js +44 -0
- package/dist/player-sources.js.map +1 -0
- package/dist/proxy-denylist.d.ts +11 -0
- package/dist/proxy-denylist.d.ts.map +1 -0
- package/dist/proxy-denylist.js +44 -0
- package/dist/proxy-denylist.js.map +1 -0
- package/dist/public-config.d.ts +20 -0
- package/dist/public-config.d.ts.map +1 -0
- package/dist/public-config.js +109 -0
- package/dist/public-config.js.map +1 -0
- package/dist/qoe-core.d.ts +72 -0
- package/dist/qoe-core.d.ts.map +1 -0
- package/dist/qoe-core.js +113 -0
- package/dist/qoe-core.js.map +1 -0
- package/dist/reactive-request.d.ts +80 -0
- package/dist/reactive-request.d.ts.map +1 -0
- package/dist/reactive-request.js +192 -0
- package/dist/reactive-request.js.map +1 -0
- package/dist/read-cache.d.ts +129 -0
- package/dist/read-cache.d.ts.map +1 -0
- package/dist/read-cache.js +566 -0
- package/dist/read-cache.js.map +1 -0
- package/dist/recorder-core.d.ts +57 -0
- package/dist/recorder-core.d.ts.map +1 -0
- package/dist/recorder-core.js +136 -0
- package/dist/recorder-core.js.map +1 -0
- package/dist/ref.d.ts +41 -0
- package/dist/ref.d.ts.map +1 -0
- package/dist/ref.js +98 -0
- package/dist/ref.js.map +1 -0
- package/dist/refusal.d.ts +82 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +218 -0
- package/dist/refusal.js.map +1 -0
- package/dist/region-insets.d.ts +61 -0
- package/dist/region-insets.d.ts.map +1 -0
- package/dist/region-insets.js +67 -0
- package/dist/region-insets.js.map +1 -0
- package/dist/rive-core.d.ts +323 -0
- package/dist/rive-core.d.ts.map +1 -0
- package/dist/rive-core.js +677 -0
- package/dist/rive-core.js.map +1 -0
- package/dist/runner.d.ts +595 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +4094 -0
- package/dist/runner.js.map +1 -0
- package/dist/scene/a11y.d.ts +11 -0
- package/dist/scene/a11y.d.ts.map +1 -0
- package/dist/scene/a11y.js +67 -0
- package/dist/scene/a11y.js.map +1 -0
- package/dist/scene/anim.d.ts +149 -0
- package/dist/scene/anim.d.ts.map +1 -0
- package/dist/scene/anim.js +396 -0
- package/dist/scene/anim.js.map +1 -0
- package/dist/scene/bind.d.ts +33 -0
- package/dist/scene/bind.d.ts.map +1 -0
- package/dist/scene/bind.js +66 -0
- package/dist/scene/bind.js.map +1 -0
- package/dist/scene/collide.d.ts +56 -0
- package/dist/scene/collide.d.ts.map +1 -0
- package/dist/scene/collide.js +146 -0
- package/dist/scene/collide.js.map +1 -0
- package/dist/scene/frame.d.ts +22 -0
- package/dist/scene/frame.d.ts.map +1 -0
- package/dist/scene/frame.js +57 -0
- package/dist/scene/frame.js.map +1 -0
- package/dist/scene/gltf.d.ts +79 -0
- package/dist/scene/gltf.d.ts.map +1 -0
- package/dist/scene/gltf.js +409 -0
- package/dist/scene/gltf.js.map +1 -0
- package/dist/scene/ir.d.ts +293 -0
- package/dist/scene/ir.d.ts.map +1 -0
- package/dist/scene/ir.js +692 -0
- package/dist/scene/ir.js.map +1 -0
- package/dist/scene/math.d.ts +50 -0
- package/dist/scene/math.d.ts.map +1 -0
- package/dist/scene/math.js +180 -0
- package/dist/scene/math.js.map +1 -0
- package/dist/scene/orbit.d.ts +19 -0
- package/dist/scene/orbit.d.ts.map +1 -0
- package/dist/scene/orbit.js +60 -0
- package/dist/scene/orbit.js.map +1 -0
- package/dist/scene/physics.d.ts +228 -0
- package/dist/scene/physics.d.ts.map +1 -0
- package/dist/scene/physics.js +1500 -0
- package/dist/scene/physics.js.map +1 -0
- package/dist/scene/registry.d.ts +85 -0
- package/dist/scene/registry.d.ts.map +1 -0
- package/dist/scene/registry.js +75 -0
- package/dist/scene/registry.js.map +1 -0
- package/dist/scene/skin.d.ts +82 -0
- package/dist/scene/skin.d.ts.map +1 -0
- package/dist/scene/skin.js +351 -0
- package/dist/scene/skin.js.map +1 -0
- package/dist/scene/sprite.d.ts +36 -0
- package/dist/scene/sprite.d.ts.map +1 -0
- package/dist/scene/sprite.js +107 -0
- package/dist/scene/sprite.js.map +1 -0
- package/dist/scene/viewer.d.ts +96 -0
- package/dist/scene/viewer.d.ts.map +1 -0
- package/dist/scene/viewer.js +235 -0
- package/dist/scene/viewer.js.map +1 -0
- package/dist/scoped-slots.d.ts +9 -0
- package/dist/scoped-slots.d.ts.map +1 -0
- package/dist/scoped-slots.js +42 -0
- package/dist/scoped-slots.js.map +1 -0
- package/dist/screen.d.ts +109 -0
- package/dist/screen.d.ts.map +1 -0
- package/dist/screen.js +309 -0
- package/dist/screen.js.map +1 -0
- package/dist/scroll.d.ts +525 -0
- package/dist/scroll.d.ts.map +1 -0
- package/dist/scroll.js +1226 -0
- package/dist/scroll.js.map +1 -0
- package/dist/settings-plane.d.ts +58 -0
- package/dist/settings-plane.d.ts.map +1 -0
- package/dist/settings-plane.js +86 -0
- package/dist/settings-plane.js.map +1 -0
- package/dist/share-inbox.d.ts +56 -0
- package/dist/share-inbox.d.ts.map +1 -0
- package/dist/share-inbox.js +114 -0
- package/dist/share-inbox.js.map +1 -0
- package/dist/shared-transition.d.ts +152 -0
- package/dist/shared-transition.d.ts.map +1 -0
- package/dist/shared-transition.js +257 -0
- package/dist/shared-transition.js.map +1 -0
- package/dist/sheet-content-padding.d.ts +24 -0
- package/dist/sheet-content-padding.d.ts.map +1 -0
- package/dist/sheet-content-padding.js +32 -0
- package/dist/sheet-content-padding.js.map +1 -0
- package/dist/shot-devices.d.ts +36 -0
- package/dist/shot-devices.d.ts.map +1 -0
- package/dist/shot-devices.js +90 -0
- package/dist/shot-devices.js.map +1 -0
- package/dist/shot-guards.d.ts +100 -0
- package/dist/shot-guards.d.ts.map +1 -0
- package/dist/shot-guards.js +260 -0
- package/dist/shot-guards.js.map +1 -0
- package/dist/shot-scope.d.ts +140 -0
- package/dist/shot-scope.d.ts.map +1 -0
- package/dist/shot-scope.js +302 -0
- package/dist/shot-scope.js.map +1 -0
- package/dist/slot-partition.d.ts +9 -0
- package/dist/slot-partition.d.ts.map +1 -0
- package/dist/slot-partition.js +38 -0
- package/dist/slot-partition.js.map +1 -0
- package/dist/snackbar.d.ts +165 -0
- package/dist/snackbar.d.ts.map +1 -0
- package/dist/snackbar.js +220 -0
- package/dist/snackbar.js.map +1 -0
- package/dist/socket.d.ts +96 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +370 -0
- package/dist/socket.js.map +1 -0
- package/dist/spotlight.d.ts +77 -0
- package/dist/spotlight.d.ts.map +1 -0
- package/dist/spotlight.js +174 -0
- package/dist/spotlight.js.map +1 -0
- package/dist/state-primitive.d.ts +37 -0
- package/dist/state-primitive.d.ts.map +1 -0
- package/dist/state-primitive.js +91 -0
- package/dist/state-primitive.js.map +1 -0
- package/dist/store-query.d.ts +25 -0
- package/dist/store-query.d.ts.map +1 -0
- package/dist/store-query.js +88 -0
- package/dist/store-query.js.map +1 -0
- package/dist/store-value.d.ts +48 -0
- package/dist/store-value.d.ts.map +1 -0
- package/dist/store-value.js +264 -0
- package/dist/store-value.js.map +1 -0
- package/dist/store-versioning.d.ts +70 -0
- package/dist/store-versioning.d.ts.map +1 -0
- package/dist/store-versioning.js +188 -0
- package/dist/store-versioning.js.map +1 -0
- package/dist/store.d.ts +282 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +1144 -0
- package/dist/store.js.map +1 -0
- package/dist/strings.d.ts +141 -0
- package/dist/strings.d.ts.map +1 -0
- package/dist/strings.js +581 -0
- package/dist/strings.js.map +1 -0
- package/dist/telemetry.d.ts +95 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +255 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/transform-core.d.ts +228 -0
- package/dist/transform-core.d.ts.map +1 -0
- package/dist/transform-core.js +921 -0
- package/dist/transform-core.js.map +1 -0
- package/dist/transition-core.d.ts +58 -0
- package/dist/transition-core.d.ts.map +1 -0
- package/dist/transition-core.js +352 -0
- package/dist/transition-core.js.map +1 -0
- package/dist/trim-trailing.d.ts +3 -0
- package/dist/trim-trailing.d.ts.map +1 -0
- package/dist/trim-trailing.js +14 -0
- package/dist/trim-trailing.js.map +1 -0
- package/dist/upload.d.ts +51 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +68 -0
- package/dist/upload.js.map +1 -0
- package/dist/vendor-face.d.ts +44 -0
- package/dist/vendor-face.d.ts.map +1 -0
- package/dist/vendor-face.js +80 -0
- package/dist/vendor-face.js.map +1 -0
- package/dist/vendor-session.d.ts +166 -0
- package/dist/vendor-session.d.ts.map +1 -0
- package/dist/vendor-session.js +423 -0
- package/dist/vendor-session.js.map +1 -0
- package/dist/vendor-surface.d.ts +290 -0
- package/dist/vendor-surface.d.ts.map +1 -0
- package/dist/vendor-surface.js +439 -0
- package/dist/vendor-surface.js.map +1 -0
- package/dist/version-rules.generated.d.ts +17 -0
- package/dist/version-rules.generated.d.ts.map +1 -0
- package/dist/version-rules.generated.js +99 -0
- package/dist/version-rules.generated.js.map +1 -0
- package/dist/view-transition-core.d.ts +99 -0
- package/dist/view-transition-core.d.ts.map +1 -0
- package/dist/view-transition-core.js +127 -0
- package/dist/view-transition-core.js.map +1 -0
- package/dist/view-transition-door.d.ts +26 -0
- package/dist/view-transition-door.d.ts.map +1 -0
- package/dist/view-transition-door.js +88 -0
- package/dist/view-transition-door.js.map +1 -0
- package/dist/window-identity.d.ts +3 -0
- package/dist/window-identity.d.ts.map +1 -0
- package/dist/window-identity.js +27 -0
- package/dist/window-identity.js.map +1 -0
- package/package.json +139 -4
|
@@ -0,0 +1,1440 @@
|
|
|
1
|
+
//
|
|
2
|
+
// audio-core.ts - the pure laws of the audio subsystem (proposals/audio-revamp.md, Phase 2 row
|
|
3
|
+
// audio-laws-corpus): graph validation, normalization, the stream/mix tier fold, reconcile by
|
|
4
|
+
// node id, verb arguments, the session fold, interruptions, duck rules, the queue, routes, the
|
|
5
|
+
// project document and BS.1770 loudness. Core/Audio's arbiter and engines apply these on every
|
|
6
|
+
// renderer; the corpus is OpenSource/Conformance/audio and the twins are Kotlin :core AudioCore.kt
|
|
7
|
+
// and Engine/Swift/AudioCore.swift. Times are seconds everywhere.
|
|
8
|
+
//
|
|
9
|
+
import { parseFilePath } from "./filepaths.js";
|
|
10
|
+
import { audioValidateEffect } from "./audio-mix.js";
|
|
11
|
+
import { foldRecorderFormat } from "./recorder-core.js";
|
|
12
|
+
import { JSE, StackStore } from "./jse/jse.js";
|
|
13
|
+
import { trimTrailing } from "./trim-trailing.js";
|
|
14
|
+
import { normalizeAudioTrackRequest } from "./playback-core.js";
|
|
15
|
+
/** The recorder format fold (Conformance/recorder lifecycle.json formats), for the capture seam's writers. */
|
|
16
|
+
export const audioFoldFormat = foldRecorderFormat;
|
|
17
|
+
export const AUDIO_KINDS = ["player", "bus", "tap", "input", "output"];
|
|
18
|
+
export const AUDIO_INTENTS = ["media", "spoken", "ambient", "sfx", "voice"];
|
|
19
|
+
export const AUDIO_OTHERS = ["interrupt", "duck", "mix"];
|
|
20
|
+
export const AUDIO_LOOP = ["off", "one", "all"];
|
|
21
|
+
export const AUDIO_PITCH = ["preserve", "natural"];
|
|
22
|
+
/** Whether the system may spatialize a player (AVPlayerItem.allowedAudioSpatializationFormats, AudioAttributes spatialization behavior). */
|
|
23
|
+
export const AUDIO_SPATIALIZATION = ["auto", "never"];
|
|
24
|
+
export const AUDIO_CACHE = ["stream", "cache"];
|
|
25
|
+
export const AUDIO_MEASURES = ["level", "spectrum", "waveform", "vad", "pitch"];
|
|
26
|
+
export const AUDIO_EFFECTS = [
|
|
27
|
+
"eq", "compressor", "limiter", "gate", "reverb", "delay", "distortion", "pitch", "filter", "space", "loudness",
|
|
28
|
+
];
|
|
29
|
+
export const AUDIO_VERBS = ["graph.set", "set", "play", "pause", "stop", "seek", "route.pick", "route.set"];
|
|
30
|
+
export const AUDIO_RECORD_VERBS = ["record.start", "record.pause", "record.resume", "record.stop"];
|
|
31
|
+
export const AUDIO_EDIT_VERBS = ["edit.render", "edit.analyze"];
|
|
32
|
+
export const AUDIO_ERRORS = [
|
|
33
|
+
"invalid_graph", "invalid_id", "invalid_value", "unknown_value", "unknown_node", "bus_cycle", "out_of_range",
|
|
34
|
+
"invalid_source", "stream_tier_only",
|
|
35
|
+
];
|
|
36
|
+
export const AUDIO_SOURCE_URLS = ["https:"];
|
|
37
|
+
/** A claim's preferred hardware, in the order a request is kept (claims.json). */
|
|
38
|
+
export const AUDIO_HARDWARE_KEYS = ["sampleRate", "bufferDuration", "inputChannels", "outputChannels"];
|
|
39
|
+
export const AUDIO_LIMITS = Object.freeze({
|
|
40
|
+
gainMin: 0, gainMax: 2, panMin: -1, panMax: 1, rateMin: 0.25, rateMax: 4, tapRateMax: 60, removeFade: 0.01, duckRamp: 0.25,
|
|
41
|
+
});
|
|
42
|
+
/** The socket endpoint law (Conformance/audio/socket.json): pcm16 on the wire, 24 kHz by default, 20 ms chunks. */
|
|
43
|
+
export const AUDIO_SOCKET = Object.freeze({ format: "pcm16", rate: 24000, rateMin: 8000, rateMax: 48000, chunkMs: 20 });
|
|
44
|
+
export const AUDIO_SESSION_ORDER = ["call", "voice", "record", "spoken", "media", "ambient"];
|
|
45
|
+
export const AUDIO_PREV_RESTART = 3;
|
|
46
|
+
export const AUDIO_RESUME_END_TOLERANCE = 5;
|
|
47
|
+
export const AUDIO_POSITION_INTERVAL = 1;
|
|
48
|
+
export const AUDIO_SAMPLE_RATES = [8000, 16000, 22050, 24000, 32000, 44100, 48000, 88200, 96000];
|
|
49
|
+
const MAIN = "main";
|
|
50
|
+
const SAMPLE_MEASURES = ["waveform", "vad", "pitch"];
|
|
51
|
+
function isDict(v) {
|
|
52
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
53
|
+
}
|
|
54
|
+
function isNum(v) {
|
|
55
|
+
return typeof v === "number" && Number.isFinite(v);
|
|
56
|
+
}
|
|
57
|
+
function inRange(v, lo, hi) {
|
|
58
|
+
return isNum(v) && v >= lo && v <= hi;
|
|
59
|
+
}
|
|
60
|
+
function round4(x) {
|
|
61
|
+
return Math.sign(x) * Math.round(Math.abs(x) * 1e4) / 1e4 + 0;
|
|
62
|
+
}
|
|
63
|
+
function roundHalfAway(x) {
|
|
64
|
+
return Math.sign(x) * Math.round(Math.abs(x)) + 0;
|
|
65
|
+
}
|
|
66
|
+
function canonical(v) {
|
|
67
|
+
if (Array.isArray(v))
|
|
68
|
+
return "[" + v.map(canonical).join(",") + "]";
|
|
69
|
+
if (isDict(v))
|
|
70
|
+
return "{" + Object.keys(v).sort().map((k) => JSON.stringify(k) + ":" + canonical(v[k])).join(",") + "}";
|
|
71
|
+
return JSON.stringify(v ?? null);
|
|
72
|
+
}
|
|
73
|
+
/** An https URL or a Core/Files path naming a file (the Files path law, so it never escapes its
|
|
74
|
+
* root); never an absolute path, a file: URL or inline bytes. */
|
|
75
|
+
export function audioIsSource(v) {
|
|
76
|
+
if (typeof v !== "string")
|
|
77
|
+
return false;
|
|
78
|
+
if (v.startsWith("https://"))
|
|
79
|
+
return v.length > "https://".length;
|
|
80
|
+
const parsed = parseFilePath(v);
|
|
81
|
+
return parsed.ok && parsed.value.relative !== "";
|
|
82
|
+
}
|
|
83
|
+
function isHls(src) {
|
|
84
|
+
return typeof src === "string" && /\.m3u8(?:[?#]|$)/i.test(src);
|
|
85
|
+
}
|
|
86
|
+
// ─── graph: normalize ──────────────────────────────────────────────────────────────────────────
|
|
87
|
+
function mixable(n, isMain) {
|
|
88
|
+
return {
|
|
89
|
+
id: n["id"], kind: n["kind"], to: isMain ? null : (n["to"] ?? MAIN),
|
|
90
|
+
gain: n["gain"] ?? 1, pan: n["pan"] ?? 0, mute: n["mute"] ?? false,
|
|
91
|
+
effects: n["effects"] ?? [], duck: n["duck"] ?? null,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function normalizeItems(n) {
|
|
95
|
+
if (Array.isArray(n["items"])) {
|
|
96
|
+
return n["items"].map((it, i) => {
|
|
97
|
+
const item = isDict(it) ? it : {};
|
|
98
|
+
return { ...item, id: item["id"] ?? String(i) };
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (n["src"] !== undefined)
|
|
102
|
+
return [{ id: n["id"], src: n["src"] }];
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
function normalizeNode(n) {
|
|
106
|
+
const kind = n["kind"];
|
|
107
|
+
if (kind === "player") {
|
|
108
|
+
const intent = n["intent"] ?? "media";
|
|
109
|
+
return {
|
|
110
|
+
...mixable(n, false),
|
|
111
|
+
intent, items: normalizeItems(n), index: n["index"] ?? 0, loop: n["loop"] ?? "off",
|
|
112
|
+
shuffle: n["shuffle"] ?? false, rate: n["rate"] ?? 1, pitch: n["pitch"] ?? "preserve", spatialization: n["spatialization"] ?? "auto",
|
|
113
|
+
audioTrack: n["audioTrack"] ?? "default", subtitle: n["subtitle"] ?? "off",
|
|
114
|
+
crossfade: n["crossfade"] ?? 0, gapless: n["gapless"] ?? true, nowPlaying: n["nowPlaying"] ?? false,
|
|
115
|
+
remote: n["remote"] ?? null, sleep: n["sleep"] ?? null, resume: n["resume"] ?? null,
|
|
116
|
+
cache: n["cache"] ?? "stream", voices: n["voices"] ?? 1, preload: n["preload"] ?? false,
|
|
117
|
+
background: n["background"] ?? (intent === "media" || intent === "spoken" || intent === "voice"),
|
|
118
|
+
project: n["project"] ?? null, socket: n["socket"] ?? null,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (kind === "bus")
|
|
122
|
+
return mixable(n, n["id"] === MAIN);
|
|
123
|
+
if (kind === "input") {
|
|
124
|
+
return {
|
|
125
|
+
...mixable(n, false),
|
|
126
|
+
source: n["source"] ?? "mic", voiceProcessing: n["voiceProcessing"] ?? false,
|
|
127
|
+
monitor: n["monitor"] ?? false, channels: n["channels"] ?? 1,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (kind === "tap") {
|
|
131
|
+
const m = n["measure"];
|
|
132
|
+
return {
|
|
133
|
+
id: n["id"], kind, of: n["of"] ?? null,
|
|
134
|
+
measure: Array.isArray(m) ? m : (typeof m === "string" ? [m] : []),
|
|
135
|
+
bands: n["bands"] ?? 16, rate: n["rate"] ?? 30,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (kind === "output")
|
|
139
|
+
return { id: n["id"], kind, from: n["from"] ?? null, socket: n["socket"] ?? null };
|
|
140
|
+
return { ...n };
|
|
141
|
+
}
|
|
142
|
+
/** The graph every engine receives: defaults filled, `main` always present. Assumes a valid graph. */
|
|
143
|
+
export function audioNormalizeGraph(graph) {
|
|
144
|
+
const g = isDict(graph) ? graph : {};
|
|
145
|
+
const raw = Array.isArray(g["nodes"]) ? g["nodes"].filter(isDict) : [];
|
|
146
|
+
const nodes = raw.map(normalizeNode);
|
|
147
|
+
if (!nodes.some((n) => n["id"] === MAIN))
|
|
148
|
+
nodes.push(mixable({ id: MAIN, kind: "bus" }, true));
|
|
149
|
+
return { others: g["others"] ?? "interrupt", nodes };
|
|
150
|
+
}
|
|
151
|
+
// ─── graph: validate ───────────────────────────────────────────────────────────────────────────
|
|
152
|
+
function checkEffects(effects, path, live, errors) {
|
|
153
|
+
if (effects === undefined)
|
|
154
|
+
return;
|
|
155
|
+
if (!Array.isArray(effects)) {
|
|
156
|
+
errors.push(`invalid_value@${path}`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
effects.forEach((e, j) => {
|
|
160
|
+
if (!isDict(e)) {
|
|
161
|
+
errors.push(`invalid_value@${path}[${j}]`);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const type = e["type"];
|
|
165
|
+
const p = `${path}[${j}].type`;
|
|
166
|
+
if (typeof type !== "string" || !AUDIO_EFFECTS.includes(type)) {
|
|
167
|
+
errors.push(`unknown_value@${p}`);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
// The one effect-parameter table (audio-mix.ts, Conformance/audio/effects.json): every
|
|
171
|
+
// parameter is checked at its own path, and a misspelt one is refused, never ignored.
|
|
172
|
+
errors.push(...audioValidateEffect(e, `${path}[${j}]`));
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function checkWord(n, key, words, path, errors) {
|
|
177
|
+
if (n[key] !== undefined && !(typeof n[key] === "string" && words.includes(n[key]))) {
|
|
178
|
+
errors.push(`unknown_value@${path}.${key}`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** `audioTrack` (`<bcp47>|default`) and `subtitle` (`<bcp47>|off`): the one word, or a BCP 47 shaped tag as the
|
|
182
|
+
* playback selection law reads one (Conformance/media/playback-selection.json `normalizeAudioTrackRequest`, which
|
|
183
|
+
* folds anything that is not a tag to `default`); anything else is `invalid_value` at its path. */
|
|
184
|
+
function checkLanguage(n, key, word, path, errors) {
|
|
185
|
+
const v = n[key];
|
|
186
|
+
if (v === undefined)
|
|
187
|
+
return;
|
|
188
|
+
const t = typeof v === "string" ? v.trim() : "";
|
|
189
|
+
if (t.toLowerCase() === word)
|
|
190
|
+
return;
|
|
191
|
+
if (t === "" || normalizeAudioTrackRequest(t) === "default")
|
|
192
|
+
errors.push(`invalid_value@${path}.${key}`);
|
|
193
|
+
}
|
|
194
|
+
function checkRange(n, key, lo, hi, path, errors) {
|
|
195
|
+
if (n[key] !== undefined && !inRange(n[key], lo, hi))
|
|
196
|
+
errors.push(`out_of_range@${path}.${key}`);
|
|
197
|
+
}
|
|
198
|
+
function checkPlayerSources(n, p, errors) {
|
|
199
|
+
if (Array.isArray(n["items"])) {
|
|
200
|
+
n["items"].forEach((it, j) => {
|
|
201
|
+
const item = isDict(it) ? it : {};
|
|
202
|
+
if (!audioIsSource(item["src"]))
|
|
203
|
+
errors.push(`invalid_source@${p}.items[${j}].src`);
|
|
204
|
+
for (const key of ["artwork", "transcript"]) {
|
|
205
|
+
if (item[key] !== undefined && !audioIsSource(item[key]))
|
|
206
|
+
errors.push(`invalid_source@${p}.items[${j}].${key}`);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
if (n["items"].length > 0)
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
else if (n["src"] !== undefined) {
|
|
213
|
+
if (!audioIsSource(n["src"]))
|
|
214
|
+
errors.push(`invalid_source@${p}.items[0].src`);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (n["project"] === undefined && n["socket"] === undefined)
|
|
218
|
+
errors.push(`invalid_source@${p}.items`);
|
|
219
|
+
}
|
|
220
|
+
/** A socket endpoint (Conformance/audio/socket.json): names its block by `as`, speaks pcm16 at 8000 to 48000 Hz,
|
|
221
|
+
* `frame` is an output's JSE and `unframe` a player's. */
|
|
222
|
+
function checkSocket(s, kind, p, errors) {
|
|
223
|
+
if (!isDict(s)) {
|
|
224
|
+
errors.push(`invalid_value@${p}`);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (!(typeof s["as"] === "string" && s["as"] !== ""))
|
|
228
|
+
errors.push(`invalid_value@${p}.as`);
|
|
229
|
+
if (s["format"] !== undefined && s["format"] !== AUDIO_SOCKET.format)
|
|
230
|
+
errors.push(`unknown_value@${p}.format`);
|
|
231
|
+
if (s["rate"] !== undefined && !(Number.isInteger(s["rate"]) && s["rate"] >= AUDIO_SOCKET.rateMin && s["rate"] <= AUDIO_SOCKET.rateMax)) {
|
|
232
|
+
errors.push(`out_of_range@${p}.rate`);
|
|
233
|
+
}
|
|
234
|
+
if (s["frame"] !== undefined && !(kind === "output" && typeof s["frame"] === "string"))
|
|
235
|
+
errors.push(`invalid_value@${p}.frame`);
|
|
236
|
+
if (s["unframe"] !== undefined && !(kind === "player" && typeof s["unframe"] === "string"))
|
|
237
|
+
errors.push(`invalid_value@${p}.unframe`);
|
|
238
|
+
}
|
|
239
|
+
/** Every problem in a graph as `code@path`, in discovery order; empty when the graph is valid. */
|
|
240
|
+
export function audioValidateGraph(graph) {
|
|
241
|
+
if (!isDict(graph))
|
|
242
|
+
return ["invalid_graph@graph"];
|
|
243
|
+
const errors = [];
|
|
244
|
+
if (graph["others"] !== undefined && !(typeof graph["others"] === "string" && AUDIO_OTHERS.includes(graph["others"]))) {
|
|
245
|
+
errors.push("unknown_value@others");
|
|
246
|
+
}
|
|
247
|
+
const list = graph["nodes"];
|
|
248
|
+
if (!Array.isArray(list))
|
|
249
|
+
return [...errors, "invalid_graph@nodes"];
|
|
250
|
+
const kinds = new Map([[MAIN, "bus"]]);
|
|
251
|
+
const seen = new Set();
|
|
252
|
+
for (const n of list) {
|
|
253
|
+
if (isDict(n) && typeof n["id"] === "string" && n["id"] !== "" && typeof n["kind"] === "string" && !seen.has(n["id"])) {
|
|
254
|
+
seen.add(n["id"]);
|
|
255
|
+
kinds.set(n["id"], n["kind"]);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const ids = new Set();
|
|
259
|
+
list.forEach((n, i) => {
|
|
260
|
+
const p = `nodes[${i}]`;
|
|
261
|
+
if (!isDict(n)) {
|
|
262
|
+
errors.push(`invalid_graph@${p}`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const id = n["id"];
|
|
266
|
+
const kind = n["kind"];
|
|
267
|
+
if (typeof id !== "string" || id === "" || ids.has(id) || (id === MAIN && kind !== "bus")) {
|
|
268
|
+
errors.push(`invalid_id@${p}.id`);
|
|
269
|
+
}
|
|
270
|
+
if (typeof id === "string")
|
|
271
|
+
ids.add(id);
|
|
272
|
+
if (typeof kind !== "string" || !AUDIO_KINDS.includes(kind)) {
|
|
273
|
+
errors.push(`unknown_value@${p}.kind`);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (kind === "player" || kind === "bus" || kind === "input") {
|
|
277
|
+
if (kind === "bus" && id === MAIN) {
|
|
278
|
+
if (n["to"] !== undefined && n["to"] !== null)
|
|
279
|
+
errors.push(`invalid_value@${p}.to`);
|
|
280
|
+
}
|
|
281
|
+
else if (n["to"] !== undefined && !(typeof n["to"] === "string" && kinds.get(n["to"]) === "bus")) {
|
|
282
|
+
errors.push(`unknown_node@${p}.to`);
|
|
283
|
+
}
|
|
284
|
+
checkRange(n, "gain", AUDIO_LIMITS.gainMin, AUDIO_LIMITS.gainMax, p, errors);
|
|
285
|
+
checkRange(n, "pan", AUDIO_LIMITS.panMin, AUDIO_LIMITS.panMax, p, errors);
|
|
286
|
+
checkEffects(n["effects"], `${p}.effects`, true, errors);
|
|
287
|
+
const duck = n["duck"];
|
|
288
|
+
if (duck !== undefined && duck !== null) {
|
|
289
|
+
if (!isDict(duck)) {
|
|
290
|
+
errors.push(`invalid_value@${p}.duck`);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
const when = duck["when"];
|
|
294
|
+
if (!Array.isArray(when) || when.length === 0 || !when.every((w) => typeof w === "string"))
|
|
295
|
+
errors.push(`invalid_value@${p}.duck.when`);
|
|
296
|
+
if (!inRange(duck["to"], 0, 1))
|
|
297
|
+
errors.push(`out_of_range@${p}.duck.to`);
|
|
298
|
+
if (duck["ramp"] !== undefined && !inRange(duck["ramp"], 0, Infinity))
|
|
299
|
+
errors.push(`out_of_range@${p}.duck.ramp`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (kind === "player") {
|
|
304
|
+
checkWord(n, "intent", AUDIO_INTENTS, p, errors);
|
|
305
|
+
checkWord(n, "loop", AUDIO_LOOP, p, errors);
|
|
306
|
+
checkWord(n, "pitch", AUDIO_PITCH, p, errors);
|
|
307
|
+
checkWord(n, "spatialization", AUDIO_SPATIALIZATION, p, errors);
|
|
308
|
+
checkLanguage(n, "audioTrack", "default", p, errors);
|
|
309
|
+
checkLanguage(n, "subtitle", "off", p, errors);
|
|
310
|
+
checkWord(n, "cache", AUDIO_CACHE, p, errors);
|
|
311
|
+
checkRange(n, "rate", AUDIO_LIMITS.rateMin, AUDIO_LIMITS.rateMax, p, errors);
|
|
312
|
+
checkRange(n, "crossfade", 0, Infinity, p, errors);
|
|
313
|
+
if (n["voices"] !== undefined && !(Number.isInteger(n["voices"]) && n["voices"] >= 1))
|
|
314
|
+
errors.push(`out_of_range@${p}.voices`);
|
|
315
|
+
checkPlayerSources(n, p, errors);
|
|
316
|
+
if (n["socket"] !== undefined)
|
|
317
|
+
checkSocket(n["socket"], kind, `${p}.socket`, errors);
|
|
318
|
+
}
|
|
319
|
+
else if (kind === "tap") {
|
|
320
|
+
if (!(typeof n["of"] === "string" && kinds.has(n["of"])))
|
|
321
|
+
errors.push(`unknown_node@${p}.of`);
|
|
322
|
+
const m = n["measure"];
|
|
323
|
+
if (typeof m === "string") {
|
|
324
|
+
if (!AUDIO_MEASURES.includes(m))
|
|
325
|
+
errors.push(`unknown_value@${p}.measure`);
|
|
326
|
+
}
|
|
327
|
+
else if (Array.isArray(m)) {
|
|
328
|
+
m.forEach((w, j) => { if (typeof w !== "string" || !AUDIO_MEASURES.includes(w))
|
|
329
|
+
errors.push(`unknown_value@${p}.measure[${j}]`); });
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
errors.push(`invalid_value@${p}.measure`);
|
|
333
|
+
}
|
|
334
|
+
if (n["rate"] !== undefined && !(isNum(n["rate"]) && n["rate"] > 0 && n["rate"] <= AUDIO_LIMITS.tapRateMax))
|
|
335
|
+
errors.push(`out_of_range@${p}.rate`);
|
|
336
|
+
if (n["bands"] !== undefined && !(Number.isInteger(n["bands"]) && n["bands"] >= 1))
|
|
337
|
+
errors.push(`out_of_range@${p}.bands`);
|
|
338
|
+
}
|
|
339
|
+
else if (kind === "output") {
|
|
340
|
+
const from = n["from"];
|
|
341
|
+
if (!(typeof from === "string" && kinds.has(from)))
|
|
342
|
+
errors.push(`unknown_node@${p}.from`);
|
|
343
|
+
else if (kinds.get(from) !== "input" && kinds.get(from) !== "bus")
|
|
344
|
+
errors.push(`invalid_value@${p}.from`);
|
|
345
|
+
if (n["socket"] === undefined)
|
|
346
|
+
errors.push(`invalid_value@${p}.socket`);
|
|
347
|
+
else
|
|
348
|
+
checkSocket(n["socket"], kind, `${p}.socket`, errors);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
// A routing loop is reported once, on its earliest member.
|
|
352
|
+
const busTo = new Map();
|
|
353
|
+
const busIndex = new Map();
|
|
354
|
+
list.forEach((n, i) => {
|
|
355
|
+
if (isDict(n) && n["kind"] === "bus" && typeof n["id"] === "string" && n["id"] !== MAIN && typeof n["to"] === "string") {
|
|
356
|
+
if (!busIndex.has(n["id"])) {
|
|
357
|
+
busTo.set(n["id"], n["to"]);
|
|
358
|
+
busIndex.set(n["id"], i);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
const reported = new Set();
|
|
363
|
+
for (const start of busIndex.keys()) {
|
|
364
|
+
const path = [];
|
|
365
|
+
let cur = start;
|
|
366
|
+
while (cur !== undefined && busTo.has(cur) && !path.includes(cur)) {
|
|
367
|
+
path.push(cur);
|
|
368
|
+
cur = busTo.get(cur);
|
|
369
|
+
}
|
|
370
|
+
if (cur === undefined || !path.includes(cur))
|
|
371
|
+
continue;
|
|
372
|
+
const cycle = path.slice(path.indexOf(cur));
|
|
373
|
+
const key = [...cycle].sort().join("|");
|
|
374
|
+
if (reported.has(key))
|
|
375
|
+
continue;
|
|
376
|
+
reported.add(key);
|
|
377
|
+
const first = Math.min(...cycle.map((id) => busIndex.get(id)));
|
|
378
|
+
errors.push(`bus_cycle@nodes[${first}].to`);
|
|
379
|
+
}
|
|
380
|
+
if (audioTier(graph) === "mix") {
|
|
381
|
+
list.forEach((n, i) => {
|
|
382
|
+
if (!isDict(n) || n["kind"] !== "player")
|
|
383
|
+
return;
|
|
384
|
+
if (Array.isArray(n["items"])) {
|
|
385
|
+
n["items"].forEach((it, j) => {
|
|
386
|
+
if (isDict(it) && isHls(it["src"]))
|
|
387
|
+
errors.push(`stream_tier_only@nodes[${i}].items[${j}].src`);
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
else if (isHls(n["src"])) {
|
|
391
|
+
errors.push(`stream_tier_only@nodes[${i}].items[0].src`);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
return errors;
|
|
396
|
+
}
|
|
397
|
+
// ─── graph: tier, reconcile, verbs ─────────────────────────────────────────────────────────────
|
|
398
|
+
/** `stream` (platform players: HLS, AirPlay long-form, DRM, lowest battery) or `mix` (an engine graph). */
|
|
399
|
+
/** A malformed `effects` (validation reports it invalid_value) reads as no effects here, as the Swift core does. */
|
|
400
|
+
function listOf(value) { return Array.isArray(value) ? value : []; }
|
|
401
|
+
export function audioTier(graph) {
|
|
402
|
+
const g = audioNormalizeGraph(graph);
|
|
403
|
+
const buses = new Set(g.nodes.filter((n) => n["kind"] === "bus").map((n) => n["id"]));
|
|
404
|
+
for (const n of g.nodes) {
|
|
405
|
+
const kind = n["kind"];
|
|
406
|
+
if (kind === "input" || kind === "output")
|
|
407
|
+
return "mix";
|
|
408
|
+
if (kind === "bus") {
|
|
409
|
+
if (n["id"] !== MAIN || listOf(n["effects"]).length > 0)
|
|
410
|
+
return "mix";
|
|
411
|
+
}
|
|
412
|
+
else if (kind === "tap") {
|
|
413
|
+
if (buses.has(n["of"]))
|
|
414
|
+
return "mix";
|
|
415
|
+
if (n["measure"].some((m) => SAMPLE_MEASURES.includes(m)))
|
|
416
|
+
return "mix";
|
|
417
|
+
}
|
|
418
|
+
else if (kind === "player") {
|
|
419
|
+
if (n["project"] !== null || n["socket"] !== null || n["voices"] > 1)
|
|
420
|
+
return "mix";
|
|
421
|
+
if (listOf(n["effects"]).some((e) => !isDict(e) || e["type"] !== "eq"))
|
|
422
|
+
return "mix";
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return "stream";
|
|
426
|
+
}
|
|
427
|
+
/** The diff the arbiter applies: a surviving id keeps its engine state, a removed one fades over removeFade. */
|
|
428
|
+
export function audioReconcile(prev, next) {
|
|
429
|
+
const before = prev === null || prev === undefined ? [] : audioNormalizeGraph(prev).nodes;
|
|
430
|
+
const after = audioNormalizeGraph(next).nodes;
|
|
431
|
+
const old = new Map(before.map((n) => [n["id"], n]));
|
|
432
|
+
const out = { keep: [], update: [], add: [], remove: [], replace: [] };
|
|
433
|
+
for (const n of after) {
|
|
434
|
+
const id = n["id"];
|
|
435
|
+
const o = old.get(id);
|
|
436
|
+
if (!o) {
|
|
437
|
+
out.add.push(id);
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (o["kind"] !== n["kind"]) {
|
|
441
|
+
out.replace.push(id);
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
const props = [...new Set([...Object.keys(o), ...Object.keys(n)])]
|
|
445
|
+
.filter((k) => k !== "id" && k !== "kind" && canonical(o[k]) !== canonical(n[k]))
|
|
446
|
+
.sort();
|
|
447
|
+
if (props.length === 0)
|
|
448
|
+
out.keep.push(id);
|
|
449
|
+
else
|
|
450
|
+
out.update.push({ id, props });
|
|
451
|
+
}
|
|
452
|
+
const live = new Set(after.map((n) => n["id"]));
|
|
453
|
+
for (const n of before)
|
|
454
|
+
if (!live.has(n["id"]))
|
|
455
|
+
out.remove.push(n["id"]);
|
|
456
|
+
return out;
|
|
457
|
+
}
|
|
458
|
+
/** The first problem with a verb's arguments as `code@argument`, or null. */
|
|
459
|
+
export function audioValidateVerb(verb, args, graph) {
|
|
460
|
+
if (!AUDIO_VERBS.includes(verb))
|
|
461
|
+
return "unknown_value@verb";
|
|
462
|
+
const a = isDict(args) ? args : {};
|
|
463
|
+
if (verb === "graph.set")
|
|
464
|
+
return a["graph"] === undefined || a["graph"] === null ? "invalid_graph@graph" : null;
|
|
465
|
+
if (verb === "route.pick")
|
|
466
|
+
return null;
|
|
467
|
+
if (verb === "route.set")
|
|
468
|
+
return typeof a["output"] === "string" && a["output"] !== "" ? null : "invalid_value@output";
|
|
469
|
+
const id = a["id"];
|
|
470
|
+
if (typeof id !== "string" || id === "")
|
|
471
|
+
return "invalid_id@id";
|
|
472
|
+
const g = audioNormalizeGraph(graph);
|
|
473
|
+
const node = g.nodes.find((n) => n["id"] === id);
|
|
474
|
+
if (!node)
|
|
475
|
+
return "unknown_node@id";
|
|
476
|
+
if (verb === "set")
|
|
477
|
+
return validateSet(graph, node, a);
|
|
478
|
+
// An input follows play, pause and stop like a player: the microphone opens only on
|
|
479
|
+
// an explicit verb. It has no graph-clock start and nothing to seek.
|
|
480
|
+
if (node["kind"] === "input") {
|
|
481
|
+
if (verb === "play")
|
|
482
|
+
return a["at"] !== undefined ? "invalid_value@at" : null;
|
|
483
|
+
return verb === "pause" || verb === "stop" ? null : "invalid_value@id";
|
|
484
|
+
}
|
|
485
|
+
if (node["kind"] !== "player")
|
|
486
|
+
return "invalid_value@id";
|
|
487
|
+
if (verb === "play") {
|
|
488
|
+
return a["at"] !== undefined && !inRange(a["at"], 0, Infinity) ? "out_of_range@at" : null;
|
|
489
|
+
}
|
|
490
|
+
if (verb === "seek") {
|
|
491
|
+
const targets = ["to", "by", "item", "chapter"].filter((k) => a[k] !== undefined && a[k] !== null);
|
|
492
|
+
if (targets.length !== 1)
|
|
493
|
+
return "invalid_value@to";
|
|
494
|
+
const key = targets[0];
|
|
495
|
+
const v = a[key];
|
|
496
|
+
if (key === "to")
|
|
497
|
+
return inRange(v, 0, Infinity) ? null : "out_of_range@to";
|
|
498
|
+
if (key === "by")
|
|
499
|
+
return isNum(v) ? null : "out_of_range@by";
|
|
500
|
+
if (key === "item") {
|
|
501
|
+
const items = node["items"];
|
|
502
|
+
if (typeof v === "number")
|
|
503
|
+
return Number.isInteger(v) && v >= 0 && v < items.length ? null : "out_of_range@item";
|
|
504
|
+
if (v === "next" || v === "prev")
|
|
505
|
+
return null;
|
|
506
|
+
return items.some((it) => it["id"] === v) ? null : "unknown_value@item";
|
|
507
|
+
}
|
|
508
|
+
if (v === "next" || v === "prev" || (Number.isInteger(v) && v >= 0))
|
|
509
|
+
return null;
|
|
510
|
+
return "invalid_value@chapter";
|
|
511
|
+
}
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
/** The argument law of `capture`, Core/Audio's native-bus-only seam for the Record child (graph.json
|
|
515
|
+
* `capture`): one op per call, start `{ owner, from, path, format, sampleRate?, channels? }`, pause or resume
|
|
516
|
+
* `{ owner, paused }`, status `{ owner }`, finish `{ owner, release: true }`; or a frames start
|
|
517
|
+
* `{ owner, frames: { format, rate? }, from?, channels? }` (validateFramesCapture). `tier` is the graph's live tier. */
|
|
518
|
+
export function audioValidateCapture(args, graph, tier) {
|
|
519
|
+
const a = isDict(args) ? args : {};
|
|
520
|
+
if (typeof a["owner"] !== "string" || a["owner"] === "")
|
|
521
|
+
return "invalid_value@owner";
|
|
522
|
+
if (a["release"] === true)
|
|
523
|
+
return null;
|
|
524
|
+
if (a["paused"] !== undefined)
|
|
525
|
+
return typeof a["paused"] === "boolean" ? null : "invalid_value@paused";
|
|
526
|
+
if (a["frames"] !== undefined)
|
|
527
|
+
return validateFramesCapture(a, graph, tier);
|
|
528
|
+
if (a["from"] === undefined)
|
|
529
|
+
return null;
|
|
530
|
+
const source = validateCaptureSource(a["from"], graph, tier);
|
|
531
|
+
if (source !== null)
|
|
532
|
+
return source;
|
|
533
|
+
if (foldRecorderFormat(a["format"]) === null)
|
|
534
|
+
return "unsupported_format@format";
|
|
535
|
+
if (typeof a["path"] !== "string" || a["path"] === "")
|
|
536
|
+
return "invalid_value@path";
|
|
537
|
+
if (a["sampleRate"] !== undefined && !inRange(a["sampleRate"], 8000, 192000))
|
|
538
|
+
return "out_of_range@sampleRate";
|
|
539
|
+
if (a["channels"] !== undefined && a["channels"] !== 1 && a["channels"] !== 2)
|
|
540
|
+
return "out_of_range@channels";
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
/** The input-or-bus law of a capture's `from` (a file start and a frames start share it). */
|
|
544
|
+
function validateCaptureSource(from, graph, tier) {
|
|
545
|
+
const node = audioNormalizeGraph(graph).nodes.find((n) => n["id"] === from);
|
|
546
|
+
if (!node)
|
|
547
|
+
return "unknown_node@from";
|
|
548
|
+
if (node["kind"] !== "input" && node["kind"] !== "bus")
|
|
549
|
+
return "invalid_value@from";
|
|
550
|
+
if (node["kind"] === "bus" && tier !== "mix")
|
|
551
|
+
return "mix_unavailable@from";
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
/** A frames start: `frames: { format: "pcm16" | "f32", rate? }` in place of a file, one sink per
|
|
555
|
+
* capture; `from` is optional (absent = the device microphone through Core/Audio's own input). */
|
|
556
|
+
function validateFramesCapture(a, graph, tier) {
|
|
557
|
+
const f = a["frames"];
|
|
558
|
+
if (!isDict(f))
|
|
559
|
+
return "invalid_value@frames";
|
|
560
|
+
if (f["format"] !== "pcm16" && f["format"] !== "f32")
|
|
561
|
+
return "invalid_value@frames.format";
|
|
562
|
+
if (f["rate"] !== undefined && !inRange(f["rate"], 8000, 192000))
|
|
563
|
+
return "out_of_range@frames.rate";
|
|
564
|
+
if (a["path"] !== undefined)
|
|
565
|
+
return "invalid_value@path";
|
|
566
|
+
if (a["format"] !== undefined)
|
|
567
|
+
return "invalid_value@format";
|
|
568
|
+
if (a["sampleRate"] !== undefined)
|
|
569
|
+
return "invalid_value@sampleRate";
|
|
570
|
+
if (a["channels"] !== undefined && a["channels"] !== 1 && a["channels"] !== 2)
|
|
571
|
+
return "out_of_range@channels";
|
|
572
|
+
return a["from"] === undefined ? null : validateCaptureSource(a["from"], graph, tier);
|
|
573
|
+
}
|
|
574
|
+
function validateSet(graph, node, a) {
|
|
575
|
+
if (a["kind"] !== undefined)
|
|
576
|
+
return "invalid_value@kind";
|
|
577
|
+
const props = Object.keys(a).filter((k) => k !== "id" && k !== "ramp");
|
|
578
|
+
for (const k of props)
|
|
579
|
+
if (!(k in node))
|
|
580
|
+
return `invalid_value@${k}`;
|
|
581
|
+
if (a["ramp"] !== undefined && !inRange(a["ramp"], 0, Infinity))
|
|
582
|
+
return "out_of_range@ramp";
|
|
583
|
+
const raw = isDict(graph) && Array.isArray(graph["nodes"]) ? graph["nodes"] : [];
|
|
584
|
+
const index = raw.findIndex((n) => isDict(n) && n["id"] === node["id"]);
|
|
585
|
+
if (index < 0)
|
|
586
|
+
return null;
|
|
587
|
+
const merged = { ...raw[index] };
|
|
588
|
+
for (const k of props)
|
|
589
|
+
merged[k] = a[k];
|
|
590
|
+
const nodes = [...raw];
|
|
591
|
+
nodes[index] = merged;
|
|
592
|
+
const prefix = `nodes[${index}].`;
|
|
593
|
+
for (const e of audioValidateGraph({ ...graph, nodes })) {
|
|
594
|
+
const at = e.indexOf("@");
|
|
595
|
+
const path = e.slice(at + 1);
|
|
596
|
+
if (path.startsWith(prefix))
|
|
597
|
+
return `${e.slice(0, at)}@${path.slice(prefix.length)}`;
|
|
598
|
+
}
|
|
599
|
+
return null;
|
|
600
|
+
}
|
|
601
|
+
/** The one session the arbiter applies, from what is sounding, `others` and the bus claims. */
|
|
602
|
+
/** `unprocessed`: the record claim holding the session asked for capture with no voice processing, automatic gain
|
|
603
|
+
* or noise suppression (claims.json): iOS mode measurement, Android source unprocessed (the adapter falls back to
|
|
604
|
+
* voiceRecognition where the device does not support it), web capture with every processing constraint off.
|
|
605
|
+
* `hapticsDuringRecording`: a live claim asked that haptics and system sounds keep playing while the app records
|
|
606
|
+
* (claims.json): iOS AVAudioSession.setAllowHapticsAndSystemSoundsDuringRecording, carried on every iOS fold; Android
|
|
607
|
+
* and the web have no such setting, because neither silences vibration while capturing. */
|
|
608
|
+
export function audioSessionFold(graph, sounding, claims, unprocessed = false, hapticsDuringRecording = false) {
|
|
609
|
+
const g = audioNormalizeGraph(graph);
|
|
610
|
+
const live = new Set();
|
|
611
|
+
for (const n of g.nodes) {
|
|
612
|
+
if (!sounding.includes(n["id"]))
|
|
613
|
+
continue;
|
|
614
|
+
if (n["kind"] === "player")
|
|
615
|
+
live.add(n["intent"] === "sfx" ? "ambient" : n["intent"]);
|
|
616
|
+
else if (n["kind"] === "input")
|
|
617
|
+
live.add(n["voiceProcessing"] === true ? "voice" : "record");
|
|
618
|
+
}
|
|
619
|
+
for (const c of claims)
|
|
620
|
+
live.add(c === "video" ? "media" : c === "speech" ? "spoken" : c);
|
|
621
|
+
const claim = AUDIO_SESSION_ORDER.find((c) => live.has(c));
|
|
622
|
+
if (!claim)
|
|
623
|
+
return { claim: "none", ios: null, android: null, web: null };
|
|
624
|
+
const others = g.others;
|
|
625
|
+
const othersOption = others === "duck" ? ["duckOthers"] : others === "mix" ? ["mixWithOthers"] : [];
|
|
626
|
+
const focus = (base) => others === "duck" ? "gainTransientMayDuck" : others === "mix" ? "none" : base;
|
|
627
|
+
const ios = (category, mode, options, policy, voiceProcessing) => ({ category, mode, options: [...options].sort(), policy, voiceProcessing, hapticsDuringRecording });
|
|
628
|
+
const android = (usage, contentType, f, pauseWhenDucked, mode, source) => ({ usage, contentType, focus: f, pauseWhenDucked, mode, source });
|
|
629
|
+
const noCapture = { echoCancellation: false, noiseSuppression: false, autoGainControl: false };
|
|
630
|
+
const voiceCapture = { echoCancellation: true, noiseSuppression: true, autoGainControl: true };
|
|
631
|
+
switch (claim) {
|
|
632
|
+
case "call":
|
|
633
|
+
return { claim,
|
|
634
|
+
ios: ios("playAndRecord", "voiceChat", ["allowBluetoothHFP"], "default", false),
|
|
635
|
+
android: android("voiceCommunication", "speech", "telecom", false, "inCommunication", "voiceCommunication"),
|
|
636
|
+
web: { mediaSession: false, capture: null } };
|
|
637
|
+
case "voice":
|
|
638
|
+
return { claim,
|
|
639
|
+
ios: ios("playAndRecord", "voiceChat", ["allowBluetoothHFP", "defaultToSpeaker", ...othersOption], "default", true),
|
|
640
|
+
android: android("voiceCommunication", "speech", focus("gain"), false, "inCommunication", "voiceCommunication"),
|
|
641
|
+
web: { mediaSession: false, capture: voiceCapture } };
|
|
642
|
+
case "record":
|
|
643
|
+
return { claim,
|
|
644
|
+
ios: ios("playAndRecord", unprocessed ? "measurement" : "default", ["allowBluetoothA2DP", "defaultToSpeaker", ...othersOption], "default", false),
|
|
645
|
+
android: android("media", "music", focus("gainTransient"), false, "normal", unprocessed ? "unprocessed" : "mic"),
|
|
646
|
+
web: { mediaSession: false, capture: noCapture } };
|
|
647
|
+
case "spoken": {
|
|
648
|
+
const options = others === "mix" ? ["interruptSpokenAudioAndMixWithOthers", "mixWithOthers"] : othersOption;
|
|
649
|
+
return { claim,
|
|
650
|
+
ios: ios("playback", "spokenAudio", options, others === "interrupt" ? "longFormAudio" : "default", false),
|
|
651
|
+
android: android("media", "speech", focus("gain"), true, "normal", null),
|
|
652
|
+
web: { mediaSession: true, capture: null } };
|
|
653
|
+
}
|
|
654
|
+
case "media":
|
|
655
|
+
return { claim,
|
|
656
|
+
ios: ios("playback", "default", othersOption, others === "interrupt" ? "longFormAudio" : "default", false),
|
|
657
|
+
android: android("media", "music", focus("gain"), false, "normal", null),
|
|
658
|
+
web: { mediaSession: true, capture: null } };
|
|
659
|
+
default:
|
|
660
|
+
return { claim,
|
|
661
|
+
ios: ios(others === "interrupt" ? "soloAmbient" : "ambient", "default", others === "duck" ? ["duckOthers"] : [], "default", false),
|
|
662
|
+
android: android("game", "sonification", focus("gain"), false, "normal", null),
|
|
663
|
+
web: { mediaSession: false, capture: null } };
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
// ─── claims (the bus claim contract, proposals/audio-revamp.md section 5.2.1) ─────────────────────
|
|
667
|
+
export const AUDIO_CLAIM_INTENTS = ["call", "voice", "record", "spoken", "media", "ambient", "sfx"];
|
|
668
|
+
const CLAIM_PAUSABLE = ["media", "spoken", "voice"];
|
|
669
|
+
const CLAIM_BACKGROUND_DEFAULT = ["call", "voice", "media", "spoken"];
|
|
670
|
+
export function audioClaimEmpty() { return { claims: [], held: [], generation: 0 }; }
|
|
671
|
+
/** What other apps hear while the holder's claim stands: its `others` word, or null when it named none. */
|
|
672
|
+
/** Whether the claim holding the session is a record claim that asked for unprocessed capture. */
|
|
673
|
+
export function audioClaimUnprocessed(state) {
|
|
674
|
+
const folded = AUDIO_SESSION_ORDER.find((c) => state.claims.some((k) => claimFolded(k["intent"]) === c));
|
|
675
|
+
if (folded !== "record")
|
|
676
|
+
return false;
|
|
677
|
+
return state.claims.find((k) => k["intent"] === "record")["unprocessed"] === true;
|
|
678
|
+
}
|
|
679
|
+
/** The hardware preference of the claim holding the session ({ sampleRate?, bufferDuration? }), or null when the holder
|
|
680
|
+
* named none. iOS applies it as the preferred sample rate and I/O buffer duration; Android and the web report it as unsupported. */
|
|
681
|
+
function audioClaimHardware(state) {
|
|
682
|
+
const folded = AUDIO_SESSION_ORDER.find((c) => state.claims.some((k) => claimFolded(k["intent"]) === c));
|
|
683
|
+
if (folded === undefined)
|
|
684
|
+
return null;
|
|
685
|
+
const holder = state.claims.find((k) => claimFolded(k["intent"]) === folded);
|
|
686
|
+
return holder["hardware"] ?? null;
|
|
687
|
+
}
|
|
688
|
+
/** Whether any live claim asked that haptics and system sounds keep playing while the app records. Unlike
|
|
689
|
+
* `unprocessed` it is not the holder's alone: the claimant that needs it is usually not the one recording. */
|
|
690
|
+
export function audioClaimHapticsDuringRecording(state) {
|
|
691
|
+
return state.claims.some((k) => k["hapticsDuringRecording"] === true);
|
|
692
|
+
}
|
|
693
|
+
export function audioClaimOthers(state) {
|
|
694
|
+
const folded = AUDIO_SESSION_ORDER.find((c) => state.claims.some((k) => claimFolded(k["intent"]) === c));
|
|
695
|
+
if (folded === undefined)
|
|
696
|
+
return null;
|
|
697
|
+
const holder = state.claims.find((k) => claimFolded(k["intent"]) === folded);
|
|
698
|
+
return holder["others"] ?? null;
|
|
699
|
+
}
|
|
700
|
+
function claimFolded(intent) { return intent === "sfx" ? "ambient" : intent; }
|
|
701
|
+
export function audioClaimView(state) {
|
|
702
|
+
const folded = AUDIO_SESSION_ORDER.find((c) => state.claims.some((k) => claimFolded(k["intent"]) === c));
|
|
703
|
+
const holder = folded === undefined ? null
|
|
704
|
+
: state.claims.find((k) => claimFolded(k["intent"]) === folded)["owner"];
|
|
705
|
+
return {
|
|
706
|
+
holder, intent: folded ?? "none",
|
|
707
|
+
claims: state.claims.map((k) => ({ owner: k["owner"], intent: k["intent"] })),
|
|
708
|
+
interrupted: state.held.map((h) => h["owner"]),
|
|
709
|
+
generation: state.generation,
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
/** One operation of the claim contract. Pure: the next state, what to pause and resume, and a typed refusal. */
|
|
713
|
+
export function audioClaimStep(state, op) {
|
|
714
|
+
const o = isDict(op) ? op : {};
|
|
715
|
+
const type = o["type"];
|
|
716
|
+
let claims = state.claims.map((k) => ({ ...k }));
|
|
717
|
+
let held = state.held.map((h) => ({ ...h }));
|
|
718
|
+
let changed = false;
|
|
719
|
+
let pause = [];
|
|
720
|
+
let resume = [];
|
|
721
|
+
const refuse = (error, path) => ({ state, view: audioClaimView(state), pause: [], resume: [], error, path, others: audioClaimOthers(state), unprocessed: audioClaimUnprocessed(state), hardware: audioClaimHardware(state),
|
|
722
|
+
hapticsDuringRecording: audioClaimHapticsDuringRecording(state) });
|
|
723
|
+
const mark = (cause) => {
|
|
724
|
+
const out = [];
|
|
725
|
+
for (const k of claims) {
|
|
726
|
+
const owner = k["owner"];
|
|
727
|
+
const intent = k["intent"];
|
|
728
|
+
const eligible = cause === "background" ? intent !== "call" && k["background"] === false : CLAIM_PAUSABLE.includes(intent);
|
|
729
|
+
if (eligible && !held.some((h) => h["owner"] === owner)) {
|
|
730
|
+
held.push({ owner, cause });
|
|
731
|
+
out.push(owner);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return out;
|
|
735
|
+
};
|
|
736
|
+
const lift = (cause) => {
|
|
737
|
+
const out = claims.map((k) => k["owner"]).filter((id) => held.some((h) => h["owner"] === id && h["cause"] === cause));
|
|
738
|
+
held = held.filter((h) => h["cause"] !== cause);
|
|
739
|
+
return out;
|
|
740
|
+
};
|
|
741
|
+
switch (type) {
|
|
742
|
+
case "claim": {
|
|
743
|
+
const owner = o["owner"];
|
|
744
|
+
const intent = o["intent"];
|
|
745
|
+
if (typeof owner !== "string" || owner === "")
|
|
746
|
+
return refuse("invalid_value", "owner");
|
|
747
|
+
if (typeof intent !== "string" || !AUDIO_CLAIM_INTENTS.includes(intent))
|
|
748
|
+
return refuse("invalid_value", "intent");
|
|
749
|
+
if ((intent === "voice" || intent === "record") && o["permission"] === "denied")
|
|
750
|
+
return refuse("permission_denied", null);
|
|
751
|
+
const othersWord = o["others"];
|
|
752
|
+
if (othersWord !== undefined && (typeof othersWord !== "string" || !AUDIO_OTHERS.includes(othersWord)))
|
|
753
|
+
return refuse("invalid_value", "others");
|
|
754
|
+
const raw = o["unprocessed"];
|
|
755
|
+
if (raw !== undefined && (typeof raw !== "boolean" || (raw && intent !== "record")))
|
|
756
|
+
return refuse("invalid_value", "unprocessed");
|
|
757
|
+
const hw = o["hardware"];
|
|
758
|
+
let hardware = null;
|
|
759
|
+
if (hw !== undefined) {
|
|
760
|
+
const positive = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
761
|
+
const count = (v) => typeof v === "number" && Number.isInteger(v) && v > 0;
|
|
762
|
+
if (!isDict(hw) || Object.keys(hw).length === 0 || Object.keys(hw).some((k) => !AUDIO_HARDWARE_KEYS.includes(k))
|
|
763
|
+
|| ("sampleRate" in hw && !positive(hw["sampleRate"])) || ("bufferDuration" in hw && !positive(hw["bufferDuration"]))
|
|
764
|
+
|| ("inputChannels" in hw && !count(hw["inputChannels"])) || ("outputChannels" in hw && !count(hw["outputChannels"])))
|
|
765
|
+
return refuse("invalid_value", "hardware");
|
|
766
|
+
hardware = Object.fromEntries(AUDIO_HARDWARE_KEYS.filter((k) => k in hw).map((k) => [k, hw[k]]));
|
|
767
|
+
}
|
|
768
|
+
const haptics = o["hapticsDuringRecording"];
|
|
769
|
+
if (haptics !== undefined && typeof haptics !== "boolean")
|
|
770
|
+
return refuse("invalid_value", "hapticsDuringRecording");
|
|
771
|
+
const background = typeof o["background"] === "boolean" ? o["background"] : CLAIM_BACKGROUND_DEFAULT.includes(intent);
|
|
772
|
+
const entry = othersWord === undefined ? { owner, intent, background } : { owner, intent, background, others: othersWord };
|
|
773
|
+
if (raw === true)
|
|
774
|
+
entry["unprocessed"] = true;
|
|
775
|
+
if (hardware !== null)
|
|
776
|
+
entry["hardware"] = hardware;
|
|
777
|
+
if (haptics === true)
|
|
778
|
+
entry["hapticsDuringRecording"] = true;
|
|
779
|
+
const at = claims.findIndex((k) => k["owner"] === owner);
|
|
780
|
+
if (at < 0) {
|
|
781
|
+
claims.push(entry);
|
|
782
|
+
changed = true;
|
|
783
|
+
}
|
|
784
|
+
else if (claims[at]["intent"] !== intent || claims[at]["background"] !== background || claims[at]["others"] !== entry["others"] || claims[at]["unprocessed"] !== entry["unprocessed"]
|
|
785
|
+
|| JSON.stringify(claims[at]["hardware"] ?? null) !== JSON.stringify(entry["hardware"] ?? null)
|
|
786
|
+
|| claims[at]["hapticsDuringRecording"] !== entry["hapticsDuringRecording"]) {
|
|
787
|
+
claims[at] = entry;
|
|
788
|
+
if (!CLAIM_PAUSABLE.includes(intent))
|
|
789
|
+
held = held.filter((h) => h["owner"] !== owner);
|
|
790
|
+
changed = true;
|
|
791
|
+
}
|
|
792
|
+
break;
|
|
793
|
+
}
|
|
794
|
+
case "release": {
|
|
795
|
+
const owner = o["owner"];
|
|
796
|
+
if (typeof owner !== "string" || owner === "")
|
|
797
|
+
return refuse("invalid_value", "owner");
|
|
798
|
+
if (claims.some((k) => k["owner"] === owner)) {
|
|
799
|
+
claims = claims.filter((k) => k["owner"] !== owner);
|
|
800
|
+
held = held.filter((h) => h["owner"] !== owner);
|
|
801
|
+
changed = true;
|
|
802
|
+
}
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
805
|
+
case "began":
|
|
806
|
+
pause = mark("session");
|
|
807
|
+
changed = pause.length > 0;
|
|
808
|
+
break;
|
|
809
|
+
case "background":
|
|
810
|
+
pause = mark("background");
|
|
811
|
+
changed = pause.length > 0;
|
|
812
|
+
break;
|
|
813
|
+
case "ended":
|
|
814
|
+
resume = lift("session");
|
|
815
|
+
changed = resume.length > 0;
|
|
816
|
+
if (o["shouldResume"] !== true)
|
|
817
|
+
resume = [];
|
|
818
|
+
break;
|
|
819
|
+
case "foreground":
|
|
820
|
+
resume = lift("background");
|
|
821
|
+
changed = resume.length > 0;
|
|
822
|
+
break;
|
|
823
|
+
default: return refuse("invalid_value", "type");
|
|
824
|
+
}
|
|
825
|
+
// A call taking the session pauses the app's media, spoken and voice claimants (rule 4: the call's OS
|
|
826
|
+
// configuration is the claimant's, the app's own sound yields); the last call going resumes only those.
|
|
827
|
+
if (type === "claim" || type === "release") {
|
|
828
|
+
const hadCall = state.claims.some((k) => k["intent"] === "call");
|
|
829
|
+
const hasCall = claims.some((k) => k["intent"] === "call");
|
|
830
|
+
if (!hadCall && hasCall)
|
|
831
|
+
pause = mark("call");
|
|
832
|
+
if (hadCall && !hasCall)
|
|
833
|
+
resume = lift("call");
|
|
834
|
+
}
|
|
835
|
+
const next = { claims, held, generation: state.generation + (changed ? 1 : 0) };
|
|
836
|
+
return { state: next, view: audioClaimView(next), pause, resume, error: null, path: null, others: audioClaimOthers(next), unprocessed: audioClaimUnprocessed(next), hardware: audioClaimHardware(next),
|
|
837
|
+
hapticsDuringRecording: audioClaimHapticsDuringRecording(next) };
|
|
838
|
+
}
|
|
839
|
+
// ─── interruptions ─────────────────────────────────────────────────────────────────────────────
|
|
840
|
+
const SOUNDING = ["playing", "buffering", "loading"];
|
|
841
|
+
/** One event applied to every player; a cause resumes only what that cause paused. */
|
|
842
|
+
export function audioInterrupt(players, event) {
|
|
843
|
+
const e = isDict(event) ? event : {};
|
|
844
|
+
const type = e["type"];
|
|
845
|
+
return players.map((p) => {
|
|
846
|
+
const q = { ...p };
|
|
847
|
+
const sounding = SOUNDING.includes(q["status"]);
|
|
848
|
+
const intent = q["intent"];
|
|
849
|
+
switch (type) {
|
|
850
|
+
case "began":
|
|
851
|
+
if (sounding) {
|
|
852
|
+
q["status"] = "interrupted";
|
|
853
|
+
q["interrupted"] = "session";
|
|
854
|
+
q["ducked"] = false;
|
|
855
|
+
}
|
|
856
|
+
break;
|
|
857
|
+
case "ended":
|
|
858
|
+
if (q["interrupted"] === "session") {
|
|
859
|
+
q["status"] = e["shouldResume"] === true ? "playing" : "paused";
|
|
860
|
+
q["interrupted"] = null;
|
|
861
|
+
}
|
|
862
|
+
break;
|
|
863
|
+
case "focusDuck":
|
|
864
|
+
if (sounding) {
|
|
865
|
+
if (intent === "spoken") {
|
|
866
|
+
q["status"] = "interrupted";
|
|
867
|
+
q["interrupted"] = "focus";
|
|
868
|
+
}
|
|
869
|
+
else
|
|
870
|
+
q["ducked"] = true;
|
|
871
|
+
}
|
|
872
|
+
break;
|
|
873
|
+
case "focusGain":
|
|
874
|
+
q["ducked"] = false;
|
|
875
|
+
if (q["interrupted"] === "focus") {
|
|
876
|
+
q["status"] = "playing";
|
|
877
|
+
q["interrupted"] = null;
|
|
878
|
+
}
|
|
879
|
+
break;
|
|
880
|
+
case "routeLost":
|
|
881
|
+
if (sounding && (intent === "media" || intent === "spoken"))
|
|
882
|
+
q["status"] = "paused";
|
|
883
|
+
break;
|
|
884
|
+
case "background":
|
|
885
|
+
if (sounding && q["background"] === false) {
|
|
886
|
+
q["status"] = "interrupted";
|
|
887
|
+
q["interrupted"] = "background";
|
|
888
|
+
}
|
|
889
|
+
break;
|
|
890
|
+
case "foreground":
|
|
891
|
+
if (q["interrupted"] === "background") {
|
|
892
|
+
q["status"] = "playing";
|
|
893
|
+
q["interrupted"] = null;
|
|
894
|
+
}
|
|
895
|
+
break;
|
|
896
|
+
}
|
|
897
|
+
return q;
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
/** Each gain-bearing node's duck factor, its ramp and its effective gain for what is sounding. */
|
|
901
|
+
/** `claims` is the folded intent list of the live bus claims (claims.json): a claim ducks a rule that names
|
|
902
|
+
* its intent exactly as a sounding node of that intent would (Record's `record`, SpeechSynthesis's `spoken`). */
|
|
903
|
+
export function audioDuck(graph, sounding, claims = []) {
|
|
904
|
+
const g = audioNormalizeGraph(graph);
|
|
905
|
+
const live = new Set(sounding);
|
|
906
|
+
// A bus sounds when anything feeding it sounds.
|
|
907
|
+
let grew = true;
|
|
908
|
+
while (grew) {
|
|
909
|
+
grew = false;
|
|
910
|
+
for (const n of g.nodes) {
|
|
911
|
+
const to = n["to"];
|
|
912
|
+
if (typeof to === "string" && live.has(n["id"]) && !live.has(to)) {
|
|
913
|
+
live.add(to);
|
|
914
|
+
grew = true;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
const out = {};
|
|
919
|
+
for (const n of g.nodes) {
|
|
920
|
+
if (n["kind"] !== "player" && n["kind"] !== "bus" && n["kind"] !== "input")
|
|
921
|
+
continue;
|
|
922
|
+
const gain = n["gain"];
|
|
923
|
+
const rule = n["duck"];
|
|
924
|
+
if (!isDict(rule)) {
|
|
925
|
+
out[n["id"]] = { factor: 1, ramp: 0, effective: round4(gain) };
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
const when = rule["when"];
|
|
929
|
+
const ducked = claims.some((intent) => when.includes(intent)) ||
|
|
930
|
+
g.nodes.some((m) => m["id"] !== n["id"] && live.has(m["id"]) && (when.includes(m["id"]) ||
|
|
931
|
+
(m["kind"] === "player" && when.includes(m["intent"])) ||
|
|
932
|
+
(m["kind"] === "input" && when.includes("record"))));
|
|
933
|
+
const factor = ducked ? rule["to"] : 1;
|
|
934
|
+
const ramp = rule["ramp"] ?? AUDIO_LIMITS.duckRamp;
|
|
935
|
+
out[n["id"]] = { factor, ramp, effective: round4(gain * factor) };
|
|
936
|
+
}
|
|
937
|
+
return out;
|
|
938
|
+
}
|
|
939
|
+
/** A linear amplitude ramp from `from` at `start` to `to` over `ramp` seconds, held after. */
|
|
940
|
+
export function audioRamp(from, to, start, ramp, t) {
|
|
941
|
+
if (ramp <= 0)
|
|
942
|
+
return t >= start ? to : from;
|
|
943
|
+
if (t <= start)
|
|
944
|
+
return from;
|
|
945
|
+
if (t >= start + ramp)
|
|
946
|
+
return to;
|
|
947
|
+
return from + (to - from) * (t - start) / ramp;
|
|
948
|
+
}
|
|
949
|
+
/** The queue's next index on `next`, `prev` (with the position into the item) or a natural `ended`. */
|
|
950
|
+
export function audioQueueAdvance(queue, event, position) {
|
|
951
|
+
const q = isDict(queue) ? queue : {};
|
|
952
|
+
const count = q["count"] ?? 0;
|
|
953
|
+
const index = q["index"] ?? 0;
|
|
954
|
+
const loop = q["loop"] ?? "off";
|
|
955
|
+
if (count <= 0)
|
|
956
|
+
return { index: 0, restart: false, ended: true };
|
|
957
|
+
const order = Array.isArray(q["order"]) ? q["order"] : Array.from({ length: count }, (_, i) => i);
|
|
958
|
+
const pos = order.indexOf(index);
|
|
959
|
+
const done = (i) => ({ index: i, restart: i === index, ended: false });
|
|
960
|
+
if (event === "ended" && loop === "one")
|
|
961
|
+
return done(index);
|
|
962
|
+
if (event === "next" || event === "ended") {
|
|
963
|
+
if (pos + 1 < order.length)
|
|
964
|
+
return done(order[pos + 1]);
|
|
965
|
+
if (loop === "all")
|
|
966
|
+
return done(order[0]);
|
|
967
|
+
return { index, restart: false, ended: true };
|
|
968
|
+
}
|
|
969
|
+
if (event === "prev") {
|
|
970
|
+
if (position > AUDIO_PREV_RESTART)
|
|
971
|
+
return done(index);
|
|
972
|
+
if (pos - 1 >= 0)
|
|
973
|
+
return done(order[pos - 1]);
|
|
974
|
+
if (loop === "all")
|
|
975
|
+
return done(order[order.length - 1]);
|
|
976
|
+
return done(index);
|
|
977
|
+
}
|
|
978
|
+
return { index, restart: false, ended: false };
|
|
979
|
+
}
|
|
980
|
+
function chapterSpans(item) {
|
|
981
|
+
const it = isDict(item) ? item : {};
|
|
982
|
+
const duration = it["duration"];
|
|
983
|
+
const list = Array.isArray(it["chapters"]) ? it["chapters"] : [];
|
|
984
|
+
return list.map((c, i) => ({
|
|
985
|
+
start: c["start"],
|
|
986
|
+
end: c["end"] ?? list[i + 1]?.["start"] ?? duration,
|
|
987
|
+
}));
|
|
988
|
+
}
|
|
989
|
+
/** The chapter index a position is in, or -1 in a gap or past the end. */
|
|
990
|
+
export function audioChapterAt(item, position) {
|
|
991
|
+
return chapterSpans(item).findIndex((c) => position >= c.start && position < c.end);
|
|
992
|
+
}
|
|
993
|
+
/** The position seek({ chapter }) goes to, or null when there is no such chapter. */
|
|
994
|
+
export function audioSeekChapter(item, position, target) {
|
|
995
|
+
const spans = chapterSpans(item);
|
|
996
|
+
if (typeof target === "number")
|
|
997
|
+
return spans[target]?.start ?? null;
|
|
998
|
+
const cur = audioChapterAt(item, position);
|
|
999
|
+
if (target === "next")
|
|
1000
|
+
return spans.find((c) => c.start > position)?.start ?? null;
|
|
1001
|
+
if (cur >= 0) {
|
|
1002
|
+
if (position - spans[cur].start > AUDIO_PREV_RESTART)
|
|
1003
|
+
return spans[cur].start;
|
|
1004
|
+
return spans[cur > 0 ? cur - 1 : cur].start;
|
|
1005
|
+
}
|
|
1006
|
+
const before = spans.filter((c) => c.start <= position);
|
|
1007
|
+
return before.length > 0 ? before[before.length - 1].start : null;
|
|
1008
|
+
}
|
|
1009
|
+
/** A sleep rule as a deadline: wall-clock seconds from when it was set, or a media position. */
|
|
1010
|
+
export function audioSleepDeadline(sleep, state) {
|
|
1011
|
+
const s = isDict(sleep) ? sleep : {};
|
|
1012
|
+
const fade = s["fade"] ?? 0;
|
|
1013
|
+
const at = s["at"];
|
|
1014
|
+
if (typeof at === "number")
|
|
1015
|
+
return { clock: "wall", at, fadeFrom: Math.max(0, at - fade) };
|
|
1016
|
+
let end = state.duration;
|
|
1017
|
+
if (at === "chapterEnd" && state.chapters.length > 0) {
|
|
1018
|
+
const item = { duration: state.duration, chapters: state.chapters };
|
|
1019
|
+
const spans = chapterSpans(item);
|
|
1020
|
+
const cur = audioChapterAt(item, state.position);
|
|
1021
|
+
end = cur >= 0 ? spans[cur].end : (spans.find((c) => c.start > state.position)?.start ?? state.duration);
|
|
1022
|
+
}
|
|
1023
|
+
return { clock: "media", at: end, fadeFrom: Math.max(state.position, end - fade * state.rate) };
|
|
1024
|
+
}
|
|
1025
|
+
/** When the next item starts sounding; a crossfade longer than half the item is clamped to half. */
|
|
1026
|
+
export function audioCrossfadeStart(duration, crossfade) {
|
|
1027
|
+
return duration - Math.min(Math.max(crossfade, 0), duration / 2);
|
|
1028
|
+
}
|
|
1029
|
+
/** The start position from a checkpoint; near or past the end starts over. */
|
|
1030
|
+
export function audioResumePosition(saved, duration) {
|
|
1031
|
+
if (!isNum(saved) || saved < 0)
|
|
1032
|
+
return 0;
|
|
1033
|
+
if (duration === null || duration === undefined)
|
|
1034
|
+
return saved;
|
|
1035
|
+
return saved >= duration - AUDIO_RESUME_END_TOLERANCE ? 0 : saved;
|
|
1036
|
+
}
|
|
1037
|
+
const ID3_FRAMES = {
|
|
1038
|
+
TIT2: "title", TT2: "title", TPE1: "artist", TP1: "artist", TALB: "album", TAL: "album",
|
|
1039
|
+
};
|
|
1040
|
+
function metaText(v) {
|
|
1041
|
+
if (typeof v !== "string")
|
|
1042
|
+
return null;
|
|
1043
|
+
const t = v.replace(/\u0000/g, "").trim();
|
|
1044
|
+
return t === "" ? null : t;
|
|
1045
|
+
}
|
|
1046
|
+
/** The text of an ICY `StreamTitle='...';` field, or null. The value runs to the last `';` (titles hold apostrophes). */
|
|
1047
|
+
function icyStreamTitle(text) {
|
|
1048
|
+
const marker = "StreamTitle='";
|
|
1049
|
+
const at = text.indexOf(marker);
|
|
1050
|
+
if (at < 0)
|
|
1051
|
+
return null;
|
|
1052
|
+
let rest = text.slice(at + marker.length);
|
|
1053
|
+
const url = rest.indexOf("';StreamUrl=");
|
|
1054
|
+
if (url >= 0)
|
|
1055
|
+
rest = rest.slice(0, url);
|
|
1056
|
+
else {
|
|
1057
|
+
const end = rest.lastIndexOf("';");
|
|
1058
|
+
if (end >= 0)
|
|
1059
|
+
rest = rest.slice(0, end);
|
|
1060
|
+
else if (trimTrailing(rest, "\u0000").endsWith("'"))
|
|
1061
|
+
rest = trimTrailing(rest, "\u0000").slice(0, -1);
|
|
1062
|
+
}
|
|
1063
|
+
return rest;
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Normalizes one stream metadata update (ICY text, ID3 frames or common fields) into title, artist and album, or null when it
|
|
1067
|
+
* carries none (a clear). ICY splits `Artist - Title` at the first ` - ` when both sides are non-empty.
|
|
1068
|
+
*/
|
|
1069
|
+
export function audioStreamMetadata(input) {
|
|
1070
|
+
const d = (input ?? {});
|
|
1071
|
+
let out = { title: null, artist: null, album: null };
|
|
1072
|
+
if (d["kind"] === "icy") {
|
|
1073
|
+
const raw = typeof d["text"] === "string" ? icyStreamTitle(d["text"]) : null;
|
|
1074
|
+
const t = metaText(raw);
|
|
1075
|
+
if (t !== null) {
|
|
1076
|
+
const cut = t.indexOf(" - ");
|
|
1077
|
+
if (cut > 0 && t.slice(cut + 3).trim() !== "")
|
|
1078
|
+
out = { title: t.slice(cut + 3).trim(), artist: t.slice(0, cut).trim(), album: null };
|
|
1079
|
+
else
|
|
1080
|
+
out.title = t;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
else if (d["kind"] === "id3") {
|
|
1084
|
+
const frames = (d["frames"] ?? {});
|
|
1085
|
+
for (const key of Object.keys(ID3_FRAMES)) {
|
|
1086
|
+
const t = metaText(frames[key]);
|
|
1087
|
+
if (t !== null)
|
|
1088
|
+
out[ID3_FRAMES[key]] = t;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
else if (d["kind"] === "fields") {
|
|
1092
|
+
out = { title: metaText(d["title"]), artist: metaText(d["artist"]), album: metaText(d["album"]) };
|
|
1093
|
+
}
|
|
1094
|
+
return out.title === null && out.artist === null && out.album === null ? null : out;
|
|
1095
|
+
}
|
|
1096
|
+
/** What the now-playing surface shows: each field is the stream metadata's when it has one, else the item's. */
|
|
1097
|
+
export function audioNowPlayingDisplay(item, metadata) {
|
|
1098
|
+
const i = (item ?? {});
|
|
1099
|
+
const m = (metadata ?? {});
|
|
1100
|
+
return { title: metaText(m["title"]) ?? metaText(i["title"]), artist: metaText(m["artist"]) ?? metaText(i["artist"]) };
|
|
1101
|
+
}
|
|
1102
|
+
// ─── routes ────────────────────────────────────────────────────────────────────────────────────
|
|
1103
|
+
const IOS_PORTS = {
|
|
1104
|
+
builtInSpeaker: "speaker", builtInReceiver: "receiver", headphones: "wired", headsetMic: "wired", lineOut: "wired",
|
|
1105
|
+
bluetoothA2DP: "bluetooth", bluetoothHFP: "bluetooth", bluetoothLE: "bluetooth", airPlay: "airplay",
|
|
1106
|
+
carAudio: "car", usbAudio: "usb", HDMI: "hdmi",
|
|
1107
|
+
};
|
|
1108
|
+
const ANDROID_PORTS = {
|
|
1109
|
+
TYPE_BUILTIN_SPEAKER: "speaker", TYPE_BUILTIN_EARPIECE: "receiver", TYPE_WIRED_HEADSET: "wired",
|
|
1110
|
+
TYPE_WIRED_HEADPHONES: "wired", TYPE_LINE_ANALOG: "wired", TYPE_LINE_DIGITAL: "wired",
|
|
1111
|
+
TYPE_BLUETOOTH_A2DP: "bluetooth", TYPE_BLUETOOTH_SCO: "bluetooth", TYPE_BLE_HEADSET: "bluetooth",
|
|
1112
|
+
TYPE_BLE_SPEAKER: "bluetooth", TYPE_HEARING_AID: "bluetooth", TYPE_USB_HEADSET: "usb", TYPE_USB_DEVICE: "usb",
|
|
1113
|
+
TYPE_HDMI: "hdmi", TYPE_REMOTE_SUBMIX: "cast", TYPE_BUS: "car",
|
|
1114
|
+
};
|
|
1115
|
+
/** A platform's own output port word folded into the published `route.output.kind`. */
|
|
1116
|
+
export function audioRouteKind(platform, port) {
|
|
1117
|
+
if (platform === "ios")
|
|
1118
|
+
return IOS_PORTS[port] ?? "other";
|
|
1119
|
+
if (platform === "android")
|
|
1120
|
+
return ANDROID_PORTS[port] ?? "other";
|
|
1121
|
+
return port === "default" ? "speaker" : "other";
|
|
1122
|
+
}
|
|
1123
|
+
/** What route.set({ output }) does for the live session claim: the native call, or a typed refusal. */
|
|
1124
|
+
export function audioRouteSet(platform, claim, output) {
|
|
1125
|
+
if (platform === "ios") {
|
|
1126
|
+
if (claim === "call")
|
|
1127
|
+
return { method: "call" };
|
|
1128
|
+
if (claim === "voice" || claim === "record") {
|
|
1129
|
+
return { method: output === "speaker" || output === "receiver" ? "overrideOutputAudioPort" : "setPreferredInput" };
|
|
1130
|
+
}
|
|
1131
|
+
return { error: "picker_only" };
|
|
1132
|
+
}
|
|
1133
|
+
if (platform === "android") {
|
|
1134
|
+
if (claim === "call")
|
|
1135
|
+
return { method: "call" };
|
|
1136
|
+
return { method: claim === "voice" ? "setCommunicationDevice" : "setPreferredDevice" };
|
|
1137
|
+
}
|
|
1138
|
+
if (platform === "web") {
|
|
1139
|
+
if (output === "receiver")
|
|
1140
|
+
return { error: "unsupported_platform" };
|
|
1141
|
+
if (output === "bluetooth" || output === "wired")
|
|
1142
|
+
return { error: "picker_only" };
|
|
1143
|
+
return { method: "setSinkId" };
|
|
1144
|
+
}
|
|
1145
|
+
return { error: "unsupported_platform" };
|
|
1146
|
+
}
|
|
1147
|
+
// ─── project ───────────────────────────────────────────────────────────────────────────────────
|
|
1148
|
+
/** A clip's timeline span [start, end), or the first problem with it. */
|
|
1149
|
+
export function audioClipSpan(clip, sourceDuration) {
|
|
1150
|
+
const c = isDict(clip) ? clip : {};
|
|
1151
|
+
if (c["src"] !== undefined && !audioIsSource(c["src"]))
|
|
1152
|
+
return { error: "invalid_source@src" };
|
|
1153
|
+
const at = c["at"] ?? 0;
|
|
1154
|
+
if (!inRange(at, 0, Infinity))
|
|
1155
|
+
return { error: "out_of_range@at" };
|
|
1156
|
+
const from = c["from"] ?? 0;
|
|
1157
|
+
if (!inRange(from, 0, Infinity))
|
|
1158
|
+
return { error: "out_of_range@from" };
|
|
1159
|
+
const to = c["to"] ?? sourceDuration;
|
|
1160
|
+
if (!isNum(to) || to <= from)
|
|
1161
|
+
return { error: "out_of_range@to" };
|
|
1162
|
+
if (c["loop"] !== true && to > sourceDuration)
|
|
1163
|
+
return { error: "out_of_range@to" };
|
|
1164
|
+
return { start: at, end: at + (to - from) };
|
|
1165
|
+
}
|
|
1166
|
+
/** The source position a clip reads at timeline time t, or null outside the clip; loops wrap to `from`. */
|
|
1167
|
+
export function audioClipSourceTime(clip, sourceDuration, t) {
|
|
1168
|
+
const span = audioClipSpan(clip, sourceDuration);
|
|
1169
|
+
if ("error" in span || t < span.start || t >= span.end)
|
|
1170
|
+
return null;
|
|
1171
|
+
const c = clip;
|
|
1172
|
+
const from = c["from"] ?? 0;
|
|
1173
|
+
const offset = t - span.start;
|
|
1174
|
+
if (c["loop"] === true)
|
|
1175
|
+
return from + offset % (sourceDuration - from);
|
|
1176
|
+
return from + offset;
|
|
1177
|
+
}
|
|
1178
|
+
/** The clip's fade envelope at timeline time t: linear fades, the lower one where they overlap. */
|
|
1179
|
+
export function audioClipGain(clip, t) {
|
|
1180
|
+
const c = isDict(clip) ? clip : {};
|
|
1181
|
+
const at = c["at"] ?? 0;
|
|
1182
|
+
const end = at + (c["to"] - (c["from"] ?? 0));
|
|
1183
|
+
if (t < at || t >= end)
|
|
1184
|
+
return 0;
|
|
1185
|
+
let g = 1;
|
|
1186
|
+
const fadeIn = c["fadeIn"] ?? 0;
|
|
1187
|
+
const fadeOut = c["fadeOut"] ?? 0;
|
|
1188
|
+
if (fadeIn > 0)
|
|
1189
|
+
g = Math.min(g, (t - at) / fadeIn);
|
|
1190
|
+
if (fadeOut > 0)
|
|
1191
|
+
g = Math.min(g, (end - t) / fadeOut);
|
|
1192
|
+
return g;
|
|
1193
|
+
}
|
|
1194
|
+
/** The render length: the end of the latest clip, in seconds and in frames. */
|
|
1195
|
+
export function audioProjectLength(project, durations) {
|
|
1196
|
+
const p = isDict(project) ? project : {};
|
|
1197
|
+
const rate = p["sampleRate"] ?? 48000;
|
|
1198
|
+
let seconds = 0;
|
|
1199
|
+
for (const track of Array.isArray(p["tracks"]) ? p["tracks"] : []) {
|
|
1200
|
+
for (const clip of Array.isArray(track["clips"]) ? track["clips"] : []) {
|
|
1201
|
+
const span = audioClipSpan(clip, durations[clip["src"]] ?? 0);
|
|
1202
|
+
if (!("error" in span))
|
|
1203
|
+
seconds = Math.max(seconds, span.end);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
return { seconds, frames: roundHalfAway(seconds * rate) };
|
|
1207
|
+
}
|
|
1208
|
+
/** Every problem in a project document as `code@path`. */
|
|
1209
|
+
export function audioValidateProject(project) {
|
|
1210
|
+
if (!isDict(project))
|
|
1211
|
+
return ["invalid_value@project"];
|
|
1212
|
+
const errors = [];
|
|
1213
|
+
if (project["sampleRate"] !== undefined && !AUDIO_SAMPLE_RATES.includes(project["sampleRate"]))
|
|
1214
|
+
errors.push("unknown_value@sampleRate");
|
|
1215
|
+
const tracks = project["tracks"];
|
|
1216
|
+
if (!Array.isArray(tracks))
|
|
1217
|
+
return [...errors, "invalid_value@tracks"];
|
|
1218
|
+
const ids = new Set();
|
|
1219
|
+
tracks.forEach((track, i) => {
|
|
1220
|
+
const p = `tracks[${i}]`;
|
|
1221
|
+
if (!isDict(track)) {
|
|
1222
|
+
errors.push(`invalid_value@${p}`);
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
const id = track["id"];
|
|
1226
|
+
if (typeof id !== "string" || id === "" || ids.has(id))
|
|
1227
|
+
errors.push(`invalid_id@${p}.id`);
|
|
1228
|
+
if (typeof id === "string")
|
|
1229
|
+
ids.add(id);
|
|
1230
|
+
checkRange(track, "gain", AUDIO_LIMITS.gainMin, AUDIO_LIMITS.gainMax, p, errors);
|
|
1231
|
+
checkRange(track, "pan", AUDIO_LIMITS.panMin, AUDIO_LIMITS.panMax, p, errors);
|
|
1232
|
+
checkEffects(track["effects"], `${p}.effects`, false, errors);
|
|
1233
|
+
const clips = Array.isArray(track["clips"]) ? track["clips"] : [];
|
|
1234
|
+
clips.forEach((clip, j) => {
|
|
1235
|
+
if (!isDict(clip) || !audioIsSource(clip["src"]))
|
|
1236
|
+
errors.push(`invalid_source@${p}.clips[${j}].src`);
|
|
1237
|
+
});
|
|
1238
|
+
});
|
|
1239
|
+
const master = project["master"];
|
|
1240
|
+
if (isDict(master))
|
|
1241
|
+
checkEffects(master["effects"], "master.effects", false, errors);
|
|
1242
|
+
return errors;
|
|
1243
|
+
}
|
|
1244
|
+
/** The two K-weighting stages derived for the sample rate from the analog prototype. */
|
|
1245
|
+
export function audioKWeighting(rate) {
|
|
1246
|
+
let f0 = 1681.974450955533;
|
|
1247
|
+
const gainDb = 3.999843853973347;
|
|
1248
|
+
let q = 0.7071752369554196;
|
|
1249
|
+
let k = Math.tan(Math.PI * f0 / rate);
|
|
1250
|
+
const vh = Math.pow(10, gainDb / 20);
|
|
1251
|
+
const vb = Math.pow(vh, 0.4996667741545416);
|
|
1252
|
+
let a0 = 1 + k / q + k * k;
|
|
1253
|
+
const shelf = {
|
|
1254
|
+
b: [(vh + vb * k / q + k * k) / a0, 2 * (k * k - vh) / a0, (vh - vb * k / q + k * k) / a0],
|
|
1255
|
+
a: [1, 2 * (k * k - 1) / a0, (1 - k / q + k * k) / a0],
|
|
1256
|
+
};
|
|
1257
|
+
f0 = 38.13547087602444;
|
|
1258
|
+
q = 0.5003270373238773;
|
|
1259
|
+
k = Math.tan(Math.PI * f0 / rate);
|
|
1260
|
+
a0 = 1 + k / q + k * k;
|
|
1261
|
+
const highPass = { b: [1, -2, 1], a: [1, 2 * (k * k - 1) / a0, (1 - k / q + k * k) / a0] };
|
|
1262
|
+
return { shelf, highPass };
|
|
1263
|
+
}
|
|
1264
|
+
function biquad(x, f) {
|
|
1265
|
+
const y = new Float64Array(x.length);
|
|
1266
|
+
let x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
|
1267
|
+
for (let n = 0; n < x.length; n++) {
|
|
1268
|
+
const v = f.b[0] * x[n] + f.b[1] * x1 + f.b[2] * x2 - f.a[1] * y1 - f.a[2] * y2;
|
|
1269
|
+
x2 = x1;
|
|
1270
|
+
x1 = x[n];
|
|
1271
|
+
y2 = y1;
|
|
1272
|
+
y1 = v;
|
|
1273
|
+
y[n] = v;
|
|
1274
|
+
}
|
|
1275
|
+
return y;
|
|
1276
|
+
}
|
|
1277
|
+
/** Gated integrated loudness in LUFS (channel weight 1: mono, left, right), or null when no block survives. */
|
|
1278
|
+
export function audioIntegratedLoudness(channels, rate) {
|
|
1279
|
+
const block = Math.round(0.4 * rate);
|
|
1280
|
+
const hop = Math.round(0.1 * rate);
|
|
1281
|
+
const length = channels.length > 0 ? channels[0].length : 0;
|
|
1282
|
+
if (length < block)
|
|
1283
|
+
return null;
|
|
1284
|
+
const k = audioKWeighting(rate);
|
|
1285
|
+
const sums = channels.map((ch) => {
|
|
1286
|
+
const y = biquad(biquad(ch, k.shelf), k.highPass);
|
|
1287
|
+
const prefix = new Float64Array(y.length + 1);
|
|
1288
|
+
for (let n = 0; n < y.length; n++)
|
|
1289
|
+
prefix[n + 1] = prefix[n] + y[n] * y[n];
|
|
1290
|
+
return prefix;
|
|
1291
|
+
});
|
|
1292
|
+
const energies = [];
|
|
1293
|
+
for (let start = 0; start + block <= length; start += hop) {
|
|
1294
|
+
let z = 0;
|
|
1295
|
+
for (const prefix of sums)
|
|
1296
|
+
z += (prefix[start + block] - prefix[start]) / block;
|
|
1297
|
+
energies.push(z);
|
|
1298
|
+
}
|
|
1299
|
+
const loudness = (z) => -0.691 + 10 * Math.log10(z);
|
|
1300
|
+
const absolute = energies.filter((z) => z > 0 && loudness(z) > -70);
|
|
1301
|
+
if (absolute.length === 0)
|
|
1302
|
+
return null;
|
|
1303
|
+
const relative = loudness(absolute.reduce((s, z) => s + z, 0) / absolute.length) - 10;
|
|
1304
|
+
const gated = absolute.filter((z) => loudness(z) > relative);
|
|
1305
|
+
if (gated.length === 0)
|
|
1306
|
+
return null;
|
|
1307
|
+
return loudness(gated.reduce((s, z) => s + z, 0) / gated.length);
|
|
1308
|
+
}
|
|
1309
|
+
/** The `loudness` effect's gain in dB: target minus measured, never past the true-peak ceiling. */
|
|
1310
|
+
export function audioLoudnessGain(measured, target, truePeak, ceiling) {
|
|
1311
|
+
if (measured === null || !isNum(measured))
|
|
1312
|
+
return 0;
|
|
1313
|
+
const toTarget = target - measured;
|
|
1314
|
+
return truePeak === null || !isNum(truePeak) ? toTarget : Math.min(toTarget, ceiling - truePeak);
|
|
1315
|
+
}
|
|
1316
|
+
// ── the socket endpoint (Conformance/audio/socket.json, proposal section 5.7) ─────────────────
|
|
1317
|
+
/** A socket object's normalized form: format pcm16, rate 24000, the 20 ms chunk, frame/unframe only when written. */
|
|
1318
|
+
export function audioSocketDefaults(s) {
|
|
1319
|
+
const rate = typeof s["rate"] === "number" ? s["rate"] : AUDIO_SOCKET.rate;
|
|
1320
|
+
const out = { as: s["as"], format: AUDIO_SOCKET.format, rate, chunk: Math.round(rate * AUDIO_SOCKET.chunkMs / 1000) };
|
|
1321
|
+
if (typeof s["frame"] === "string")
|
|
1322
|
+
out["frame"] = s["frame"];
|
|
1323
|
+
if (typeof s["unframe"] === "string")
|
|
1324
|
+
out["unframe"] = s["unframe"];
|
|
1325
|
+
return out;
|
|
1326
|
+
}
|
|
1327
|
+
const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
1328
|
+
function base64(bytes) {
|
|
1329
|
+
let out = "";
|
|
1330
|
+
for (let i = 0; i < bytes.length; i += 3) {
|
|
1331
|
+
const a = bytes[i], b = bytes[i + 1], c = bytes[i + 2];
|
|
1332
|
+
out += B64[a >> 2] + B64[((a & 3) << 4) | ((b ?? 0) >> 4)]
|
|
1333
|
+
+ (b === undefined ? "=" : B64[((b & 15) << 2) | ((c ?? 0) >> 6)])
|
|
1334
|
+
+ (c === undefined ? "=" : B64[c & 63]);
|
|
1335
|
+
}
|
|
1336
|
+
return out;
|
|
1337
|
+
}
|
|
1338
|
+
function unbase64(text) {
|
|
1339
|
+
if (text.length % 4 !== 0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(text))
|
|
1340
|
+
return null;
|
|
1341
|
+
const pad = text.endsWith("==") ? 2 : text.endsWith("=") ? 1 : 0;
|
|
1342
|
+
const out = new Uint8Array((text.length / 4) * 3 - pad);
|
|
1343
|
+
let o = 0;
|
|
1344
|
+
for (let i = 0; i < text.length; i += 4) {
|
|
1345
|
+
const n = (B64.indexOf(text[i]) << 18) | (B64.indexOf(text[i + 1]) << 12)
|
|
1346
|
+
| (Math.max(0, B64.indexOf(text[i + 2])) << 6) | Math.max(0, B64.indexOf(text[i + 3]));
|
|
1347
|
+
for (const shift of [16, 8, 0])
|
|
1348
|
+
if (o < out.length)
|
|
1349
|
+
out[o++] = (n >> shift) & 255;
|
|
1350
|
+
}
|
|
1351
|
+
return out;
|
|
1352
|
+
}
|
|
1353
|
+
/** Float samples to the wire: NaN is 0, clamp to [-1, 1], negative x32768 else x32767, floor(x + 0.5), int16 LE, base64. */
|
|
1354
|
+
export function audioPcm16Encode(samples) {
|
|
1355
|
+
const bytes = new Uint8Array(samples.length * 2);
|
|
1356
|
+
for (let i = 0; i < samples.length; i++) {
|
|
1357
|
+
const raw = samples[i];
|
|
1358
|
+
const v = Number.isNaN(raw) ? 0 : Math.max(-1, Math.min(1, raw));
|
|
1359
|
+
const q = Math.max(-32768, Math.min(32767, Math.floor(v * (v < 0 ? 32768 : 32767) + 0.5)));
|
|
1360
|
+
bytes[2 * i] = q & 255;
|
|
1361
|
+
bytes[2 * i + 1] = (q >> 8) & 255;
|
|
1362
|
+
}
|
|
1363
|
+
return base64(bytes);
|
|
1364
|
+
}
|
|
1365
|
+
/** The wire back to floats (int16 LE / 32768); a trailing odd byte is dropped; text that is not base64 is null. */
|
|
1366
|
+
export function audioPcm16Decode(text) {
|
|
1367
|
+
const bytes = unbase64(text);
|
|
1368
|
+
if (bytes === null)
|
|
1369
|
+
return null;
|
|
1370
|
+
const out = [];
|
|
1371
|
+
for (let i = 0; i + 1 < bytes.length; i += 2) {
|
|
1372
|
+
const u = bytes[i] | (bytes[i + 1] << 8);
|
|
1373
|
+
out.push((u >= 32768 ? u - 65536 : u) / 32768);
|
|
1374
|
+
}
|
|
1375
|
+
return out;
|
|
1376
|
+
}
|
|
1377
|
+
/** What a `frame` answer puts on the wire: a dict or a list JSON-encoded with sorted keys, a string verbatim, anything else nothing. */
|
|
1378
|
+
export function audioSocketSends(answer) {
|
|
1379
|
+
if (typeof answer === "string")
|
|
1380
|
+
return answer;
|
|
1381
|
+
if (Array.isArray(answer) || isDict(answer))
|
|
1382
|
+
return JSON.stringify(sortedKeys(answer));
|
|
1383
|
+
return null;
|
|
1384
|
+
}
|
|
1385
|
+
function sortedKeys(v) {
|
|
1386
|
+
if (Array.isArray(v))
|
|
1387
|
+
return v.map(sortedKeys);
|
|
1388
|
+
if (isDict(v)) {
|
|
1389
|
+
const out = {};
|
|
1390
|
+
for (const k of Object.keys(v).sort())
|
|
1391
|
+
out[k] = sortedKeys(v[k]);
|
|
1392
|
+
return out;
|
|
1393
|
+
}
|
|
1394
|
+
return v === undefined ? null : v;
|
|
1395
|
+
}
|
|
1396
|
+
/** The per-chunk `frame` / `unframe` evaluator of one endpoint: its own store, `dsx.this` the chunk view or the
|
|
1397
|
+
* incoming message; an expression that throws answers null (the chunk sends nothing, the message is left to the page). */
|
|
1398
|
+
export function audioSocketEvaluator() {
|
|
1399
|
+
const store = new StackStore();
|
|
1400
|
+
return (expr, item) => {
|
|
1401
|
+
// A text frame that is not JSON is `dsx.this` as the string itself (socket.json unframe); the evaluator reads any value.
|
|
1402
|
+
try {
|
|
1403
|
+
return JSE.eval(expr, store, item);
|
|
1404
|
+
}
|
|
1405
|
+
catch {
|
|
1406
|
+
return null;
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
/** What an `unframe` answer plays: a non-empty string is a base64 pcm16 chunk (and consumes the message); else null. */
|
|
1411
|
+
export function audioSocketPlays(answer) {
|
|
1412
|
+
return typeof answer === "string" && answer !== "" ? answer : null;
|
|
1413
|
+
}
|
|
1414
|
+
/** The OUTPUT side's chunker (socket.json `pipe`): samples already resampled to the socket's rate accumulate and leave in
|
|
1415
|
+
* whole chunks, each numbered from 0; `reset` (the source went silent) drops what is pending and restarts the count. */
|
|
1416
|
+
export class AudioSocketPipe {
|
|
1417
|
+
pending = [];
|
|
1418
|
+
seq = 0;
|
|
1419
|
+
chunk;
|
|
1420
|
+
constructor(chunk) { this.chunk = chunk; }
|
|
1421
|
+
push(samples) {
|
|
1422
|
+
for (let i = 0; i < samples.length; i++)
|
|
1423
|
+
this.pending.push(samples[i]);
|
|
1424
|
+
const out = [];
|
|
1425
|
+
while (this.pending.length >= this.chunk)
|
|
1426
|
+
out.push({ samples: this.pending.splice(0, this.chunk), seq: this.seq++ });
|
|
1427
|
+
return out;
|
|
1428
|
+
}
|
|
1429
|
+
reset() {
|
|
1430
|
+
this.pending = [];
|
|
1431
|
+
this.seq = 0;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
/** The PLAYER side's gapless queue (socket.json `schedule`): a chunk starts at the later of `lead` after now and where the
|
|
1435
|
+
* previous one ends, and the next one starts where it ends. */
|
|
1436
|
+
export function audioSocketSchedule(now, next, duration, lead = 0.02) {
|
|
1437
|
+
const start = Math.max(now + lead, next);
|
|
1438
|
+
return { start, next: start + duration };
|
|
1439
|
+
}
|
|
1440
|
+
//# sourceMappingURL=audio-core.js.map
|