castle-web-cli 0.4.232 → 0.4.234
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/dist/agent-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/api.d.ts +11 -0
- package/dist/api.js +43 -0
- package/dist/bundle.d.ts +64 -0
- package/dist/bundle.js +558 -2
- package/dist/castle-host/host.d.ts +18 -2
- package/dist/castle-host/host.js +844 -39
- package/dist/castleJson.d.ts +23 -2
- package/dist/castleJson.js +46 -2
- package/dist/check.d.ts +3 -1
- package/dist/check.js +20 -3
- package/dist/chunkLoader.d.ts +3 -0
- package/dist/chunkLoader.js +111 -0
- package/dist/devParty.d.ts +26 -0
- package/dist/devParty.js +231 -0
- package/dist/devSaveStorage.js +4 -0
- package/dist/devSessionStorage.js +50 -2
- package/dist/devSocial.d.ts +24 -0
- package/dist/devSocial.js +70 -0
- package/dist/ide.d.ts +2 -0
- package/dist/ide.js +119 -15
- package/dist/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +11 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +25 -1
- package/dist/save-deck.js +178 -9
- package/dist/serve.js +32 -11
- package/dist/shell/assets/{index-D2tWM896.js → index-DulbYIJm.js} +97 -97
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/dist/vitePlugins.d.ts +2 -1
- package/dist/vitePlugins.js +13 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +339 -5
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +7 -3
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +176 -1
- package/kits/base/sdk/commands.js +3 -0
- package/kits/base/sdk/display.d.ts +3 -0
- package/kits/base/sdk/display.js +9 -3
- package/kits/base/sdk/hub.d.ts +37 -6
- package/kits/base/sdk/hub.js +63 -4
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +148 -32
- package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
- package/kits/base/sdk/party.d.ts +23 -0
- package/kits/base/sdk/party.js +91 -0
- package/kits/base/sdk/reconnectBudget.d.ts +23 -0
- package/kits/base/sdk/reconnectBudget.js +96 -0
- package/kits/base/sdk/save.d.ts +38 -1
- package/kits/base/sdk/save.js +81 -7
- package/kits/base/sdk/server/hub.d.ts +117 -0
- package/kits/base/sdk/server/hub.js +119 -2
- package/kits/base/sdk/server/platformHandle.d.ts +43 -1
- package/kits/base/sdk/server/storage.d.ts +17 -0
- package/kits/base/sdk/server/storage.js +65 -3
- package/kits/base/sdk/server/wrapper.d.ts +43 -6
- package/kits/base/sdk/server/wrapper.js +93 -9
- package/kits/base/sdk/social.d.ts +9 -0
- package/kits/base/sdk/social.js +5 -0
- package/kits/hub-game/CLAUDE.md +451 -13
- package/kits/hub-game/README.md +63 -0
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/castle.json +5 -5
- package/kits/hub-game/code/client/act.js +312 -0
- package/kits/hub-game/code/client/actionLayout.js +147 -0
- package/kits/hub-game/code/client/actionOverflow.js +556 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/arrivalCamera.js +50 -0
- package/kits/hub-game/code/client/askSlot.js +117 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +311 -35
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +253 -0
- package/kits/hub-game/code/client/backVisibility.js +13 -0
- package/kits/hub-game/code/client/ballot.js +472 -0
- package/kits/hub-game/code/client/build.js +38 -0
- package/kits/hub-game/code/client/chat.js +41 -5
- package/kits/hub-game/code/client/chatModeration.js +5 -0
- package/kits/hub-game/code/client/chrome.js +2144 -160
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/crowdNames.js +241 -0
- package/kits/hub-game/code/client/decor.js +515 -0
- package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
- package/kits/hub-game/code/client/doorErrors.js +39 -0
- package/kits/hub-game/code/client/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -0
- package/kits/hub-game/code/client/fall.js +18 -0
- package/kits/hub-game/code/client/farAvatars.js +233 -0
- package/kits/hub-game/code/client/firstJoin.js +9 -2
- package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
- package/kits/hub-game/code/client/frameBatch.js +5 -0
- package/kits/hub-game/code/client/grab.js +368 -29
- package/kits/hub-game/code/client/hookLayer.js +385 -20
- package/kits/hub-game/code/client/hudCopy.js +51 -0
- package/kits/hub-game/code/client/hudRate.js +20 -0
- package/kits/hub-game/code/client/idle.js +177 -24
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/invites.js +231 -0
- package/kits/hub-game/code/client/joinError.js +9 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +234 -0
- package/kits/hub-game/code/client/landscapeLayout.js +17 -0
- package/kits/hub-game/code/client/layoutCache.js +264 -0
- package/kits/hub-game/code/client/loadTelemetry.js +20 -0
- package/kits/hub-game/code/client/loadingCover.js +148 -0
- package/kits/hub-game/code/client/loadingEntry.js +8 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/menuRows.js +43 -0
- package/kits/hub-game/code/client/modelReady.js +7 -0
- package/kits/hub-game/code/client/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- package/kits/hub-game/code/client/padCueArrival.js +23 -0
- package/kits/hub-game/code/client/padCues.js +112 -0
- package/kits/hub-game/code/client/padOccupancy.js +88 -0
- package/kits/hub-game/code/client/padReadability.js +26 -0
- package/kits/hub-game/code/client/padRings.js +69 -0
- package/kits/hub-game/code/client/pushVisit.js +14 -0
- package/kits/hub-game/code/client/quality.js +205 -0
- package/kits/hub-game/code/client/qualityEntry.js +55 -0
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/safeLayout.js +338 -0
- package/kits/hub-game/code/client/safeStyle.js +42 -0
- package/kits/hub-game/code/client/say.js +12 -3
- package/kits/hub-game/code/client/shot.js +146 -0
- package/kits/hub-game/code/client/shotFit.js +56 -0
- package/kits/hub-game/code/client/signIn.js +28 -0
- package/kits/hub-game/code/client/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +162 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +714 -59
- package/kits/hub-game/code/client/tiers.js +543 -52
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +39 -2
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/weakestLookBake.js +92 -0
- package/kits/hub-game/code/client/weakestTier.js +295 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/worldLabels.js +241 -0
- package/kits/hub-game/code/client/yours.js +200 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/npcDisplayText.js +55 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/act.js +124 -0
- package/kits/hub-game/code/server/actions.js +138 -0
- package/kits/hub-game/code/server/actors.js +11 -2
- package/kits/hub-game/code/server/analytics.js +83 -0
- package/kits/hub-game/code/server/anonymousEntry.js +49 -0
- package/kits/hub-game/code/server/arrivalPose.js +36 -0
- package/kits/hub-game/code/server/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +107 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/doorAnalytics.js +52 -0
- package/kits/hub-game/code/server/earned.js +478 -0
- package/kits/hub-game/code/server/frameBatch.js +183 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +272 -0
- package/kits/hub-game/code/server/history.js +7 -0
- package/kits/hub-game/code/server/hub.js +2510 -95
- package/kits/hub-game/code/server/idle.js +60 -12
- package/kits/hub-game/code/server/index.js +28 -6
- package/kits/hub-game/code/server/invites.js +19 -0
- package/kits/hub-game/code/server/labels.js +36 -2
- package/kits/hub-game/code/server/loadAbandon.js +106 -0
- package/kits/hub-game/code/server/manifest.js +586 -7
- package/kits/hub-game/code/server/menu.js +161 -0
- package/kits/hub-game/code/server/npcs.js +1025 -113
- package/kits/hub-game/code/server/observe.js +408 -0
- package/kits/hub-game/code/server/padOccupancy.js +85 -0
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +30 -0
- package/kits/hub-game/code/server/resumePose.js +152 -0
- package/kits/hub-game/code/server/say.js +1 -1
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +123 -0
- package/kits/hub-game/code/server/storageLimit.js +187 -0
- package/kits/hub-game/code/server/vis.js +175 -0
- package/kits/hub-game/code/server/wear.js +12 -0
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/act.js +35 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/danceIdle.js +28 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/loadStages.js +12 -0
- package/kits/hub-game/code/shared/quality.js +74 -0
- package/kits/hub-game/code/shared/say.js +2 -0
- package/kits/hub-game/code/shared/shot.js +53 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +1753 -202
- package/kits/hub-game/docs/analytics.md +279 -0
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +3475 -77
- package/kits/hub-game/docs/home-pieces.md +71 -0
- package/kits/hub-game/docs/observed-progress.md +252 -0
- package/kits/hub-game/main.jsx +2 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +10 -1
- package/kits/hub-game/package.json +6 -2
- package/kits/hub-game/play/player.js +142 -0
- package/kits/hub-game/play/registry.js +47 -0
- package/kits/hub-game/play.jsx +37 -0
- package/kits/hub-game/scripts/check.mjs +117 -16
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +132 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +26 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +123 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-act-client.mjs +186 -0
- package/kits/hub-game/scripts/test-act.mjs +171 -0
- package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
- package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +853 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +38 -23
- package/kits/hub-game/scripts/test-analytics.mjs +76 -0
- package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
- package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +792 -0
- package/kits/hub-game/scripts/test-avatar.mjs +584 -7
- package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
- package/kits/hub-game/scripts/test-ballot.mjs +1008 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
- package/kits/hub-game/scripts/test-build.mjs +49 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +863 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +216 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
- package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +344 -0
- package/kits/hub-game/scripts/test-decor.mjs +464 -0
- package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
- package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1224 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
- package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
- package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +961 -0
- package/kits/hub-game/scripts/test-grab.mjs +7 -0
- package/kits/hub-game/scripts/test-hats.mjs +422 -168
- package/kits/hub-game/scripts/test-high-only.mjs +170 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +758 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +1594 -12
- package/kits/hub-game/scripts/test-hud-clear.mjs +484 -57
- package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
- package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
- package/kits/hub-game/scripts/test-idle.mjs +427 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +513 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-interest.mjs +15 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
- package/kits/hub-game/scripts/test-invites.mjs +109 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +664 -0
- package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
- package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
- package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
- package/kits/hub-game/scripts/test-manifest.mjs +472 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +585 -0
- package/kits/hub-game/scripts/test-menu.mjs +319 -0
- package/kits/hub-game/scripts/test-npcs.mjs +2528 -13
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-observed.mjs +745 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
- package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
- package/kits/hub-game/scripts/test-picker.mjs +541 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
- package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
- package/kits/hub-game/scripts/test-quality.mjs +385 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1733 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
- package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
- package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
- package/kits/hub-game/scripts/test-say.mjs +1 -1
- package/kits/hub-game/scripts/test-shot.mjs +901 -0
- package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5437 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +449 -0
- package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1904 -0
- package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +412 -0
- package/kits/hub-game/scripts/test-tiers.mjs +476 -2
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +22 -22
- package/kits/hub-game/scripts/test-vis.mjs +770 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +210 -0
- package/kits/hub-game/scripts/test-yours.mjs +403 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +443 -34
- package/kits/multiplayer-3d/package-lock.json +8 -1
- package/kits/multiplayer-3d/package.json +3 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
- package/kits/physics-2d/CLAUDE.md +19 -1
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/frozenActors.js +233 -0
- package/kits/physics-2d/engine/scene.js +337 -3
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/eslint.config.js +1 -1
- package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
- package/kits/physics-2d/play/behaviors/Camera.js +40 -0
- package/kits/physics-2d/play/behaviors/Collider.js +122 -0
- package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
- package/kits/physics-2d/play/behaviors/Goal.js +46 -0
- package/kits/physics-2d/play/behaviors/Joints.js +126 -0
- package/kits/physics-2d/play/behaviors/Layout.js +71 -0
- package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
- package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
- package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
- package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
- package/kits/physics-2d/play/behaviors/Style.js +209 -0
- package/kits/physics-2d/play/behaviors/Text.js +85 -0
- package/kits/physics-2d/play/behaviors/Video.js +93 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +42 -529
- package/kits/physics-3d/behaviors/Body.jsx +3 -0
- package/kits/physics-3d/behaviors/Model.jsx +3 -0
- package/kits/physics-3d/behaviors/Player.jsx +661 -87
- package/kits/physics-3d/behaviors/Shape.jsx +3 -0
- package/kits/physics-3d/behaviors/Solid.jsx +3 -0
- package/kits/physics-3d/behaviors/Transform.jsx +3 -0
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-camera.md +542 -0
- package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
- package/kits/physics-3d/docs/engine-load.md +149 -0
- package/kits/physics-3d/docs/engine-look.md +114 -0
- package/kits/physics-3d/docs/engine-shadows.md +372 -0
- package/kits/physics-3d/docs/engine-skip-work.md +187 -0
- package/kits/physics-3d/docs/engine-sky.md +198 -0
- package/kits/physics-3d/docs/engine-static-actors.md +226 -0
- package/kits/physics-3d/docs/engine-view.md +37 -0
- package/kits/physics-3d/docs/pxmodel-format.md +9 -1
- package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -277
- package/kits/physics-3d/engine3d/actornode.js +87 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/branches.js +3 -13
- package/kits/physics-3d/engine3d/cage.js +2 -7
- package/kits/physics-3d/engine3d/cageops.js +2 -17
- package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
- package/kits/physics-3d/engine3d/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +99 -0
- package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
- package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
- package/kits/physics-3d/engine3d/gait.js +126 -0
- package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +514 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/modelFiles.js +3 -17
- package/kits/physics-3d/engine3d/modelMath.js +49 -0
- package/kits/physics-3d/engine3d/modelready.js +16 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +106 -21
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +522 -10
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/partgeometry.js +1 -16
- package/kits/physics-3d/engine3d/paths.js +1 -9
- package/kits/physics-3d/engine3d/playTimings.js +50 -0
- package/kits/physics-3d/engine3d/playerRun.js +372 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/rapier.js +27 -0
- package/kits/physics-3d/engine3d/scatter.js +1 -11
- package/kits/physics-3d/engine3d/shadowfade.js +890 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/squarefirst.js +177 -0
- package/kits/physics-3d/engine3d/stillshadows.js +399 -0
- package/kits/physics-3d/engine3d/sweep.js +1 -25
- package/kits/physics-3d/engine3d/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +1253 -76
- package/kits/physics-3d/eslint.config.js +2 -1
- package/kits/physics-3d/main.jsx +10 -2
- package/kits/physics-3d/package-lock.json +7 -0
- package/kits/physics-3d/package.json +5 -1
- package/kits/physics-3d/play/behaviors/Body.js +31 -0
- package/kits/physics-3d/play/behaviors/Door.js +37 -0
- package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
- package/kits/physics-3d/play/behaviors/Model.js +23 -0
- package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
- package/kits/physics-3d/play/behaviors/Player.js +1204 -0
- package/kits/physics-3d/play/behaviors/Shape.js +47 -0
- package/kits/physics-3d/play/behaviors/Solid.js +16 -0
- package/kits/physics-3d/play/behaviors/Transform.js +29 -0
- package/kits/physics-3d/pnpm-lock.yaml +8 -0
- package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
- package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
- package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2613 -82
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +2 -2
- package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +438 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
- package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
- package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
- package/kits/physics-3d/scripts/test-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +5 -2
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +2001 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +582 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +657 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +10 -1
- package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2174 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +7 -2
- package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +419 -9
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +33 -10
- package/kits/real-time/code/client/gameHooks.js +2 -0
- package/kits/real-time/code/client/joinOverlay.js +9 -4
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +102 -22
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,1209 @@
|
|
|
1
|
+
// Simlish-like NPC speech, round 6: smooth glottal pulses and gated breath.
|
|
2
|
+
//
|
|
3
|
+
// simlish(context, destination, text, startTime, voice) -> { end, stop(t) }
|
|
4
|
+
//
|
|
5
|
+
// Round 4's generator (../hub-sound-audition-4/modules/simlish.js), retuned
|
|
6
|
+
// toward measurements of real Simlish (The Sims 1 conversation takes, see
|
|
7
|
+
// analysis.md). Nothing here is derived from those recordings' samples: the
|
|
8
|
+
// voice is still a buzz through four formant filters plus filtered noise,
|
|
9
|
+
// and only parameters moved.
|
|
10
|
+
//
|
|
11
|
+
// consonant noise s, sh, f, h and the aspiration of p t k are shorter
|
|
12
|
+
// (the reference's hissy stretches: median 50 ms; round
|
|
13
|
+
// 4's: 55-75 ms, its s up to 140 ms), swell and fade instead of
|
|
14
|
+
// holding a flat level, and sit in narrower bands (s
|
|
15
|
+
// 3.8-10 kHz, sh 1.9-6 kHz, f 1.8-7 kHz; round 4's f
|
|
16
|
+
// was white from 1.4 to 9 kHz and s reached 11 kHz).
|
|
17
|
+
// Aspiration (h, and p t k) is kept under 5 kHz.
|
|
18
|
+
// pitch the reference moves 10-16 semitones within a phrase
|
|
19
|
+
// and glides inside most syllables (2-3 st); round 4
|
|
20
|
+
// moved ~5 st and held every syllable flat. Now: a
|
|
21
|
+
// register per phrase, bigger hops between syllables, a
|
|
22
|
+
// quick rise, fall or rise-fall inside most vowels, a
|
|
23
|
+
// gentler declination. The glides stay inside the
|
|
24
|
+
// vowel, so nothing slides across a pause (round 3's
|
|
25
|
+
// fault). `expr` scales all of it (0 = round 4's tune).
|
|
26
|
+
// rhythm three in ten syllables are drawn out (the reference's
|
|
27
|
+
// syllable timing varies about twice as much as ours).
|
|
28
|
+
// voice quality breath noise inside the voice, kept under ~3 kHz (HNR
|
|
29
|
+
// ~29 dB -> ~16 dB; the reference measures ~13 dB) and
|
|
30
|
+
// random pitch jitter (0.5% -> ~1.5%; reference ~2%). `breath`
|
|
31
|
+
// and `jitter` scale them.
|
|
32
|
+
// rate the reference speaks ~3.1 syllables a second; the
|
|
33
|
+
// page's options use rate 3.3 (round 4: 3.9).
|
|
34
|
+
//
|
|
35
|
+
// Round 6 adds the breath gate oscillator: 22 synthesis nodes per line.
|
|
36
|
+
|
|
37
|
+
export const BABBLE_MAX_S = 3;
|
|
38
|
+
export const BABBLE_MAX_SYLLABLES = 30;
|
|
39
|
+
|
|
40
|
+
const LETTER = /[\p{L}\p{N}']/u;
|
|
41
|
+
export const TUNE = { shelfHz: 3000, shelfDb: 0, fric: 3, asp: 1.3, burst: 1.7, formantDb: [14, 15, 12, 9], formantQ: [4, 6, 7, 5], source: 'lf', rd: 1.2, oq: 0.6, sq: 2.5, srcGain: 1, breathGate: 1, tilt: 1.3, harmonics: 40, taper: 0.4, voiceTop: 9000, gain: 0.2, vowelShare: 0.4, breath: 0.16, breathHz: 3200, jitter: 400, jitterHz: 220 };
|
|
42
|
+
|
|
43
|
+
export const NODE_COUNT = 22;
|
|
44
|
+
|
|
45
|
+
// [F1, F2, F3, F4] Hz, an adult's; scaled by `mouth`.
|
|
46
|
+
const VOWELS = {
|
|
47
|
+
a: [800, 1250, 2650, 3550],
|
|
48
|
+
e: [520, 1850, 2600, 3550],
|
|
49
|
+
i: [320, 2350, 3000, 3750],
|
|
50
|
+
o: [540, 920, 2500, 3450],
|
|
51
|
+
u: [360, 880, 2350, 3400],
|
|
52
|
+
ae: [700, 1720, 2600, 3550],
|
|
53
|
+
uh: [640, 1220, 2550, 3500],
|
|
54
|
+
};
|
|
55
|
+
const DIPHTHONGS = { ai: ['a', 'i'], ou: ['o', 'u'], ei: ['e', 'i'], oi: ['o', 'i'] };
|
|
56
|
+
|
|
57
|
+
const KIND = {
|
|
58
|
+
p: 'stop', t: 'stop', k: 'stop', b: 'stop', d: 'stop', g: 'stop',
|
|
59
|
+
s: 'fric', sh: 'fric', f: 'fric', h: 'h',
|
|
60
|
+
m: 'nasal', n: 'nasal',
|
|
61
|
+
l: 'liquid', r: 'liquid', w: 'liquid', y: 'liquid',
|
|
62
|
+
};
|
|
63
|
+
const VOICED = new Set(['b', 'd', 'g']);
|
|
64
|
+
const PLACE = { p: 'lab', b: 'lab', m: 'lab', f: 'lab', w: 'lab', t: 'alv', d: 'alv', n: 'alv', s: 'alv', l: 'alv', sh: 'post', r: 'post', y: 'pal', k: 'vel', g: 'vel', h: 'glot' };
|
|
65
|
+
|
|
66
|
+
// Weighted choices; Simlish leans on b, l, n, m, sh and open vowels.
|
|
67
|
+
const ONSETS = [['b', 11], ['d', 7], ['g', 5], ['p', 6], ['t', 6], ['k', 7], ['s', 9], ['sh', 7], ['f', 5], ['h', 4], ['m', 8], ['n', 8], ['l', 9], ['r', 5], ['w', 5], ['y', 3]];
|
|
68
|
+
const CODAS = [['n', 22], ['m', 9], ['l', 14], ['s', 14], ['sh', 7], ['k', 10], ['t', 9], ['b', 5], ['r', 5], ['g', 5]];
|
|
69
|
+
const NUCLEI = [['a', 20], ['e', 13], ['i', 12], ['o', 14], ['u', 9], ['ae', 7], ['uh', 8], ['ai', 6], ['ou', 4], ['ei', 4], ['oi', 3]];
|
|
70
|
+
|
|
71
|
+
function hashOf(text) {
|
|
72
|
+
let h = 0x811c9dc5;
|
|
73
|
+
const s = String(text);
|
|
74
|
+
for (let i = 0; i < s.length; i += 1) {
|
|
75
|
+
h ^= s.charCodeAt(i);
|
|
76
|
+
h = Math.imul(h, 0x01000193);
|
|
77
|
+
}
|
|
78
|
+
return h >>> 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function seeded(seed) {
|
|
82
|
+
let a = seed >>> 0;
|
|
83
|
+
return () => {
|
|
84
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
85
|
+
let t = a;
|
|
86
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
87
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
88
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function pick(list, next) {
|
|
93
|
+
let total = 0;
|
|
94
|
+
for (const [, w] of list) {
|
|
95
|
+
total += w;
|
|
96
|
+
}
|
|
97
|
+
let r = next() * total;
|
|
98
|
+
for (const [v, w] of list) {
|
|
99
|
+
r -= w;
|
|
100
|
+
if (r < 0) {
|
|
101
|
+
return v;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return list[0][0];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// One made-up word of `n` syllables.
|
|
108
|
+
function makeSylls(n, next) {
|
|
109
|
+
const sylls = [];
|
|
110
|
+
for (let i = 0; i < n; i += 1) {
|
|
111
|
+
const onset = i > 0 || next() < 0.88 ? pick(ONSETS, next) : null;
|
|
112
|
+
const last = i === n - 1;
|
|
113
|
+
const coda = next() < (last ? 0.42 : 0.22) ? pick(CODAS, next) : null;
|
|
114
|
+
sylls.push({ onset, nucleus: pick(NUCLEI, next), coda });
|
|
115
|
+
}
|
|
116
|
+
return sylls;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Common English one-syllable words as these syllables would sound them
|
|
120
|
+
// ("mi" is "me", "tu" is "two"); a one-syllable pseudo-word that lands on one
|
|
121
|
+
// is drawn again, so nothing real slips out. Longer words are not checked.
|
|
122
|
+
const REAL = new Set(`bi di ki mi ni pi ti si shi fi hi li wi bo do go mo no to so sho fo ho lo ro wo yo bu du gu ku mu nu pu tu su shu hu lu ru wu yu
|
|
123
|
+
ba ma pa la ha sha bai dai gai mai nai pai tai sai shai hai lai rai wai bei dei gei kei mei nei pei sei hei lei rei wei yei bou dou gou mou nou tou sou shou lou rou
|
|
124
|
+
boi toi soi koi bin pin tin din sin kin fin win yes bes ben ten den hen men pen yen ban man pan tan fan ran can kan son sun fun gun run bun nun don
|
|
125
|
+
bit bet bat but pit pet pat pot put kit kat cut kut hit hat hot hut lit let lot nut not net sit set sat sot fit fat wit wet yet rat rot rut mat met
|
|
126
|
+
bad bed bid bud bod dad did had hid mad mud red rid rod sad kid lid led god bag big bog bug dig dog fig hog hug log leg lag rag rig wig pig peg mug
|
|
127
|
+
sob rob rib rub mob web bus mis mes pas gas has his yes kis los nos dos sis sash mash bash rash lash cash dish fish wish push bush rush mush gush
|
|
128
|
+
bel bil bal tel til tal sel sil kil kal fel fil fal hel hil hal mel mil mal nil wel wil pil pal dal dil dol gal gol gul hol pol pul sol tol
|
|
129
|
+
bik bak bek bok buk lik lak lek lok luk sik sak tik tak tok tuk pik pak pek pok puk nik nek nok rak rok ruk sek sok kik kak hik hak hok huk
|
|
130
|
+
bom tom mom mum sum som dim him hem ham jam ram rim tim gum gem rum lum`.split(/\s+/));
|
|
131
|
+
|
|
132
|
+
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
133
|
+
const num = (v, fallback) => (typeof v === 'number' && Number.isFinite(v) ? v : fallback);
|
|
134
|
+
|
|
135
|
+
export const VOICE_DEFAULTS = {
|
|
136
|
+
pitch: 240, // Hz, the voice's resting pitch
|
|
137
|
+
rate: 4.2, // syllables a second, on average
|
|
138
|
+
pace: 1, // how much the pace, gaps and emphasis vary (0 = even)
|
|
139
|
+
mouth: 1.08, // formant scale (a smaller mouth, higher formants)
|
|
140
|
+
spread: null, // semitones of word accent (default 3 + 2 * expr)
|
|
141
|
+
expr: 1, // pitch expressiveness: phrase registers, hops, glides (0 = round 4)
|
|
142
|
+
breath: 1, // breath noise in the voice (0 = none)
|
|
143
|
+
jitter: 1, // random pitch jitter (0 = none)
|
|
144
|
+
lift: 1, // how far ?, ! and . move the tune
|
|
145
|
+
bounce: 0, // semitones of syllable-to-syllable hop
|
|
146
|
+
vibrato: 9, // cents
|
|
147
|
+
wordGap: 0.045, // seconds between pseudo-words
|
|
148
|
+
level: 0.5,
|
|
149
|
+
seed: 0, // varies the made-up words between speakers
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// The four round-6 audition options, including their matched source RMS.
|
|
153
|
+
export const VOICE_TYPES = {
|
|
154
|
+
townsfolk: { pitch: 240, rate: 3.3, mouth: 1.08, pace: 1.3, tune: { source: 'rosenberg', oq: 0.6, sq: 2.5, breathHz: 2400, srcGain: 0.86 } },
|
|
155
|
+
lively: { pitch: 240, rate: 4.6, mouth: 1.08, pace: 1.3, tune: { source: 'rosenberg', oq: 0.6, sq: 2.5, breathHz: 2400, srcGain: 0.86 } },
|
|
156
|
+
gruff: { pitch: 240, rate: 3.3, mouth: 1.08, pace: 1.3, tune: { source: 'lf', rd: 1.2, formantDb: [11, 12, 9, 6], breathHz: 2400, srcGain: 1.158 } },
|
|
157
|
+
gentle: { pitch: 240, rate: 3.3, mouth: 1.08, pace: 1.3, jitter: 0.7, breath: 0.75, tune: { source: 'rosenberg', oq: 0.6, sq: 2.5, breathHz: 2400, formantDb: [11, 12, 9, 6], jitterHz: 120, srcGain: 1.047 } },
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// --- the plan ----------------------------------------------------------------
|
|
161
|
+
|
|
162
|
+
// A line as sentences of words of syllables { onset, nucleus, coda }.
|
|
163
|
+
export function simlishWords(text, seed = 0) {
|
|
164
|
+
const sentences = [];
|
|
165
|
+
let words = [];
|
|
166
|
+
let word = '';
|
|
167
|
+
const flushWord = (pauseAfter) => {
|
|
168
|
+
if (word) {
|
|
169
|
+
const n = clamp(Math.round(word.replace(/'/g, '').length / 3.2), 1, 3);
|
|
170
|
+
const next = seeded(hashOf(word.toLowerCase()) ^ seed);
|
|
171
|
+
let sylls = [];
|
|
172
|
+
for (let tries = 0; tries < 8; tries += 1) {
|
|
173
|
+
sylls = makeSylls(n, next);
|
|
174
|
+
if (n > 1 || !REAL.has(sylls.map((y) => `${y.onset ?? ''}${y.nucleus}${y.coda ?? ''}`).join(''))) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
words.push({ sylls, pause: 0 });
|
|
179
|
+
word = '';
|
|
180
|
+
}
|
|
181
|
+
if (pauseAfter && words.length) {
|
|
182
|
+
words[words.length - 1].pause = Math.max(words[words.length - 1].pause, pauseAfter);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const close = (mark) => {
|
|
186
|
+
flushWord(0);
|
|
187
|
+
if (words.length) {
|
|
188
|
+
sentences.push({ words, mark });
|
|
189
|
+
words = [];
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
for (const ch of String(text ?? '')) {
|
|
193
|
+
if (LETTER.test(ch)) {
|
|
194
|
+
word += ch;
|
|
195
|
+
} else if ('.!?…'.includes(ch)) {
|
|
196
|
+
close(ch === '…' ? '.' : ch);
|
|
197
|
+
} else if (',;:—–'.includes(ch)) {
|
|
198
|
+
flushWord(0.19);
|
|
199
|
+
} else {
|
|
200
|
+
flushWord(0);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
close('.');
|
|
204
|
+
return sentences;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// --- the synthesiser -----------------------------------------------------------
|
|
208
|
+
|
|
209
|
+
// --- the glottal source ------------------------------------------------------
|
|
210
|
+
//
|
|
211
|
+
// Round 5's source was `n` harmonics in sine phase falling as 1/k^tilt
|
|
212
|
+
// (tilt 1.3: -7.8 dB/octave, between a sawtooth's -6 and a soft pulse's -12),
|
|
213
|
+
// with only the top third tapered: a darkened sawtooth with one sharp edge a
|
|
214
|
+
// cycle. Round 6 can also use a glottal pulse with a soft closing phase,
|
|
215
|
+
// realised as a PeriodicWave from its Fourier series:
|
|
216
|
+
//
|
|
217
|
+
// 'rosenberg' Rosenberg's pulse with raised-cosine opening AND closing
|
|
218
|
+
// (open quotient oq, speed quotient sq = opening / closing),
|
|
219
|
+
// radiated (differentiated, +6 dB/octave as from the lips).
|
|
220
|
+
// The flow and its slope are continuous, so the source falls
|
|
221
|
+
// at -12 dB/octave above a few harmonics.
|
|
222
|
+
// 'lf' the Liljencrants-Fant flow derivative, set by Fant's Rd
|
|
223
|
+
// (about 1 = modal, 1.5+ = soft/breathy): a firmer excitation
|
|
224
|
+
// at closure with an exponential return phase, so -6
|
|
225
|
+
// dB/octave up to Fa = 1/(2 pi Ta) and -12 above it.
|
|
226
|
+
// 'buzz' round 5's series (kept for comparison).
|
|
227
|
+
//
|
|
228
|
+
// The same pulse's flow (its open phase) gates the breath noise, so breath
|
|
229
|
+
// arrives in puffs on each glottal cycle, before the formants, rather than
|
|
230
|
+
// as a steady hiss beside the voice.
|
|
231
|
+
|
|
232
|
+
const GP = 2048; // samples per period for the Fourier series
|
|
233
|
+
function lfParams(rd) {
|
|
234
|
+
const rap = (-1 + 4.8 * rd) / 100;
|
|
235
|
+
const rkp = (22.4 + 11.8 * rd) / 100;
|
|
236
|
+
const rgp = 1 / (4 * ((0.11 * rd / (0.5 + 1.2 * rkp)) - rap) / rkp);
|
|
237
|
+
const tp = 1 / (2 * rgp);
|
|
238
|
+
return { tp, te: tp * (1 + rkp), ta: rap };
|
|
239
|
+
}
|
|
240
|
+
// One period (T = 1) of the source (flow derivative, `d`) and the flow (`g`).
|
|
241
|
+
export function glottalPeriod(tune) {
|
|
242
|
+
const d = new Float64Array(GP);
|
|
243
|
+
const g = new Float64Array(GP);
|
|
244
|
+
if (tune.source === 'rosenberg') {
|
|
245
|
+
const tp = tune.oq * tune.sq / (1 + tune.sq);
|
|
246
|
+
const tn = tune.oq / (1 + tune.sq);
|
|
247
|
+
for (let i = 0; i < GP; i += 1) {
|
|
248
|
+
const t = (i + 0.5) / GP;
|
|
249
|
+
if (t < tp) {
|
|
250
|
+
g[i] = 0.5 - 0.5 * Math.cos(Math.PI * t / tp);
|
|
251
|
+
d[i] = 0.5 * Math.PI / tp * Math.sin(Math.PI * t / tp);
|
|
252
|
+
} else if (t < tp + tn) {
|
|
253
|
+
g[i] = 0.5 + 0.5 * Math.cos(Math.PI * (t - tp) / tn);
|
|
254
|
+
d[i] = -0.5 * Math.PI / tn * Math.sin(Math.PI * (t - tp) / tn);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return { d, g };
|
|
258
|
+
}
|
|
259
|
+
const { tp, te, ta } = lfParams(tune.rd);
|
|
260
|
+
const wg = Math.PI / tp;
|
|
261
|
+
let eps = 1 / ta;
|
|
262
|
+
for (let i = 0; i < 60; i += 1) {
|
|
263
|
+
eps = (1 - Math.exp(-eps * (1 - te))) / ta;
|
|
264
|
+
}
|
|
265
|
+
const fill = (alpha) => {
|
|
266
|
+
const ee = -Math.exp(alpha * te) * Math.sin(wg * te);
|
|
267
|
+
let sum = 0;
|
|
268
|
+
for (let i = 0; i < GP; i += 1) {
|
|
269
|
+
const t = (i + 0.5) / GP;
|
|
270
|
+
d[i] = t <= te ? Math.exp(alpha * t) * Math.sin(wg * t) : -(ee / (eps * ta)) * (Math.exp(-eps * (t - te)) - Math.exp(-eps * (1 - te)));
|
|
271
|
+
sum += d[i];
|
|
272
|
+
}
|
|
273
|
+
return sum;
|
|
274
|
+
};
|
|
275
|
+
// alpha so the flow returns to zero over the cycle (bisection; the net
|
|
276
|
+
// area falls as alpha grows).
|
|
277
|
+
let lo = -20;
|
|
278
|
+
let hi = 60;
|
|
279
|
+
for (let i = 0; i < 80; i += 1) {
|
|
280
|
+
const mid = (lo + hi) / 2;
|
|
281
|
+
if (fill(mid) > 0) {
|
|
282
|
+
lo = mid;
|
|
283
|
+
} else {
|
|
284
|
+
hi = mid;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
fill((lo + hi) / 2);
|
|
288
|
+
let acc = 0;
|
|
289
|
+
let low = Infinity;
|
|
290
|
+
for (let i = 0; i < GP; i += 1) {
|
|
291
|
+
acc += d[i] / GP;
|
|
292
|
+
g[i] = acc;
|
|
293
|
+
low = Math.min(low, acc);
|
|
294
|
+
}
|
|
295
|
+
for (let i = 0; i < GP; i += 1) {
|
|
296
|
+
g[i] -= low;
|
|
297
|
+
}
|
|
298
|
+
return { d, g };
|
|
299
|
+
}
|
|
300
|
+
// Fourier coefficients (PeriodicWave's real/imag) of one period, k = 1..n.
|
|
301
|
+
function series(x, n) {
|
|
302
|
+
const real = new Float32Array(n + 1);
|
|
303
|
+
const imag = new Float32Array(n + 1);
|
|
304
|
+
for (let k = 1; k <= n; k += 1) {
|
|
305
|
+
let re = 0;
|
|
306
|
+
let im = 0;
|
|
307
|
+
for (let i = 0; i < GP; i += 1) {
|
|
308
|
+
const a = 2 * Math.PI * k * (i + 0.5) / GP;
|
|
309
|
+
re += x[i] * Math.cos(a);
|
|
310
|
+
im += x[i] * Math.sin(a);
|
|
311
|
+
}
|
|
312
|
+
real[k] = 2 * re / GP;
|
|
313
|
+
imag[k] = 2 * im / GP;
|
|
314
|
+
}
|
|
315
|
+
return { real, imag };
|
|
316
|
+
}
|
|
317
|
+
const rmsOfSeries = (s) => {
|
|
318
|
+
let e = 0;
|
|
319
|
+
for (let k = 1; k < s.real.length; k += 1) {
|
|
320
|
+
e += (s.real[k] ** 2 + s.imag[k] ** 2) / 2;
|
|
321
|
+
}
|
|
322
|
+
return Math.sqrt(e);
|
|
323
|
+
};
|
|
324
|
+
// The source's harmonic coefficients, at the RMS round 5's buzz had after
|
|
325
|
+
// Chromium normalised it to a peak of 1 (so levels stay comparable), times
|
|
326
|
+
// tune.srcGain. Exported for the analysis.
|
|
327
|
+
export function sourceCoefficients(tune) {
|
|
328
|
+
const n = tune.harmonics;
|
|
329
|
+
const from = Math.floor(n * (1 - tune.taper));
|
|
330
|
+
const fade = (i) => (i <= from ? 1 : 0.5 + 0.5 * Math.cos(Math.PI * (i - from) / (n - from + 1)));
|
|
331
|
+
let s;
|
|
332
|
+
if (tune.source === 'buzz') {
|
|
333
|
+
s = { real: new Float32Array(n + 1), imag: new Float32Array(n + 1) };
|
|
334
|
+
for (let i = 1; i <= n; i += 1) {
|
|
335
|
+
s.imag[i] = fade(i) / i ** tune.tilt;
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
s = series(glottalPeriod(tune).d, n);
|
|
339
|
+
for (let i = 1; i <= n; i += 1) {
|
|
340
|
+
s.real[i] *= fade(i);
|
|
341
|
+
s.imag[i] *= fade(i);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const scale = buzzRmsOf() * (tune.srcGain ?? 1) / rmsOfSeries(s);
|
|
345
|
+
for (let i = 1; i <= n; i += 1) {
|
|
346
|
+
s.real[i] *= scale;
|
|
347
|
+
s.imag[i] *= scale;
|
|
348
|
+
}
|
|
349
|
+
return s;
|
|
350
|
+
}
|
|
351
|
+
// RMS of round 5's buzz (40 harmonics, 1/k^1.3, taper 0.4) once normalised
|
|
352
|
+
// to a peak of 1, as Chromium plays it.
|
|
353
|
+
// Compute only when a source is requested: keyless/babble-off decks do no work.
|
|
354
|
+
let buzzRms;
|
|
355
|
+
function buzzRmsOf() {
|
|
356
|
+
if (buzzRms !== undefined) { return buzzRms; }
|
|
357
|
+
const n = 40;
|
|
358
|
+
const from = Math.floor(n * 0.6);
|
|
359
|
+
let e = 0;
|
|
360
|
+
let peak = 0;
|
|
361
|
+
const amp = [];
|
|
362
|
+
for (let i = 1; i <= n; i += 1) {
|
|
363
|
+
const a = (i <= from ? 1 : 0.5 + 0.5 * Math.cos(Math.PI * (i - from) / (n - from + 1))) / i ** 1.3;
|
|
364
|
+
amp.push(a);
|
|
365
|
+
e += a * a / 2;
|
|
366
|
+
}
|
|
367
|
+
for (let j = 0; j < 4096; j += 1) {
|
|
368
|
+
let v = 0;
|
|
369
|
+
for (let i = 1; i <= n; i += 1) {
|
|
370
|
+
v += amp[i - 1] * Math.sin(2 * Math.PI * i * j / 4096);
|
|
371
|
+
}
|
|
372
|
+
peak = Math.max(peak, Math.abs(v));
|
|
373
|
+
}
|
|
374
|
+
buzzRms = Math.sqrt(e) / peak;
|
|
375
|
+
return buzzRms;
|
|
376
|
+
}
|
|
377
|
+
// The breath gate: the flow, 0 (closed) to 1 (fully open), as a mean and a
|
|
378
|
+
// PeriodicWave of what moves around it, scaled so the gated breath keeps the
|
|
379
|
+
// energy an ungated one had (so `breath` means the same amount of noise).
|
|
380
|
+
export function breathGate(tune) {
|
|
381
|
+
const { g } = glottalPeriod(tune);
|
|
382
|
+
let top = 0;
|
|
383
|
+
for (const v of g) {
|
|
384
|
+
top = Math.max(top, v);
|
|
385
|
+
}
|
|
386
|
+
let mean = 0;
|
|
387
|
+
let sq = 0;
|
|
388
|
+
const m = new Float64Array(GP);
|
|
389
|
+
for (let i = 0; i < GP; i += 1) {
|
|
390
|
+
m[i] = g[i] / top;
|
|
391
|
+
mean += m[i] / GP;
|
|
392
|
+
sq += m[i] * m[i] / GP;
|
|
393
|
+
}
|
|
394
|
+
const cal = 1 / Math.sqrt(sq);
|
|
395
|
+
for (let i = 0; i < GP; i += 1) {
|
|
396
|
+
m[i] -= mean;
|
|
397
|
+
}
|
|
398
|
+
const s = series(m, 12);
|
|
399
|
+
for (let k = 1; k <= 12; k += 1) {
|
|
400
|
+
s.real[k] *= cal;
|
|
401
|
+
s.imag[k] *= cal;
|
|
402
|
+
}
|
|
403
|
+
return { mean: mean * cal, real: s.real, imag: s.imag };
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const waves = new WeakMap();
|
|
407
|
+
function cached(ctx, key, make) {
|
|
408
|
+
let set = waves.get(ctx);
|
|
409
|
+
if (!set) {
|
|
410
|
+
set = new Map();
|
|
411
|
+
waves.set(ctx, set);
|
|
412
|
+
}
|
|
413
|
+
let w = set.get(key);
|
|
414
|
+
if (!w) {
|
|
415
|
+
w = make();
|
|
416
|
+
set.set(key, w);
|
|
417
|
+
}
|
|
418
|
+
return w;
|
|
419
|
+
}
|
|
420
|
+
const srcKey = (t) => JSON.stringify([t.source, t.tilt, t.harmonics, t.taper, t.oq, t.sq, t.rd, t.srcGain]);
|
|
421
|
+
function sourceWave(ctx, tune) {
|
|
422
|
+
return cached(ctx, `src${srcKey(tune)}`, () => {
|
|
423
|
+
const s = sourceCoefficients(tune);
|
|
424
|
+
return ctx.createPeriodicWave(s.real, s.imag, { disableNormalization: true });
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
// The gate's wave carries its own amount (amt), so no extra gain node.
|
|
428
|
+
function gateWave(ctx, tune, amt) {
|
|
429
|
+
return cached(ctx, `gate${srcKey(tune)}/${amt}`, () => {
|
|
430
|
+
const s = breathGate(tune);
|
|
431
|
+
return { mean: s.mean, wave: ctx.createPeriodicWave(s.real.map((x) => x * amt), s.imag.map((x) => x * amt), { disableNormalization: true }) };
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// Three seconds of DC-free white noise per context, its loop seam
|
|
436
|
+
// cross-faded so the wrap is just more noise.
|
|
437
|
+
const noises = new WeakMap();
|
|
438
|
+
function noiseOf(ctx) {
|
|
439
|
+
let b = noises.get(ctx);
|
|
440
|
+
if (!b) {
|
|
441
|
+
const n = Math.floor(ctx.sampleRate * 3);
|
|
442
|
+
const fade = 2048;
|
|
443
|
+
b = ctx.createBuffer(1, n, ctx.sampleRate);
|
|
444
|
+
const d = b.getChannelData(0);
|
|
445
|
+
const next = seeded(0x51a1);
|
|
446
|
+
const raw = new Float32Array(n + fade);
|
|
447
|
+
let mean = 0;
|
|
448
|
+
for (let i = 0; i < raw.length; i += 1) {
|
|
449
|
+
raw[i] = next() * 2 - 1;
|
|
450
|
+
mean += raw[i];
|
|
451
|
+
}
|
|
452
|
+
mean /= raw.length;
|
|
453
|
+
for (let i = 0; i < n; i += 1) {
|
|
454
|
+
d[i] = raw[i] - mean;
|
|
455
|
+
}
|
|
456
|
+
for (let i = 0; i < fade; i += 1) {
|
|
457
|
+
const a = (i + 0.5) / fade;
|
|
458
|
+
d[i] = d[i] * Math.sin(a * Math.PI / 2) + (raw[n + i] - mean) * Math.cos(a * Math.PI / 2);
|
|
459
|
+
}
|
|
460
|
+
noises.set(ctx, b);
|
|
461
|
+
}
|
|
462
|
+
return b;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Breakpoint lists, emitted as linear ramps. pin(t) fixes the value a track
|
|
466
|
+
// has at t, so the next breakpoint ramps from t and never from a point
|
|
467
|
+
// before a pause (round 3's slow slides came from exactly that).
|
|
468
|
+
class Track {
|
|
469
|
+
constructor(value) {
|
|
470
|
+
this.points = [[0, value]];
|
|
471
|
+
}
|
|
472
|
+
at(t, v) {
|
|
473
|
+
this.points.push([t, v]);
|
|
474
|
+
}
|
|
475
|
+
sorted() {
|
|
476
|
+
return [...this.points].sort((a, b) => a[0] - b[0]);
|
|
477
|
+
}
|
|
478
|
+
valueAt(t) {
|
|
479
|
+
const pts = this.sorted();
|
|
480
|
+
let prev = pts[0];
|
|
481
|
+
for (const p of pts) {
|
|
482
|
+
if (p[0] <= t) {
|
|
483
|
+
prev = p;
|
|
484
|
+
} else {
|
|
485
|
+
return p[0] === prev[0] ? p[1] : prev[1] + (p[1] - prev[1]) * (t - prev[0]) / (p[0] - prev[0]);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return prev[1];
|
|
489
|
+
}
|
|
490
|
+
pin(t) {
|
|
491
|
+
this.at(t, this.valueAt(t));
|
|
492
|
+
}
|
|
493
|
+
apply(param, t0, duration) {
|
|
494
|
+
const pts = this.sorted().slice(1);
|
|
495
|
+
param.setValueAtTime(this.points[0][1], t0);
|
|
496
|
+
let last = t0;
|
|
497
|
+
for (const [t, v] of pts) {
|
|
498
|
+
if (last >= t0 + duration) { break; }
|
|
499
|
+
const at = Math.min(t0 + duration, Math.max(t0 + t, last + 0.001));
|
|
500
|
+
param.linearRampToValueAtTime(v, at);
|
|
501
|
+
last = at;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// The audition's tracks, bounded at complete pseudo-word ends. No nodes here.
|
|
507
|
+
export function babblePlan(text, voice = {}) {
|
|
508
|
+
const v = normaliseVoice(voice);
|
|
509
|
+
const { pitch, rate, pace, mouth, lift, expr } = v;
|
|
510
|
+
const tune = v.tune;
|
|
511
|
+
const ex1 = Math.min(expr, 1);
|
|
512
|
+
const spread = v.spread ?? 3 + 2 * expr;
|
|
513
|
+
const decl = 3.5 - 2 * ex1;
|
|
514
|
+
const sentences = [];
|
|
515
|
+
let count = 0;
|
|
516
|
+
for (const sentence of simlishWords(text, v.seed)) {
|
|
517
|
+
const words = [];
|
|
518
|
+
for (const word of sentence.words) {
|
|
519
|
+
if (count + word.sylls.length > BABBLE_MAX_SYLLABLES) { break; }
|
|
520
|
+
count += word.sylls.length;
|
|
521
|
+
words.push(word);
|
|
522
|
+
}
|
|
523
|
+
if (words.length) { sentences.push({ ...sentence, words }); }
|
|
524
|
+
if (words.length !== sentence.words.length || count >= BABBLE_MAX_SYLLABLES) { break; }
|
|
525
|
+
}
|
|
526
|
+
if (!sentences.length) { return null; }
|
|
527
|
+
const rnd = seeded(hashOf(text) ^ 0x5171 ^ (v.seed >>> 0));
|
|
528
|
+
// A second stream for round 5's additions, so expr 0 keeps round 4's plan.
|
|
529
|
+
const rnd2 = seeded(hashOf(text) ^ 0x9e37 ^ (v.seed >>> 0));
|
|
530
|
+
const vowelOf = (name) => (VOWELS[name] ?? VOWELS.a).map((f, i) => f * (i < 3 ? mouth : 0.5 + 0.5 * mouth));
|
|
531
|
+
// The local rate stays in 3-6 syllables a second (or around `rate` if
|
|
532
|
+
// that is outside it).
|
|
533
|
+
const rateLo = Math.min(3, rate * 0.85);
|
|
534
|
+
const rateHi = Math.max(6, rate * 1.15);
|
|
535
|
+
|
|
536
|
+
// Tracks, in seconds from startTime.
|
|
537
|
+
const P = new Track(pitch);
|
|
538
|
+
const VE = new Track(0);
|
|
539
|
+
const OPEN = tune.voiceTop;
|
|
540
|
+
const SL = new Track(OPEN);
|
|
541
|
+
const AS = new Track(0);
|
|
542
|
+
const FG = new Track(0);
|
|
543
|
+
const FB = new Track(4000);
|
|
544
|
+
const FQ = new Track(1);
|
|
545
|
+
const FH = new Track(2000);
|
|
546
|
+
const FL = new Track(9000);
|
|
547
|
+
const NG = new Track(0);
|
|
548
|
+
const NF = new Track(1400);
|
|
549
|
+
const first = sentences[0].words[0].sylls[0];
|
|
550
|
+
const firstV = vowelOf(DIPHTHONGS[first.nucleus]?.[0] ?? first.nucleus);
|
|
551
|
+
const F = [0, 1, 2, 3].map((i) => new Track(firstV[i]));
|
|
552
|
+
const ALL = [P, VE, SL, AS, FG, FB, FQ, FH, FL, NG, NF, ...F];
|
|
553
|
+
const formantsTo = (t, fs) => fs.forEach((f, i) => F[i].at(t, f));
|
|
554
|
+
|
|
555
|
+
function locus(c, fv) {
|
|
556
|
+
const [f1, f2, f3, f4] = fv;
|
|
557
|
+
switch (c) {
|
|
558
|
+
case 'l': return [380 * mouth, 1150 * mouth, 2850 * mouth, f4];
|
|
559
|
+
case 'r': return [420 * mouth, 1150 * mouth, 1700 * mouth, f4];
|
|
560
|
+
case 'w': return [310 * mouth, 760 * mouth, 2300 * mouth, f4];
|
|
561
|
+
case 'y': return [290 * mouth, 2250 * mouth, 3050 * mouth, f4];
|
|
562
|
+
case 'h': return fv;
|
|
563
|
+
default: break;
|
|
564
|
+
}
|
|
565
|
+
const place = PLACE[c];
|
|
566
|
+
const low = KIND[c] === 'fric' ? f1 * 0.8 : 270 * mouth;
|
|
567
|
+
if (place === 'lab') {
|
|
568
|
+
return [low, f2 * 0.62 + 300 * mouth, f3 * 0.9, f4];
|
|
569
|
+
}
|
|
570
|
+
if (place === 'alv') {
|
|
571
|
+
return [low, 1750 * mouth * 0.6 + f2 * 0.4, Math.max(f3, 2700 * mouth), f4];
|
|
572
|
+
}
|
|
573
|
+
if (place === 'post') {
|
|
574
|
+
return [low, 1900 * mouth * 0.6 + f2 * 0.4, Math.min(f3, 2450 * mouth), f4];
|
|
575
|
+
}
|
|
576
|
+
const pinch = Math.max(f2 * 1.08, 1450 * mouth);
|
|
577
|
+
return [low, pinch, Math.min(f3, pinch * 1.18), f4];
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function band(c, fv) {
|
|
581
|
+
switch (PLACE[c]) {
|
|
582
|
+
case 'lab': return c === 'f' ? [3600, 1.3, 1800, 7000] : [1100, 0.9, 500, 5000];
|
|
583
|
+
case 'alv': return c === 's' ? [6000, 2.2, 3800, 10000] : [4000, 1.6, 2500, 7500];
|
|
584
|
+
case 'post': return [2900, 2.4, 1900, 6000];
|
|
585
|
+
default: return [clamp(fv[1] * 1.15, 1500, 2900), 2.2, 900, 5000];
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
const setBand = (at, c, fv) => {
|
|
589
|
+
const [bf, bq, bh, top] = band(c, fv);
|
|
590
|
+
FB.at(at, bf);
|
|
591
|
+
FQ.at(at, bq);
|
|
592
|
+
FH.at(at, bh);
|
|
593
|
+
FL.at(at, top);
|
|
594
|
+
};
|
|
595
|
+
// A vowel's voice dying away: most of it in the first 40%, then to 0.
|
|
596
|
+
const release = (t0, from, rel) => {
|
|
597
|
+
VE.at(t0, from);
|
|
598
|
+
VE.at(t0 + rel * 0.4, from * 0.42);
|
|
599
|
+
VE.at(t0 + rel, 0);
|
|
600
|
+
};
|
|
601
|
+
// Does this onset stop the voice (so the vowel before it must release)?
|
|
602
|
+
const silencing = (c) => !c || KIND[c] === 'stop' || KIND[c] === 'fric' || KIND[c] === 'h';
|
|
603
|
+
const hz = (s) => pitch * 2 ** (s / 12);
|
|
604
|
+
|
|
605
|
+
let t = 0.005;
|
|
606
|
+
let pitchIndex = 0;
|
|
607
|
+
let tempo = 1;
|
|
608
|
+
const wordEnds = [];
|
|
609
|
+
const sylSpans = [];
|
|
610
|
+
let voiced = false; // is the voice sounding at t (a flowing join)?
|
|
611
|
+
let register = 0; // semitones; a new one for each phrase
|
|
612
|
+
for (let sn = 0; sn < sentences.length; sn += 1) {
|
|
613
|
+
const sentence = sentences[sn];
|
|
614
|
+
const words = sentence.words;
|
|
615
|
+
const sylCount = words.reduce((n, w) => n + w.sylls.length, 0);
|
|
616
|
+
let si = 0;
|
|
617
|
+
register = (rnd2() * 2 - 1) * 4 * expr;
|
|
618
|
+
for (let wi = 0; wi < words.length; wi += 1) {
|
|
619
|
+
const word = words[wi];
|
|
620
|
+
const accent = (rnd() * 0.8 + 0.2) * spread * (rnd() < 0.7 ? 1 : -0.4);
|
|
621
|
+
// Pace: a smoothed random walk per word, so a phrase speeds up and
|
|
622
|
+
// slows down; an occasional emphasised word.
|
|
623
|
+
const target = 2 ** ((rnd() * 2 - 1) * 0.34 * pace);
|
|
624
|
+
tempo = tempo * 0.4 + target * 0.6;
|
|
625
|
+
const emph = rnd() < 0.13 * pace && word.sylls.length <= 2;
|
|
626
|
+
for (let yi = 0; yi < word.sylls.length; yi += 1) {
|
|
627
|
+
const syl = word.sylls[yi];
|
|
628
|
+
const finalSyl = si === sylCount - 1;
|
|
629
|
+
const lastOfWord = yi === word.sylls.length - 1;
|
|
630
|
+
const stressed = yi === 0;
|
|
631
|
+
const phraseStart = !voiced && VE.valueAt(t) < 1e-4;
|
|
632
|
+
const parts = DIPHTHONGS[syl.nucleus] ?? [syl.nucleus];
|
|
633
|
+
const fv = vowelOf(parts[0]);
|
|
634
|
+
const fv2 = parts[1] ? vowelOf(parts[1]) : null;
|
|
635
|
+
const slowing = si >= sylCount - 2 ? 0.86 : 1;
|
|
636
|
+
const loc = clamp(rate * tempo * slowing, rateLo, rateHi);
|
|
637
|
+
const k = clamp(4.2 / loc, 0.72, 1.4);
|
|
638
|
+
const sylStart = t;
|
|
639
|
+
// Every track starts this syllable from where it is now.
|
|
640
|
+
for (const tr of ALL) {
|
|
641
|
+
tr.pin(t);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// Pitch: one note per syllable. Declination, a word accent, a hop,
|
|
645
|
+
// and the sentence's ending -- all as steps BETWEEN syllables.
|
|
646
|
+
const pos = sylCount > 1 ? si / (sylCount - 1) : 1;
|
|
647
|
+
// (the -2.7 st keeps the median where round 4's was, with the
|
|
648
|
+
// gentler declination and wider accents)
|
|
649
|
+
let semi = 2 - 2.7 * ex1 - decl * pos + register + (stressed ? accent : accent * 0.35) + (pitchIndex % 2 ? -1 : 1) * num(v.bounce, 0) * 0.5;
|
|
650
|
+
semi += (rnd2() * 2 - 1) * 3.5 * expr; // a hop between syllables
|
|
651
|
+
let drift = (rnd() - 0.6) * 0.4; // at most a fifth of a semitone up
|
|
652
|
+
// A glide inside the vowel: level, rise, fall or rise-fall, 1.4-5.4
|
|
653
|
+
// st (scaled by expr), over at most the vowel's first 120 ms.
|
|
654
|
+
const gr = rnd2();
|
|
655
|
+
let shape = gr < 0.25 ? 'level' : gr < 0.5 ? 'rise' : gr < 0.78 ? 'fall' : 'risefall';
|
|
656
|
+
let gst = (1.4 + rnd2() * 4) * expr;
|
|
657
|
+
if (sentence.mark === '?') {
|
|
658
|
+
if (si === sylCount - 2) {
|
|
659
|
+
semi += 1 * lift;
|
|
660
|
+
} else if (finalSyl) {
|
|
661
|
+
semi += (5 - ex1) * lift;
|
|
662
|
+
drift = 0;
|
|
663
|
+
shape = 'rise';
|
|
664
|
+
gst = Math.max(gst, 2.5 * expr) * lift;
|
|
665
|
+
}
|
|
666
|
+
} else if (sentence.mark === '!') {
|
|
667
|
+
semi += 2 * lift;
|
|
668
|
+
if (si === sylCount - 2) {
|
|
669
|
+
semi += 2.5 * lift;
|
|
670
|
+
} else if (finalSyl) {
|
|
671
|
+
semi += 0.5 * lift;
|
|
672
|
+
drift = -0.5;
|
|
673
|
+
shape = 'fall';
|
|
674
|
+
}
|
|
675
|
+
} else if (finalSyl) {
|
|
676
|
+
semi -= 2.5 * lift;
|
|
677
|
+
drift = -0.5;
|
|
678
|
+
shape = 'fall';
|
|
679
|
+
gst = Math.max(gst, 2 * expr);
|
|
680
|
+
} else if (si === sylCount - 2) {
|
|
681
|
+
semi -= 0.8 * lift;
|
|
682
|
+
}
|
|
683
|
+
if (emph && stressed) {
|
|
684
|
+
semi += 1.5;
|
|
685
|
+
}
|
|
686
|
+
pitchIndex += 1;
|
|
687
|
+
if (expr <= 0) {
|
|
688
|
+
shape = 'level';
|
|
689
|
+
}
|
|
690
|
+
// The glide's start and end, around the syllable's note.
|
|
691
|
+
const g0 = shape === 'rise' ? -gst / 2 : shape === 'fall' ? gst / 2 : shape === 'risefall' ? -gst / 3 : 0;
|
|
692
|
+
const note = hz(semi + g0);
|
|
693
|
+
P.at(t + 0.008, note);
|
|
694
|
+
const level = (stressed ? 1 : 0.82) * (sentence.mark === '!' ? 1.08 : 1) * (0.93 + rnd() * 0.14) * (emph && stressed ? 1.2 : 1);
|
|
695
|
+
|
|
696
|
+
// --- onset ---
|
|
697
|
+
const c = syl.onset;
|
|
698
|
+
const kind = c ? KIND[c] : null;
|
|
699
|
+
let tv = t;
|
|
700
|
+
const L = c ? locus(c, fv) : null;
|
|
701
|
+
let fromBar = false; // the vowel starts from a voice bar
|
|
702
|
+
if (!c) {
|
|
703
|
+
if (!phraseStart) {
|
|
704
|
+
// A vowel after a vowel: a glottal dip, never to silence.
|
|
705
|
+
VE.at(t + 0.02, level * 0.3);
|
|
706
|
+
tv = t + 0.03;
|
|
707
|
+
fromBar = true;
|
|
708
|
+
}
|
|
709
|
+
} else if (kind === 'stop') {
|
|
710
|
+
const vd = VOICED.has(c);
|
|
711
|
+
const closure = (phraseStart ? 0.03 : 0.045) * k;
|
|
712
|
+
const burst = Math.max(0.011, (PLACE[c] === "vel" ? 0.016 : PLACE[c] === "lab" ? 0.008 : 0.012) * k);
|
|
713
|
+
const vot = vd ? 0.006 : (PLACE[c] === 'vel' ? 0.03 : 0.024) * k;
|
|
714
|
+
const tb = t + closure;
|
|
715
|
+
if (vd) {
|
|
716
|
+
SL.at(t + 0.012, 420);
|
|
717
|
+
VE.at(t + 0.016, 0.12);
|
|
718
|
+
VE.at(tb - 0.002, 0.11);
|
|
719
|
+
fromBar = true;
|
|
720
|
+
} else {
|
|
721
|
+
VE.at(t + 0.012, 0);
|
|
722
|
+
}
|
|
723
|
+
formantsTo(t + closure * 0.6, L);
|
|
724
|
+
setBand(tb - 0.006, c, fv);
|
|
725
|
+
const bl = tune.burst * (vd ? 0.42 : 0.7) * (PLACE[c] === 'lab' ? 0.75 : 1);
|
|
726
|
+
// Aspiration: shorter and softer than round 4 (0.22 / 0.14).
|
|
727
|
+
FG.at(tb, 0);
|
|
728
|
+
FG.at(tb + 0.004, bl);
|
|
729
|
+
FG.at(tb + burst, bl * 0.3);
|
|
730
|
+
FG.at(tb + burst + 0.014, 0);
|
|
731
|
+
if (!vd) {
|
|
732
|
+
AS.at(tb + 0.004, 0);
|
|
733
|
+
AS.at(tb + 0.012, tune.asp * 0.16);
|
|
734
|
+
AS.at(tb + burst + vot - 0.004, tune.asp * 0.08);
|
|
735
|
+
AS.at(tb + burst + vot + 0.012, 0);
|
|
736
|
+
// the aspiration is the coming vowel whispered: kept under 5 kHz
|
|
737
|
+
SL.at(tb, 5000);
|
|
738
|
+
SL.at(tb + burst + vot, 5000);
|
|
739
|
+
SL.at(tb + burst + vot + 0.015, OPEN);
|
|
740
|
+
}
|
|
741
|
+
tv = tb + burst + vot;
|
|
742
|
+
|
|
743
|
+
if (vd) {
|
|
744
|
+
SL.at(tb, 420);
|
|
745
|
+
SL.at(tb + 0.01, OPEN);
|
|
746
|
+
}
|
|
747
|
+
formantsTo(tb, L);
|
|
748
|
+
F[0].at(tv, 260 * mouth);
|
|
749
|
+
} else if (kind === 'fric') {
|
|
750
|
+
// Swell and fade, about half round 4's length (0.075-0.088 * k,
|
|
751
|
+
// held flat), so it reads as a consonant, not a burst of hiss.
|
|
752
|
+
const d = (c === 'f' ? 0.048 : c === 'sh' ? 0.058 : 0.054) * k;
|
|
753
|
+
VE.at(t + 0.012, 0);
|
|
754
|
+
setBand(t, c, fv);
|
|
755
|
+
const fl = tune.fric * (c === 's' ? 0.52 : c === 'sh' ? 0.42 : 0.18);
|
|
756
|
+
FG.at(t, 0);
|
|
757
|
+
FG.at(t + d * 0.5, fl);
|
|
758
|
+
FG.at(t + d, fl * 0.3);
|
|
759
|
+
FG.at(t + d + 0.016, 0);
|
|
760
|
+
formantsTo(t + d * 0.5, L);
|
|
761
|
+
tv = t + d - 0.006;
|
|
762
|
+
|
|
763
|
+
} else if (kind === 'h') {
|
|
764
|
+
const d = 0.038 * k;
|
|
765
|
+
VE.at(t + 0.012, 0);
|
|
766
|
+
formantsTo(t + 0.02, fv);
|
|
767
|
+
AS.at(t + 0.018, tune.asp * 0.2);
|
|
768
|
+
AS.at(t + d, tune.asp * 0.12);
|
|
769
|
+
AS.at(t + d + 0.018, 0);
|
|
770
|
+
SL.at(t + 0.012, 4500);
|
|
771
|
+
SL.at(t + d, 4500);
|
|
772
|
+
SL.at(t + d + 0.015, OPEN);
|
|
773
|
+
tv = t + d - 0.004;
|
|
774
|
+
|
|
775
|
+
} else if (kind === 'nasal') {
|
|
776
|
+
const d = 0.062 * k;
|
|
777
|
+
SL.at(t + 0.018, 380);
|
|
778
|
+
NF.at(t, c === 'm' ? 1100 * mouth : 1700 * mouth);
|
|
779
|
+
NG.at(t + 0.018, -22);
|
|
780
|
+
VE.at(t + 0.02, 0.6 * level);
|
|
781
|
+
formantsTo(t + 0.018, L);
|
|
782
|
+
SL.at(t + d, 380);
|
|
783
|
+
SL.at(t + d + 0.016, OPEN);
|
|
784
|
+
NG.at(t + d, -22);
|
|
785
|
+
NG.at(t + d + 0.02, 0);
|
|
786
|
+
tv = t + d;
|
|
787
|
+
fromBar = true;
|
|
788
|
+
} else {
|
|
789
|
+
const d = 0.055 * k;
|
|
790
|
+
VE.at(t + 0.02, 0.62 * level);
|
|
791
|
+
formantsTo(t + 0.02, L);
|
|
792
|
+
formantsTo(t + d * 0.55, L);
|
|
793
|
+
tv = t + d;
|
|
794
|
+
fromBar = true;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// --- the vowel: its own length, not what a fixed slot leaves ---
|
|
798
|
+
const nextSyl = word.sylls[yi + 1] ?? words[wi + 1]?.sylls[0] ?? null;
|
|
799
|
+
const pauseAfter = lastOfWord && (word.pause > 0 || wi === words.length - 1);
|
|
800
|
+
let vd = (1 / loc) * tune.vowelShare * (stressed ? 1.1 : 0.9) * (0.88 + rnd() * 0.24);
|
|
801
|
+
if (emph && stressed) {
|
|
802
|
+
vd *= 1.35;
|
|
803
|
+
}
|
|
804
|
+
// Round 5: some syllables drawn out, the rest a touch shorter.
|
|
805
|
+
if (expr > 0) {
|
|
806
|
+
vd *= rnd2() < 0.3 * Math.min(expr, 1.5) ? 1.5 + rnd2() * 0.6 : 0.9;
|
|
807
|
+
}
|
|
808
|
+
if (fv2) {
|
|
809
|
+
vd *= 1.2;
|
|
810
|
+
}
|
|
811
|
+
if (finalSyl) {
|
|
812
|
+
vd *= 1.9;
|
|
813
|
+
} else if (pauseAfter) {
|
|
814
|
+
vd *= 1.3;
|
|
815
|
+
}
|
|
816
|
+
vd = Math.max(vd, finalSyl ? 0.2 : clamp(0.45 / loc, 0.072, 0.09));
|
|
817
|
+
const ve = tv + vd;
|
|
818
|
+
if (!fromBar) {
|
|
819
|
+
VE.at(tv, 0);
|
|
820
|
+
}
|
|
821
|
+
VE.at(tv + (fromBar ? 0.03 : 0.024), level);
|
|
822
|
+
VE.at(ve, level * 0.84);
|
|
823
|
+
const glide = kind === 'liquid' ? 0.065 : kind === 'nasal' ? 0.045 : 0.05;
|
|
824
|
+
formantsTo(tv + glide, fv);
|
|
825
|
+
if (fv2) {
|
|
826
|
+
formantsTo(tv + vd * 0.35, fv);
|
|
827
|
+
formantsTo(tv + vd * 0.9, fv2);
|
|
828
|
+
} else {
|
|
829
|
+
formantsTo(ve - 0.005, fv.map((f, i) => (i === 1 ? f * (0.97 + rnd() * 0.06) : f)));
|
|
830
|
+
}
|
|
831
|
+
// Pitch: round 4 held the note (a small drift only); round 5 glides
|
|
832
|
+
// inside the vowel, quickly, and holds the glide's end.
|
|
833
|
+
P.at(tv + 0.02, note);
|
|
834
|
+
let endNote = hz(semi + drift);
|
|
835
|
+
if (shape !== 'level') {
|
|
836
|
+
const span = Math.max(0.03, Math.min(vd * 0.7, 0.12, vd - 0.025));
|
|
837
|
+
if (shape === 'risefall') {
|
|
838
|
+
P.at(tv + 0.02 + span * 0.45, hz(semi + gst * 2 / 3));
|
|
839
|
+
endNote = hz(semi - gst / 3 + drift);
|
|
840
|
+
} else {
|
|
841
|
+
endNote = hz(semi - g0 + drift * 0.5);
|
|
842
|
+
}
|
|
843
|
+
P.at(tv + 0.02 + span, endNote);
|
|
844
|
+
}
|
|
845
|
+
P.at(ve, endNote);
|
|
846
|
+
|
|
847
|
+
// --- coda; every vowel finishes its release first ---
|
|
848
|
+
const cc = syl.coda;
|
|
849
|
+
const ckind = cc ? KIND[cc] : null;
|
|
850
|
+
const relFinal = finalSyl ? 0.16 : pauseAfter ? 0.1 : lastOfWord ? 0.06 : 0.045;
|
|
851
|
+
let tEnd = ve;
|
|
852
|
+
voiced = false;
|
|
853
|
+
if (!cc) {
|
|
854
|
+
const flows = !pauseAfter && nextSyl && !silencing(nextSyl.onset);
|
|
855
|
+
const glottal = !pauseAfter && nextSyl && !nextSyl.onset && !lastOfWord;
|
|
856
|
+
if (flows || glottal) {
|
|
857
|
+
voiced = true;
|
|
858
|
+
} else {
|
|
859
|
+
release(ve, level * 0.84, relFinal);
|
|
860
|
+
tEnd = ve + relFinal;
|
|
861
|
+
}
|
|
862
|
+
} else {
|
|
863
|
+
const fEnd = fv2 ?? fv;
|
|
864
|
+
const Lc = locus(cc, fEnd);
|
|
865
|
+
if (ckind === 'stop') {
|
|
866
|
+
const vdc = VOICED.has(cc);
|
|
867
|
+
const closure = Math.max(0.045 * k, 0.04) * (finalSyl ? 1.3 : 1);
|
|
868
|
+
formantsTo(ve + 0.025, Lc);
|
|
869
|
+
if (vdc) {
|
|
870
|
+
SL.at(ve, OPEN);
|
|
871
|
+
SL.at(ve + 0.022, 420);
|
|
872
|
+
VE.at(ve + 0.024, 0.1);
|
|
873
|
+
VE.at(ve + closure - 0.004, 0.08);
|
|
874
|
+
VE.at(ve + closure + 0.012, 0);
|
|
875
|
+
SL.at(ve + closure + 0.012, 420);
|
|
876
|
+
SL.at(ve + closure + 0.026, OPEN);
|
|
877
|
+
} else {
|
|
878
|
+
release(ve, level * 0.84, 0.032);
|
|
879
|
+
}
|
|
880
|
+
const tb = ve + closure;
|
|
881
|
+
setBand(tb - 0.006, cc, fEnd);
|
|
882
|
+
FG.at(tb, 0);
|
|
883
|
+
FG.at(tb + 0.004, tune.burst * (vdc ? 0.22 : 0.34));
|
|
884
|
+
FG.at(tb + 0.012, tune.burst * 0.1);
|
|
885
|
+
FG.at(tb + 0.03, 0);
|
|
886
|
+
tEnd = tb + 0.03;
|
|
887
|
+
|
|
888
|
+
} else if (ckind === 'fric') {
|
|
889
|
+
const d = 0.052 * k * (finalSyl ? 1.3 : 1);
|
|
890
|
+
setBand(ve - 0.012, cc, fEnd);
|
|
891
|
+
release(ve, level * 0.84, 0.04);
|
|
892
|
+
const fl = tune.fric * (cc === 's' ? 0.48 : cc === 'sh' ? 0.38 : 0.16);
|
|
893
|
+
FG.at(ve - 0.01, 0);
|
|
894
|
+
FG.at(ve + d * 0.45, fl);
|
|
895
|
+
FG.at(ve + d, fl * 0.3);
|
|
896
|
+
FG.at(ve + d + 0.016, 0);
|
|
897
|
+
formantsTo(ve + 0.024, Lc);
|
|
898
|
+
tEnd = ve + d + 0.016;
|
|
899
|
+
|
|
900
|
+
} else {
|
|
901
|
+
const d = 0.055 * k * (finalSyl ? 1.5 : 1);
|
|
902
|
+
if (ckind === 'nasal') {
|
|
903
|
+
NF.at(ve, cc === 'm' ? 1100 * mouth : 1700 * mouth);
|
|
904
|
+
formantsTo(ve + 0.03, Lc);
|
|
905
|
+
SL.at(ve, OPEN);
|
|
906
|
+
SL.at(ve + 0.018, 380);
|
|
907
|
+
NG.at(ve, 0);
|
|
908
|
+
NG.at(ve + 0.018, -22);
|
|
909
|
+
VE.at(ve + 0.02, 0.55 * level);
|
|
910
|
+
VE.at(ve + d, 0.45 * level);
|
|
911
|
+
} else {
|
|
912
|
+
formantsTo(ve + d * 0.7, Lc);
|
|
913
|
+
VE.at(ve + d * 0.7, 0.6 * level);
|
|
914
|
+
VE.at(ve + d, 0.55 * level);
|
|
915
|
+
}
|
|
916
|
+
tEnd = ve + d;
|
|
917
|
+
const flows = !pauseAfter && nextSyl && !silencing(nextSyl.onset);
|
|
918
|
+
if (flows) {
|
|
919
|
+
voiced = true;
|
|
920
|
+
} else {
|
|
921
|
+
const from = (ckind === 'nasal' ? 0.45 : 0.55) * level;
|
|
922
|
+
release(tEnd, from, relFinal);
|
|
923
|
+
tEnd += relFinal;
|
|
924
|
+
}
|
|
925
|
+
if (ckind === 'nasal') {
|
|
926
|
+
NG.at(tEnd, -22);
|
|
927
|
+
NG.at(tEnd + 0.02, 0);
|
|
928
|
+
SL.at(tEnd, 380);
|
|
929
|
+
SL.at(tEnd + 0.02, OPEN);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
P.at(tEnd, endNote);
|
|
934
|
+
sylSpans.push([sylStart, tEnd]);
|
|
935
|
+
|
|
936
|
+
// --- the gap after a word: varied, sometimes none, sometimes a
|
|
937
|
+
// hesitation; commas and full stops vary too ---
|
|
938
|
+
if (lastOfWord) {
|
|
939
|
+
wordEnds.push({ t: tEnd, syllables: sylSpans.length });
|
|
940
|
+
let gap = 0;
|
|
941
|
+
if (word.pause) {
|
|
942
|
+
gap = word.pause * (0.8 + rnd() * 0.5 * Math.max(pace, 0.3)) + (rnd() < 0.25 * pace ? 0.12 : 0);
|
|
943
|
+
register = (rnd2() * 2 - 1) * 4 * expr; // a new phrase
|
|
944
|
+
} else if (wi < words.length - 1) {
|
|
945
|
+
const roll = rnd();
|
|
946
|
+
const mul = roll < 0.3 ? 0.25 : roll < 0.72 ? 1 : roll < 0.9 ? 2.2 : 3.6;
|
|
947
|
+
gap = num(v.wordGap, 0.045) * k * (1 + (mul - 1) * Math.min(pace, 1.6));
|
|
948
|
+
if (rnd() < 0.08 * pace && wi > 0) {
|
|
949
|
+
gap += 0.2 + rnd() * 0.22;
|
|
950
|
+
}
|
|
951
|
+
if (voiced && gap > 0.03) {
|
|
952
|
+
// A real gap: the voice lets go first.
|
|
953
|
+
const from = VE.valueAt(tEnd);
|
|
954
|
+
release(tEnd, from, 0.05);
|
|
955
|
+
tEnd += 0.05;
|
|
956
|
+
voiced = false;
|
|
957
|
+
P.at(tEnd, endNote);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
t = tEnd + gap;
|
|
961
|
+
} else {
|
|
962
|
+
t = tEnd;
|
|
963
|
+
}
|
|
964
|
+
si += 1;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
if (sn < sentences.length - 1) {
|
|
968
|
+
const gap = 0.36 * (0.85 + rnd() * 0.5 * Math.max(pace, 0.3));
|
|
969
|
+
t += gap;
|
|
970
|
+
}
|
|
971
|
+
voiced = false;
|
|
972
|
+
}
|
|
973
|
+
// Vibrato, written into the pitch track four points a cycle (round 4 ran
|
|
974
|
+
// an oscillator and a gain for it; those two nodes now go to the breath).
|
|
975
|
+
const vibCents = num(v.vibrato, 9);
|
|
976
|
+
if (vibCents > 0) {
|
|
977
|
+
const base = P.sorted();
|
|
978
|
+
let j = 0;
|
|
979
|
+
for (let tg = 0.02; tg < t; tg += 1 / (5.4 * 4)) {
|
|
980
|
+
while (j + 1 < base.length && base[j + 1][0] <= tg) {
|
|
981
|
+
j += 1;
|
|
982
|
+
}
|
|
983
|
+
const a = base[j];
|
|
984
|
+
const b = base[j + 1] ?? a;
|
|
985
|
+
const f = b[0] > a[0] ? a[1] + (b[1] - a[1]) * (tg - a[0]) / (b[0] - a[0]) : a[1];
|
|
986
|
+
P.at(tg, f * 2 ** (vibCents * Math.sin(2 * Math.PI * 5.4 * tg) / 1200));
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
// Leave the audition's 50 ms tail inside the hard three-second cap.
|
|
990
|
+
const boundary = wordEnds.filter((w) => w.t <= BABBLE_MAX_S - 0.05).at(-1);
|
|
991
|
+
if (!boundary) { return null; }
|
|
992
|
+
const truncated = t > BABBLE_MAX_S - 0.05;
|
|
993
|
+
const duration = truncated ? boundary.t : t;
|
|
994
|
+
for (const track of truncated ? ALL : []) {
|
|
995
|
+
const value = track.valueAt(duration);
|
|
996
|
+
track.points = track.points.filter(([at]) => at <= duration);
|
|
997
|
+
track.at(duration, value);
|
|
998
|
+
}
|
|
999
|
+
return {
|
|
1000
|
+
duration, truncated, syllables: sylSpans.slice(0, boundary.syllables),
|
|
1001
|
+
wordEnds: wordEnds.filter((w) => w.t <= duration),
|
|
1002
|
+
tracks: { P, VE, SL, AS, FG, FB, FQ, FH, FL, NG, NF, F },
|
|
1003
|
+
noiseOffset: rnd() * 2.5,
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// Only synthesis parameters and trusted type tunes are accepted; arbitrary
|
|
1008
|
+
// audition taps/tune overrides cannot bypass the line gain.
|
|
1009
|
+
function normaliseVoice(voice) {
|
|
1010
|
+
const type = typeof voice?.type === 'string' && Object.hasOwn(VOICE_TYPES, voice.type) ? voice.type : 'townsfolk';
|
|
1011
|
+
const v = { ...VOICE_DEFAULTS, ...VOICE_TYPES[type], ...(voice && typeof voice === 'object' ? voice : {}) };
|
|
1012
|
+
const ranges = {
|
|
1013
|
+
pitch: [80, 500], rate: [2.5, 6], pace: [0, 2.5], mouth: [0.8, 1.35],
|
|
1014
|
+
expr: [0, 2], breath: [0, 4], jitter: [0, 4], lift: [0, 2],
|
|
1015
|
+
bounce: [0, 12], vibrato: [0, 100], wordGap: [0, 0.3], level: [0, 1],
|
|
1016
|
+
};
|
|
1017
|
+
for (const [key, [lo, hi]] of Object.entries(ranges)) {
|
|
1018
|
+
v[key] = clamp(num(v[key], VOICE_DEFAULTS[key]), lo, hi);
|
|
1019
|
+
}
|
|
1020
|
+
v.spread = v.spread === null ? null : clamp(num(v.spread, 3 + 2 * v.expr), 0, 12);
|
|
1021
|
+
v.seed = num(v.seed, 0) >>> 0;
|
|
1022
|
+
v.tune = { ...TUNE, ...VOICE_TYPES[type].tune };
|
|
1023
|
+
return v;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
export function simlish(context, destination, text, startTime, voice = {}, onEnd = () => {}) {
|
|
1027
|
+
const ctx = context;
|
|
1028
|
+
if (!Number.isFinite(startTime) || startTime < 0 || !Number.isFinite(ctx.currentTime)) { return null; }
|
|
1029
|
+
const v = normaliseVoice(voice);
|
|
1030
|
+
const plan = babblePlan(text, v);
|
|
1031
|
+
if (!plan) { return null; }
|
|
1032
|
+
const { P, VE, SL, AS, FG, FB, FQ, FH, FL, NG, NF, F } = plan.tracks;
|
|
1033
|
+
const tune = v.tune;
|
|
1034
|
+
if (!Number.isFinite(startTime + plan.duration + 0.05)) { return null; }
|
|
1035
|
+
const nodes = [];
|
|
1036
|
+
const sources = [];
|
|
1037
|
+
const made = (node, source = false) => {
|
|
1038
|
+
nodes.push(node);
|
|
1039
|
+
if (source) { sources.push(node); }
|
|
1040
|
+
return node;
|
|
1041
|
+
};
|
|
1042
|
+
let released = false;
|
|
1043
|
+
const release = () => {
|
|
1044
|
+
if (released) { return; }
|
|
1045
|
+
released = true;
|
|
1046
|
+
for (const node of sources) {
|
|
1047
|
+
node.onended = null;
|
|
1048
|
+
try { node.stop(); } catch { /* Already stopped, or never started. */ }
|
|
1049
|
+
}
|
|
1050
|
+
for (const node of nodes) {
|
|
1051
|
+
try { node.disconnect(); } catch { /* Already out. */ }
|
|
1052
|
+
}
|
|
1053
|
+
onEnd();
|
|
1054
|
+
};
|
|
1055
|
+
try {
|
|
1056
|
+
// --- the graph ---
|
|
1057
|
+
const src = made(ctx.createOscillator(), true);
|
|
1058
|
+
src.setPeriodicWave(sourceWave(ctx, tune));
|
|
1059
|
+
const murmur = made(ctx.createBiquadFilter());
|
|
1060
|
+
murmur.type = 'lowpass';
|
|
1061
|
+
murmur.Q.value = 0;
|
|
1062
|
+
const voiceEnv = made(ctx.createGain());
|
|
1063
|
+
src.connect(voiceEnv);
|
|
1064
|
+
voiceEnv.connect(murmur);
|
|
1065
|
+
// Breath: the noise, darkened, rides the voice envelope through the
|
|
1066
|
+
// formants (a flat breath noise would put hiss above every vowel).
|
|
1067
|
+
const breathLp = made(ctx.createBiquadFilter());
|
|
1068
|
+
breathLp.type = 'lowpass';
|
|
1069
|
+
breathLp.frequency.value = tune.breathHz;
|
|
1070
|
+
breathLp.Q.value = 0.5;
|
|
1071
|
+
const breath = made(ctx.createGain());
|
|
1072
|
+
const breathAmt = tune.breath * clamp(num(v.breath, 1), 0, 4);
|
|
1073
|
+
breathLp.connect(breath);
|
|
1074
|
+
breath.connect(voiceEnv);
|
|
1075
|
+
// Round 6: the breath is gated by the glottal flow (a second oscillator
|
|
1076
|
+
// on the same pitch track and jitter, playing the flow's shape into the
|
|
1077
|
+
// breath gain), so it puffs with each cycle. breathGate 0 = round 5's
|
|
1078
|
+
// steady breath.
|
|
1079
|
+
const gateDepth = tune.source === 'buzz' ? 0 : clamp(num(tune.breathGate, 1), 0, 1);
|
|
1080
|
+
let gate = null;
|
|
1081
|
+
if (gateDepth > 0 && breathAmt > 0) {
|
|
1082
|
+
const gw = gateWave(ctx, tune, breathAmt * gateDepth);
|
|
1083
|
+
gate = made(ctx.createOscillator(), true);
|
|
1084
|
+
gate.setPeriodicWave(gw.wave);
|
|
1085
|
+
gate.connect(breath.gain);
|
|
1086
|
+
breath.gain.value = breathAmt * (1 - gateDepth + gateDepth * gw.mean);
|
|
1087
|
+
} else {
|
|
1088
|
+
breath.gain.value = breathAmt;
|
|
1089
|
+
}
|
|
1090
|
+
// Jitter: the noise, kept below about f0, wobbles the buzz's pitch a
|
|
1091
|
+
// little from cycle to cycle (cents).
|
|
1092
|
+
const jitLp = made(ctx.createBiquadFilter());
|
|
1093
|
+
jitLp.type = 'lowpass';
|
|
1094
|
+
jitLp.frequency.value = tune.jitterHz;
|
|
1095
|
+
jitLp.Q.value = 0;
|
|
1096
|
+
const jit = made(ctx.createGain());
|
|
1097
|
+
jit.gain.value = tune.jitter * clamp(num(v.jitter, 1), 0, 4);
|
|
1098
|
+
jitLp.connect(jit);
|
|
1099
|
+
jit.connect(src.detune);
|
|
1100
|
+
if (gate) { jit.connect(gate.detune); }
|
|
1101
|
+
const formants = tune.formantQ.map((q, i) => {
|
|
1102
|
+
const f = made(ctx.createBiquadFilter());
|
|
1103
|
+
f.type = 'peaking';
|
|
1104
|
+
f.Q.value = q;
|
|
1105
|
+
f.gain.value = tune.formantDb[i];
|
|
1106
|
+
return f;
|
|
1107
|
+
});
|
|
1108
|
+
murmur.connect(formants[0]);
|
|
1109
|
+
for (let i = 0; i < 3; i += 1) {
|
|
1110
|
+
formants[i].connect(formants[i + 1]);
|
|
1111
|
+
}
|
|
1112
|
+
const notch = made(ctx.createBiquadFilter());
|
|
1113
|
+
notch.type = 'peaking';
|
|
1114
|
+
notch.Q.value = 2.5;
|
|
1115
|
+
formants[3].connect(notch);
|
|
1116
|
+
const shelf = made(ctx.createBiquadFilter());
|
|
1117
|
+
shelf.type = 'highshelf';
|
|
1118
|
+
shelf.frequency.value = tune.shelfHz;
|
|
1119
|
+
shelf.gain.value = tune.shelfDb;
|
|
1120
|
+
notch.connect(shelf);
|
|
1121
|
+
const out = made(ctx.createGain());
|
|
1122
|
+
// Headroom: the formant boosts stack (round 3 peaked at +7..+10 dBFS at
|
|
1123
|
+
// level 0.5); `gain` brings a line's peak under -3 dBFS at that level.
|
|
1124
|
+
out.gain.value = v.level * tune.gain;
|
|
1125
|
+
shelf.connect(out);
|
|
1126
|
+
const hp = made(ctx.createBiquadFilter());
|
|
1127
|
+
hp.type = 'highpass';
|
|
1128
|
+
hp.frequency.value = 70;
|
|
1129
|
+
hp.Q.value = 0.5;
|
|
1130
|
+
out.connect(hp);
|
|
1131
|
+
hp.connect(destination);
|
|
1132
|
+
const hiss = made(ctx.createBufferSource(), true);
|
|
1133
|
+
hiss.buffer = noiseOf(ctx);
|
|
1134
|
+
hiss.loop = true;
|
|
1135
|
+
hiss.connect(breathLp);
|
|
1136
|
+
hiss.connect(jitLp);
|
|
1137
|
+
const asp = made(ctx.createGain());
|
|
1138
|
+
hiss.connect(asp);
|
|
1139
|
+
asp.connect(murmur);
|
|
1140
|
+
const fricBand = made(ctx.createBiquadFilter());
|
|
1141
|
+
fricBand.type = 'bandpass';
|
|
1142
|
+
const fricHigh = made(ctx.createBiquadFilter());
|
|
1143
|
+
fricHigh.type = 'highpass';
|
|
1144
|
+
fricHigh.Q.value = 0.5;
|
|
1145
|
+
const fricTop = made(ctx.createBiquadFilter());
|
|
1146
|
+
fricTop.type = 'lowpass';
|
|
1147
|
+
fricTop.Q.value = 0.5;
|
|
1148
|
+
const fric = made(ctx.createGain());
|
|
1149
|
+
hiss.connect(fricBand);
|
|
1150
|
+
fricBand.connect(fricHigh);
|
|
1151
|
+
fricHigh.connect(fricTop);
|
|
1152
|
+
fricTop.connect(fric);
|
|
1153
|
+
// The noise path is not boosted by the formants, so it keeps its own
|
|
1154
|
+
// scale against the voice's headroom.
|
|
1155
|
+
fric.connect(out);
|
|
1156
|
+
|
|
1157
|
+
// Planning, graph construction and the first cached noise buffer can
|
|
1158
|
+
// consume the caller's lead on a slow device. Shift every event together
|
|
1159
|
+
// only after that work, leaving a small lead for automation and starts.
|
|
1160
|
+
startTime = Math.max(startTime, ctx.currentTime + 0.01);
|
|
1161
|
+
const end = startTime + plan.duration + 0.05;
|
|
1162
|
+
if (!Number.isFinite(end)) { release(); return null; }
|
|
1163
|
+
// The complete last word is followed by a short fade, never a fourth second.
|
|
1164
|
+
out.gain.setValueAtTime(out.gain.value, startTime + plan.duration);
|
|
1165
|
+
out.gain.linearRampToValueAtTime(0, end);
|
|
1166
|
+
|
|
1167
|
+
P.apply(src.frequency, startTime, plan.duration + 0.05);
|
|
1168
|
+
if (gate) { P.apply(gate.frequency, startTime, plan.duration + 0.05); }
|
|
1169
|
+
VE.apply(voiceEnv.gain, startTime, plan.duration + 0.05);
|
|
1170
|
+
SL.apply(murmur.frequency, startTime, plan.duration + 0.05);
|
|
1171
|
+
AS.apply(asp.gain, startTime, plan.duration + 0.05);
|
|
1172
|
+
FG.apply(fric.gain, startTime, plan.duration + 0.05);
|
|
1173
|
+
FB.apply(fricBand.frequency, startTime, plan.duration + 0.05);
|
|
1174
|
+
FQ.apply(fricBand.Q, startTime, plan.duration + 0.05);
|
|
1175
|
+
FH.apply(fricHigh.frequency, startTime, plan.duration + 0.05);
|
|
1176
|
+
FL.apply(fricTop.frequency, startTime, plan.duration + 0.05);
|
|
1177
|
+
NG.apply(notch.gain, startTime, plan.duration + 0.05);
|
|
1178
|
+
NF.apply(notch.frequency, startTime, plan.duration + 0.05);
|
|
1179
|
+
F.forEach((tr, i) => tr.apply(formants[i].frequency, startTime, plan.duration + 0.05));
|
|
1180
|
+
|
|
1181
|
+
for (const source of sources) { source.onended = release; }
|
|
1182
|
+
for (const source of gate ? [src, gate] : [src]) {
|
|
1183
|
+
source.start(startTime);
|
|
1184
|
+
source.stop(end);
|
|
1185
|
+
}
|
|
1186
|
+
hiss.start(startTime, plan.noiseOffset);
|
|
1187
|
+
hiss.stop(end);
|
|
1188
|
+
let stopped = false;
|
|
1189
|
+
return {
|
|
1190
|
+
end,
|
|
1191
|
+
nodes: nodes.length,
|
|
1192
|
+
stop(at = ctx.currentTime) {
|
|
1193
|
+
if (released || stopped) { return; }
|
|
1194
|
+
stopped = true;
|
|
1195
|
+
const now = Number.isFinite(ctx.currentTime) ? ctx.currentTime : 0;
|
|
1196
|
+
const t = Math.min(end, Math.max(now, num(at, now)));
|
|
1197
|
+
try {
|
|
1198
|
+
out.gain.cancelScheduledValues(t);
|
|
1199
|
+
out.gain.setValueAtTime(v.level * tune.gain * clamp((end - t) / 0.05, 0, 1), t);
|
|
1200
|
+
out.gain.linearRampToValueAtTime(0, Math.min(end, t + 0.02));
|
|
1201
|
+
for (const source of sources) { source.stop(Math.min(end, t + 0.03)); }
|
|
1202
|
+
} catch { release(); }
|
|
1203
|
+
},
|
|
1204
|
+
};
|
|
1205
|
+
} catch (err) {
|
|
1206
|
+
release();
|
|
1207
|
+
throw err;
|
|
1208
|
+
}
|
|
1209
|
+
}
|