@adminide-stack/clock-tik-mobile 0.0.0-stage → 12.0.37-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-flow/data/pending-insights.jsonl +43 -0
- package/.claude-flow/sessions/session-1794323376548.json +14 -0
- package/CHANGELOG.md +41 -0
- package/jest.config.cjs +22 -0
- package/lib/assets/home/loop-day.jpg +0 -0
- package/lib/assets/home/loop-day.mp4 +0 -0
- package/lib/assets/home/loop-time-back.jpg +0 -0
- package/lib/assets/home/loop-time-back.mp4 +0 -0
- package/lib/assets/home/loop-where.jpg +0 -0
- package/lib/assets/home/loop-where.mp4 +0 -0
- package/lib/assets/home/reel-gym.jpg +0 -0
- package/lib/assets/home/reel-gym.mp4 +0 -0
- package/lib/assets/home/reel-internet.jpg +0 -0
- package/lib/assets/home/reel-internet.mp4 +0 -0
- package/lib/assets/icon.png +0 -0
- package/lib/assets/lottie/.claude-flow/data/pending-insights.jsonl +1 -0
- package/lib/assets/lottie/lucy-mark-calendar.json +1827 -0
- package/lib/assets/lottie/lucy-mark-call.json +1470 -0
- package/lib/assets/lottie/lucy-mark-connect.json +2552 -0
- package/lib/assets/lottie/lucy-mark-details.json +1735 -0
- package/lib/assets/lottie/lucy-mark-email.json +1363 -0
- package/lib/assets/lottie/lucy-mark-message.json +1154 -0
- package/lib/assets/lottie/lucy-mark-search.json +1067 -0
- package/lib/assets/lottie/lucy-mark-think.json +1253 -0
- package/lib/assets/lottie/lucy-mark-write.json +1532 -0
- package/lib/assets/lottie/time-back.json +16458 -0
- package/lib/assets/lottie/where-lucy-works-chat.json +6170 -0
- package/lib/assets/lottie/where-lucy-works-cloud.json +10066 -0
- package/lib/assets/lottie/where-lucy-works-mine-none.json +2478 -0
- package/lib/assets/lottie/where-lucy-works-mine-offline.json +2373 -0
- package/lib/assets/lottie/where-lucy-works-mine-online.json +7881 -0
- package/lib/assets/sounds/hours-back.m4a +0 -0
- package/lib/assets/sounds/meet-lucy.m4a +0 -0
- package/lib/assets/sounds/power-on.m4a +0 -0
- package/lib/assets/sounds/wind-back.m4a +0 -0
- package/lib/assets/sounds/youre-in.m4a +0 -0
- package/lib/chat/agent.js +358 -0
- package/lib/chat/agent.js.map +1 -0
- package/lib/chat/appFront.js +32 -0
- package/lib/chat/appFront.js.map +1 -0
- package/lib/chat/auth.js +370 -0
- package/lib/chat/auth.js.map +1 -0
- package/lib/chat/chores.js +360 -0
- package/lib/chat/chores.js.map +1 -0
- package/lib/chat/connectors.js +45 -0
- package/lib/chat/connectors.js.map +1 -0
- package/lib/chat/jobs.js +223 -0
- package/lib/chat/jobs.js.map +1 -0
- package/lib/chat/lucyMotion.js +6 -0
- package/lib/chat/lucyMotion.js.map +1 -0
- package/lib/chat/protocol.js +111 -0
- package/lib/chat/protocol.js.map +1 -0
- package/lib/chat/results.js +133 -0
- package/lib/chat/results.js.map +1 -0
- package/lib/chat/store.js +81 -0
- package/lib/chat/store.js.map +1 -0
- package/lib/chat/useDictation.js +168 -0
- package/lib/chat/useDictation.js.map +1 -0
- package/lib/chat/useLucyChat.js +451 -0
- package/lib/chat/useLucyChat.js.map +1 -0
- package/lib/chat/useMyComputer.js +32 -0
- package/lib/chat/useMyComputer.js.map +1 -0
- package/lib/chat/whereLucyWorks.js +52 -0
- package/lib/chat/whereLucyWorks.js.map +1 -0
- package/lib/chat/workspace.js +124 -0
- package/lib/chat/workspace.js.map +1 -0
- package/lib/components/AreaShot.js +289 -0
- package/lib/components/AreaShot.js.map +1 -0
- package/lib/components/Backdrops.js +262 -0
- package/lib/components/Backdrops.js.map +1 -0
- package/lib/components/BottomSheet.js +61 -0
- package/lib/components/BottomSheet.js.map +1 -0
- package/lib/components/ChatSheets.js +429 -0
- package/lib/components/ChatSheets.js.map +1 -0
- package/lib/components/ConnectorLogo.js +91 -0
- package/lib/components/ConnectorLogo.js.map +1 -0
- package/lib/components/CustomDrawer.js +534 -0
- package/lib/components/CustomDrawer.js.map +1 -0
- package/lib/components/IdeasPane.js +394 -0
- package/lib/components/IdeasPane.js.map +1 -0
- package/lib/components/ImessageSheet.js +261 -0
- package/lib/components/ImessageSheet.js.map +1 -0
- package/lib/components/KeyboardAvoider.js +29 -0
- package/lib/components/KeyboardAvoider.js.map +1 -0
- package/lib/components/Logo.js +81 -0
- package/lib/components/Logo.js.map +1 -0
- package/lib/components/LucyWorking.js +67 -0
- package/lib/components/LucyWorking.js.map +1 -0
- package/lib/components/Markdown.js +260 -0
- package/lib/components/Markdown.js.map +1 -0
- package/lib/components/Media.js +93 -0
- package/lib/components/Media.js.map +1 -0
- package/lib/components/MessagesAppIcon.js +23 -0
- package/lib/components/MessagesAppIcon.js.map +1 -0
- package/lib/components/MicButton.js +71 -0
- package/lib/components/MicButton.js.map +1 -0
- package/lib/components/ResultCards.js +974 -0
- package/lib/components/ResultCards.js.map +1 -0
- package/lib/components/SignInPrompt.js +148 -0
- package/lib/components/SignInPrompt.js.map +1 -0
- package/lib/components/SignedOut.js +38 -0
- package/lib/components/SignedOut.js.map +1 -0
- package/lib/components/TalkToLucyHero.js +487 -0
- package/lib/components/TalkToLucyHero.js.map +1 -0
- package/lib/components/TalkToLucySheet.js +182 -0
- package/lib/components/TalkToLucySheet.js.map +1 -0
- package/lib/components/WhereLucyWorks.js +277 -0
- package/lib/components/WhereLucyWorks.js.map +1 -0
- package/lib/components/WorkspaceSection.js +271 -0
- package/lib/components/WorkspaceSection.js.map +1 -0
- package/lib/components/YantraMark.js +13 -0
- package/lib/components/YantraMark.js.map +1 -0
- package/lib/components/drawerHeader.js +38 -0
- package/lib/components/drawerHeader.js.map +1 -0
- package/lib/components/lottieInstalled.js +6 -0
- package/lib/components/lottieInstalled.js.map +1 -0
- package/lib/components/ui.js +550 -0
- package/lib/components/ui.js.map +1 -0
- package/lib/components/useSignOut.js +7 -0
- package/lib/components/useSignOut.js.map +1 -0
- package/lib/components/viewport.js +121 -0
- package/lib/components/viewport.js.map +1 -0
- package/lib/components/voiceDial.js +10 -0
- package/lib/components/voiceDial.js.map +1 -0
- package/lib/compute.js +157 -0
- package/lib/compute.js.map +1 -0
- package/lib/config/env-config.js +27 -0
- package/lib/config/env-config.js.map +1 -0
- package/lib/config/routes.js +15 -0
- package/lib/config/routes.js.map +1 -0
- package/lib/content.js +25 -0
- package/lib/content.js.map +1 -0
- package/lib/hooks/keyboardCover.js +39 -0
- package/lib/hooks/keyboardCover.js.map +1 -0
- package/lib/hooks/useKeyboard.js +121 -0
- package/lib/hooks/useKeyboard.js.map +1 -0
- package/lib/hooks/useReducedMotion.js +13 -0
- package/lib/hooks/useReducedMotion.js.map +1 -0
- package/lib/imessage/openMessages.js +25 -0
- package/lib/imessage/openMessages.js.map +1 -0
- package/lib/imessage/platform.js +12 -0
- package/lib/imessage/platform.js.map +1 -0
- package/lib/imessage/textLink.js +262 -0
- package/lib/imessage/textLink.js.map +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -0
- package/lib/live/card.js +28 -0
- package/lib/live/card.js.map +1 -0
- package/lib/live/liveActivity.js +144 -0
- package/lib/live/liveActivity.js.map +1 -0
- package/lib/module.js +3 -0
- package/lib/module.js.map +1 -0
- package/lib/offer/BlackFridayOffer.js +378 -0
- package/lib/offer/BlackFridayOffer.js.map +1 -0
- package/lib/offer/blackFriday.js +78 -0
- package/lib/offer/blackFriday.js.map +1 -0
- package/lib/offer/parts.js +624 -0
- package/lib/offer/parts.js.map +1 -0
- package/lib/offer/state.js +63 -0
- package/lib/offer/state.js.map +1 -0
- package/lib/push/push.js +142 -0
- package/lib/push/push.js.map +1 -0
- package/lib/push/usePushNotifications.js +39 -0
- package/lib/push/usePushNotifications.js.map +1 -0
- package/lib/routes.json +175 -0
- package/lib/screens/Account/index.js +209 -0
- package/lib/screens/Account/index.js.map +1 -0
- package/lib/screens/Chat/index.js +710 -0
- package/lib/screens/Chat/index.js.map +1 -0
- package/lib/screens/Chores/index.js +18 -0
- package/lib/screens/Chores/index.js.map +1 -0
- package/lib/screens/Connectors/index.js +17 -0
- package/lib/screens/Connectors/index.js.map +1 -0
- package/lib/screens/History/index.js +380 -0
- package/lib/screens/History/index.js.map +1 -0
- package/lib/screens/Home/index.js +2715 -0
- package/lib/screens/Home/index.js.map +1 -0
- package/lib/screens/Home/media.js +25 -0
- package/lib/screens/Home/media.js.map +1 -0
- package/lib/screens/Welcome/index.js +1066 -0
- package/lib/screens/Welcome/index.js.map +1 -0
- package/lib/talk/talkToLucy.js +139 -0
- package/lib/talk/talkToLucy.js.map +1 -0
- package/lib/theme/colors.js +29 -0
- package/lib/theme/colors.js.map +1 -0
- package/lib/theme/fonts.js +17 -0
- package/lib/theme/fonts.js.map +1 -0
- package/lib/theme/muse.js +134 -0
- package/lib/theme/muse.js.map +1 -0
- package/lib/utils/links.js +54 -0
- package/lib/utils/links.js.map +1 -0
- package/lib/utils/yantraLinks.js +68 -0
- package/lib/utils/yantraLinks.js.map +1 -0
- package/lib/welcome/flow.js +375 -0
- package/lib/welcome/flow.js.map +1 -0
- package/lib/welcome/haptics.js +125 -0
- package/lib/welcome/haptics.js.map +1 -0
- package/lib/welcome/parts.js +1996 -0
- package/lib/welcome/parts.js.map +1 -0
- package/lib/welcome/powerOn.js +29 -0
- package/lib/welcome/powerOn.js.map +1 -0
- package/lib/welcome/seen.js +41 -0
- package/lib/welcome/seen.js.map +1 -0
- package/lib/welcome/sound.js +110 -0
- package/lib/welcome/sound.js.map +1 -0
- package/package.json +66 -5
- package/rollup.config.mjs +42 -0
- package/src/.claude-flow/data/pending-insights.jsonl +19 -0
- package/src/.claude-flow/sessions/session-1795013028422.json +14 -0
- package/src/__tests__/auth.test.ts +94 -0
- package/src/__tests__/blackFriday.test.ts +75 -0
- package/src/__tests__/cardTokens.test.ts +77 -0
- package/src/__tests__/chores.test.ts +188 -0
- package/src/__tests__/choresList.test.ts +100 -0
- package/src/__tests__/connectLink.test.ts +21 -0
- package/src/__tests__/content.test.ts +54 -0
- package/src/__tests__/dictation.test.ts +186 -0
- package/src/__tests__/envConfig.test.ts +14 -0
- package/src/__tests__/haptics.test.ts +202 -0
- package/src/__tests__/jobs.test.ts +130 -0
- package/src/__tests__/keyboardCover.test.ts +84 -0
- package/src/__tests__/liveCard.test.ts +39 -0
- package/src/__tests__/lockedPhone.test.ts +355 -0
- package/src/__tests__/lucyMotion.test.ts +34 -0
- package/src/__tests__/platform.test.ts +32 -0
- package/src/__tests__/powerOn.test.ts +62 -0
- package/src/__tests__/protocol.test.ts +125 -0
- package/src/__tests__/push.test.ts +111 -0
- package/src/__tests__/results.test.ts +256 -0
- package/src/__tests__/sound.test.ts +248 -0
- package/src/__tests__/talkToLucy.test.ts +205 -0
- package/src/__tests__/textLink.test.ts +91 -0
- package/src/__tests__/voiceDial.test.ts +53 -0
- package/src/__tests__/welcomeFlow.test.ts +157 -0
- package/src/__tests__/whereLucyWorks.test.ts +81 -0
- package/src/__tests__/yantraLinks.test.ts +96 -0
- package/src/assets/home/loop-day.jpg +0 -0
- package/src/assets/home/loop-day.mp4 +0 -0
- package/src/assets/home/loop-time-back.jpg +0 -0
- package/src/assets/home/loop-time-back.mp4 +0 -0
- package/src/assets/home/loop-where.jpg +0 -0
- package/src/assets/home/loop-where.mp4 +0 -0
- package/src/assets/home/reel-gym.jpg +0 -0
- package/src/assets/home/reel-gym.mp4 +0 -0
- package/src/assets/home/reel-internet.jpg +0 -0
- package/src/assets/home/reel-internet.mp4 +0 -0
- package/src/assets/icon.png +0 -0
- package/src/assets/lottie/.claude-flow/data/pending-insights.jsonl +1 -0
- package/src/assets/lottie/lucy-mark-calendar.json +1827 -0
- package/src/assets/lottie/lucy-mark-call.json +1470 -0
- package/src/assets/lottie/lucy-mark-connect.json +2552 -0
- package/src/assets/lottie/lucy-mark-details.json +1735 -0
- package/src/assets/lottie/lucy-mark-email.json +1363 -0
- package/src/assets/lottie/lucy-mark-message.json +1154 -0
- package/src/assets/lottie/lucy-mark-search.json +1067 -0
- package/src/assets/lottie/lucy-mark-think.json +1253 -0
- package/src/assets/lottie/lucy-mark-write.json +1532 -0
- package/src/assets/lottie/time-back.json +16458 -0
- package/src/assets/lottie/where-lucy-works-chat.json +6170 -0
- package/src/assets/lottie/where-lucy-works-cloud.json +10066 -0
- package/src/assets/lottie/where-lucy-works-mine-none.json +2478 -0
- package/src/assets/lottie/where-lucy-works-mine-offline.json +2373 -0
- package/src/assets/lottie/where-lucy-works-mine-online.json +7881 -0
- package/src/assets/sounds/hours-back.m4a +0 -0
- package/src/assets/sounds/meet-lucy.m4a +0 -0
- package/src/assets/sounds/power-on.m4a +0 -0
- package/src/assets/sounds/wind-back.m4a +0 -0
- package/src/assets/sounds/youre-in.m4a +0 -0
- package/src/chat/.claude-flow/data/pending-insights.jsonl +1 -0
- package/src/chat/agent.ts +376 -0
- package/src/chat/appFront.ts +39 -0
- package/src/chat/auth.ts +433 -0
- package/src/chat/chores.ts +394 -0
- package/src/chat/connectors.ts +75 -0
- package/src/chat/jobs.ts +228 -0
- package/src/chat/lucyMotion.ts +33 -0
- package/src/chat/protocol.ts +192 -0
- package/src/chat/results.ts +224 -0
- package/src/chat/store.ts +87 -0
- package/src/chat/useDictation.ts +201 -0
- package/src/chat/useLucyChat.ts +458 -0
- package/src/chat/useMyComputer.ts +41 -0
- package/src/chat/whereLucyWorks.ts +97 -0
- package/src/chat/workspace.ts +127 -0
- package/src/components/.claude-flow/data/pending-insights.jsonl +3 -0
- package/src/components/AreaShot.tsx +239 -0
- package/src/components/Backdrops.tsx +323 -0
- package/src/components/BottomSheet.tsx +96 -0
- package/src/components/ChatSheets.tsx +565 -0
- package/src/components/ConnectorLogo.tsx +116 -0
- package/src/components/CustomDrawer.tsx +526 -0
- package/src/components/IdeasPane.tsx +318 -0
- package/src/components/ImessageSheet.tsx +280 -0
- package/src/components/KeyboardAvoider.tsx +45 -0
- package/src/components/Logo.tsx +97 -0
- package/src/components/LucyWorking.tsx +122 -0
- package/src/components/Markdown.tsx +219 -0
- package/src/components/Media.tsx +173 -0
- package/src/components/MessagesAppIcon.tsx +51 -0
- package/src/components/MicButton.tsx +92 -0
- package/src/components/ResultCards.tsx +1067 -0
- package/src/components/SignInPrompt.tsx +182 -0
- package/src/components/SignedOut.tsx +47 -0
- package/src/components/TalkToLucyHero.tsx +540 -0
- package/src/components/TalkToLucySheet.tsx +208 -0
- package/src/components/VoiceOrb.tsx +364 -0
- package/src/components/WhereLucyWorks.tsx +261 -0
- package/src/components/WorkspaceSection.tsx +307 -0
- package/src/components/YantraMark.tsx +30 -0
- package/src/components/drawerHeader.tsx +46 -0
- package/src/components/kit.tsx +309 -0
- package/src/components/lottieInstalled.ts +7 -0
- package/src/components/ui.tsx +700 -0
- package/src/components/useSignOut.ts +21 -0
- package/src/components/viewport.tsx +166 -0
- package/src/components/voiceDial.ts +45 -0
- package/src/compute.ts +168 -0
- package/src/config/env-config.ts +50 -0
- package/src/config/routes.ts +28 -0
- package/src/content.ts +217 -0
- package/src/hooks/keyboardCover.ts +70 -0
- package/src/hooks/useKeyboard.ts +135 -0
- package/src/hooks/useReducedMotion.ts +19 -0
- package/src/imessage/openMessages.ts +53 -0
- package/src/imessage/platform.ts +32 -0
- package/src/imessage/textLink.ts +307 -0
- package/src/index.ts +24 -0
- package/src/live/card.ts +62 -0
- package/src/live/liveActivity.ts +192 -0
- package/src/module.ts +8 -0
- package/src/offer/BlackFridayOffer.tsx +394 -0
- package/src/offer/blackFriday.ts +109 -0
- package/src/offer/parts.tsx +650 -0
- package/src/offer/state.ts +78 -0
- package/src/push/push.ts +171 -0
- package/src/push/usePushNotifications.ts +47 -0
- package/src/screens/Account/index.tsx +310 -0
- package/src/screens/Chat/.claude-flow/data/pending-insights.jsonl +4 -0
- package/src/screens/Chat/index.tsx +891 -0
- package/src/screens/Chores/index.tsx +35 -0
- package/src/screens/Connectors/index.tsx +35 -0
- package/src/screens/History/index.tsx +346 -0
- package/src/screens/Home/index.tsx +2776 -0
- package/src/screens/Home/media.ts +31 -0
- package/src/screens/Welcome/index.tsx +1182 -0
- package/src/talk/talkToLucy.ts +187 -0
- package/src/theme/colors.ts +38 -0
- package/src/theme/fonts.ts +30 -0
- package/src/theme/muse.ts +86 -0
- package/src/utils/links.ts +84 -0
- package/src/utils/yantraLinks.ts +94 -0
- package/src/welcome/flow.ts +418 -0
- package/src/welcome/haptics.ts +179 -0
- package/src/welcome/parts.tsx +2160 -0
- package/src/welcome/powerOn.ts +84 -0
- package/src/welcome/seen.ts +68 -0
- package/src/welcome/sound.ts +173 -0
- package/tools/lottie/chat.motion +0 -0
- package/tools/lottie/cloud.motion +0 -0
- package/tools/lottie/generate.mjs +1209 -0
- package/tools/lottie/inter-glyphs.json +4416 -0
- package/tools/lottie/lucy-mark-calendar.motion +0 -0
- package/tools/lottie/lucy-mark-call.motion +0 -0
- package/tools/lottie/lucy-mark-connect.motion +0 -0
- package/tools/lottie/lucy-mark-details.motion +0 -0
- package/tools/lottie/lucy-mark-email.motion +0 -0
- package/tools/lottie/lucy-mark-message.motion +0 -0
- package/tools/lottie/lucy-mark-search.motion +0 -0
- package/tools/lottie/lucy-mark-think.motion +0 -0
- package/tools/lottie/lucy-mark-write.motion +0 -0
- package/tools/lottie/mark.json +1 -0
- package/tools/lottie/mine-none.motion +0 -0
- package/tools/lottie/mine-offline.motion +0 -0
- package/tools/lottie/mine-online.motion +0 -0
- package/tools/lottie/time-back.mjs +604 -0
- package/tools/sounds/render.mjs +730 -0
- package/tsconfig.json +17 -0
- package/README.md +0 -3
|
@@ -0,0 +1,730 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Renders the welcome's sounds (src/welcome/sound.ts) into src/assets/sounds: synthesized sample by sample here, so
|
|
4
|
+
* every beat lands exactly where the picture and the haptics do, and a tweak is an edit and a re-run, not a session in
|
|
5
|
+
* an audio editor. Plain Node, no dependencies; macOS's afconvert encodes them.
|
|
6
|
+
*
|
|
7
|
+
* node tools/sounds/render.mjs [cue ...] # every cue, or just the ones named
|
|
8
|
+
* SOUNDS_OUT=/some/dir SOUNDS_WAV=1 node tools/sounds/render.mjs # elsewhere, keeping the WAVs to inspect
|
|
9
|
+
*
|
|
10
|
+
* Each cue is set to a loudness as a phone's own speaker plays it (phoneLoudness), gentle enough that the first
|
|
11
|
+
* sound of a first launch never startles: about 6 dB under streamed music, the power-on loudest and the wind-back
|
|
12
|
+
* softest. They play on the ambient channel, so the ring/silent switch mutes them and other audio keeps playing.
|
|
13
|
+
*
|
|
14
|
+
* One family of sounds in D-flat major: a watch's tick for time, and Lucy's warm chord (D-flat, F, A-flat, C, E-flat)
|
|
15
|
+
* struck on soft vibraphone bars with a glass shimmer above and a pad beneath. The low thumps carry harmonics up where
|
|
16
|
+
* a phone's speaker can play them; the Taptic Engine supplies the rest of the weight.
|
|
17
|
+
*
|
|
18
|
+
* The power-on is rendered to POWER_ON and tickLitAt in src/welcome/powerOn.ts, and the wind-back to WIND_BACK in
|
|
19
|
+
* src/welcome/flow.ts. Change those and re-render: the test in __tests__/sound.test.ts holds them to RENDERED_FOR in
|
|
20
|
+
* sound.ts.
|
|
21
|
+
*/
|
|
22
|
+
import { execFileSync } from 'node:child_process';
|
|
23
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
24
|
+
import { tmpdir } from 'node:os';
|
|
25
|
+
import { dirname, join } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
|
|
28
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
29
|
+
const OUT = process.env.SOUNDS_OUT || join(HERE, '../../src/assets/sounds');
|
|
30
|
+
const KEEP_WAV = process.env.SOUNDS_WAV === '1';
|
|
31
|
+
|
|
32
|
+
const SR = 44100;
|
|
33
|
+
const TAU = Math.PI * 2;
|
|
34
|
+
|
|
35
|
+
/* ---------------------------------------------------------------------------------------- the picture's clock */
|
|
36
|
+
|
|
37
|
+
/** welcome/powerOn.ts, POWER_ON. */
|
|
38
|
+
const POWER_ON = { ring: 870, click: 900, ignite: 1000, beats: [1250, 1450], sink: 1640, settle: 1650, done: 2300 };
|
|
39
|
+
/** welcome/powerOn.ts, tickLitAt: when tick `i` (0 at twelve, clockwise) lights. */
|
|
40
|
+
const tickLitAt = (i) => Math.round(POWER_ON.ring * Math.pow(Math.min(59, Math.max(0, i)) / 59, 0.55));
|
|
41
|
+
/** welcome/flow.ts, WIND_BACK: the intro's third beat, 14 ticks 75 ms apart from 60 ms as the ring lights over 1100. */
|
|
42
|
+
const WIND_BACK = { count: 14, every: 75, start: 60, lit: 1100 };
|
|
43
|
+
|
|
44
|
+
/* ---------------------------------------------------------------------------------------------- the notes */
|
|
45
|
+
|
|
46
|
+
const hz = (midi) => 440 * Math.pow(2, (midi - 69) / 12);
|
|
47
|
+
const N = {
|
|
48
|
+
Db3: hz(49),
|
|
49
|
+
Ab3: hz(56),
|
|
50
|
+
Db4: hz(61),
|
|
51
|
+
Eb4: hz(63),
|
|
52
|
+
F4: hz(65),
|
|
53
|
+
Ab4: hz(68),
|
|
54
|
+
Bb4: hz(70),
|
|
55
|
+
C5: hz(72),
|
|
56
|
+
Db5: hz(73),
|
|
57
|
+
Eb5: hz(75),
|
|
58
|
+
F5: hz(77),
|
|
59
|
+
Ab5: hz(80),
|
|
60
|
+
Bb5: hz(82),
|
|
61
|
+
C6: hz(84),
|
|
62
|
+
Db6: hz(85),
|
|
63
|
+
Eb6: hz(87),
|
|
64
|
+
F6: hz(89),
|
|
65
|
+
Ab6: hz(92),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/* ---------------------------------------------------------------------------------------------- helpers */
|
|
69
|
+
|
|
70
|
+
const S = (ms) => Math.round((ms * SR) / 1000);
|
|
71
|
+
const dB = (d) => Math.pow(10, d / 20);
|
|
72
|
+
/** Falls 60 dB over `t60` seconds. */
|
|
73
|
+
const decay = (t, t60) => Math.exp((-6.907755 * t) / t60);
|
|
74
|
+
/** A raised-cosine rise over `a` seconds, so nothing starts with a click. */
|
|
75
|
+
const rise = (t, a) => (t >= a ? 1 : 0.5 - 0.5 * Math.cos((Math.PI * t) / a));
|
|
76
|
+
/** A soft bump centred on `c` seconds, `w` wide. */
|
|
77
|
+
const bump = (t, c, w) => Math.exp(-(((t - c) / w) ** 2));
|
|
78
|
+
|
|
79
|
+
/** Deterministic noise, so a re-render sounds exactly the same. */
|
|
80
|
+
let seed = 0x2b7e1516;
|
|
81
|
+
function noise() {
|
|
82
|
+
seed = (seed + 0x6d2b79f5) | 0;
|
|
83
|
+
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
|
|
84
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
85
|
+
return (((t ^ (t >>> 14)) >>> 0) / 4294967296) * 2 - 1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** RBJ biquad coefficients. */
|
|
89
|
+
function biquad(type, f, q) {
|
|
90
|
+
const w = (TAU * Math.min(f, SR * 0.45)) / SR;
|
|
91
|
+
const cw = Math.cos(w);
|
|
92
|
+
const alpha = Math.sin(w) / (2 * q);
|
|
93
|
+
let b;
|
|
94
|
+
if (type === 'lp') b = [(1 - cw) / 2, 1 - cw, (1 - cw) / 2];
|
|
95
|
+
else if (type === 'hp') b = [(1 + cw) / 2, -(1 + cw), (1 + cw) / 2];
|
|
96
|
+
else b = [alpha, 0, -alpha];
|
|
97
|
+
const a0 = 1 + alpha;
|
|
98
|
+
return { b0: b[0] / a0, b1: b[1] / a0, b2: b[2] / a0, a1: (-2 * cw) / a0, a2: (1 - alpha) / a0 };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** `x` through a biquad whose frequency may move: `f` is a number or a function of time in seconds. */
|
|
102
|
+
function filter(x, type, f, q = 0.707) {
|
|
103
|
+
const y = new Float64Array(x.length);
|
|
104
|
+
let c = biquad(type, typeof f === 'function' ? f(0) : f, q);
|
|
105
|
+
let x1 = 0;
|
|
106
|
+
let x2 = 0;
|
|
107
|
+
let y1 = 0;
|
|
108
|
+
let y2 = 0;
|
|
109
|
+
for (let i = 0; i < x.length; i++) {
|
|
110
|
+
if (typeof f === 'function' && i % 32 === 0) c = biquad(type, f(i / SR), q);
|
|
111
|
+
const v = c.b0 * x[i] + c.b1 * x1 + c.b2 * x2 - c.a1 * y1 - c.a2 * y2;
|
|
112
|
+
x2 = x1;
|
|
113
|
+
x1 = x[i];
|
|
114
|
+
y2 = y1;
|
|
115
|
+
y1 = v;
|
|
116
|
+
y[i] = v;
|
|
117
|
+
}
|
|
118
|
+
return y;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const buffer = (sec) => new Float64Array(Math.ceil(sec * SR));
|
|
122
|
+
|
|
123
|
+
/* ---------------------------------------------------------------------------------------------- the voices */
|
|
124
|
+
|
|
125
|
+
/** A watch's tick: a hair of noise around `freq`, a short metal ring and a small wooden knock beneath. */
|
|
126
|
+
function tick(freq, { ring = 0.045, knock = 0.3 } = {}) {
|
|
127
|
+
const out = buffer(0.08);
|
|
128
|
+
const burst = buffer(0.08);
|
|
129
|
+
const len = S(1.4);
|
|
130
|
+
for (let i = 0; i < len; i++) burst[i] = noise() * Math.sin((Math.PI * i) / len);
|
|
131
|
+
const snap = filter(burst, 'bp', freq * 1.3, 1.6);
|
|
132
|
+
for (let i = 0; i < out.length; i++) {
|
|
133
|
+
const t = i / SR;
|
|
134
|
+
const metal =
|
|
135
|
+
0.5 * Math.sin(TAU * freq * t) * decay(t, ring) +
|
|
136
|
+
0.16 * Math.sin(TAU * freq * 2.76 * t) * decay(t, ring * 0.5);
|
|
137
|
+
const wood = knock * Math.sin(TAU * freq * 0.26 * t) * decay(t, 0.03);
|
|
138
|
+
out[i] = snap[i] * 2.6 + (metal + wood) * rise(t, 0.0004);
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The minute hand clicking home: a crisper, brighter tick with a bit of spring in it. */
|
|
144
|
+
function latch() {
|
|
145
|
+
const out = buffer(0.2);
|
|
146
|
+
const burst = buffer(0.2);
|
|
147
|
+
const len = S(3);
|
|
148
|
+
for (let i = 0; i < len; i++) burst[i] = noise() * decay(i / SR, 0.004);
|
|
149
|
+
const snap = filter(burst, 'hp', 1400, 0.8);
|
|
150
|
+
const modes = [
|
|
151
|
+
[2150, 0.4, 0.09],
|
|
152
|
+
[3480, 0.26, 0.06],
|
|
153
|
+
[5230, 0.14, 0.04],
|
|
154
|
+
];
|
|
155
|
+
for (let i = 0; i < out.length; i++) {
|
|
156
|
+
const t = i / SR;
|
|
157
|
+
let ring = 0;
|
|
158
|
+
for (const [f, a, d] of modes) ring += a * Math.sin(TAU * f * t) * decay(t, d);
|
|
159
|
+
// a small body: a thock that drops from 640 to 300 Hz
|
|
160
|
+
const thock = 0.5 * Math.sin(TAU * (300 * t + 340 * 0.012 * (1 - Math.exp(-t / 0.012)))) * decay(t, 0.05);
|
|
161
|
+
out[i] = snap[i] * 1.6 + (ring + thock) * rise(t, 0.0003);
|
|
162
|
+
}
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* A thump that drops from `f0` to `f1` Hz: the low end for headphones, saturated so its harmonics reach a phone's
|
|
168
|
+
* speaker, with an octave-up body and a soft attack so small speakers hear where it lands.
|
|
169
|
+
*/
|
|
170
|
+
function thump({ f0 = 150, f1 = 55, glide = 0.16, t60 = 0.6, drive = 2, body = 0.5, click = 0.15 } = {}) {
|
|
171
|
+
const out = buffer(t60 + 0.05);
|
|
172
|
+
let ph = 0;
|
|
173
|
+
let ph2 = 0;
|
|
174
|
+
for (let i = 0; i < out.length; i++) {
|
|
175
|
+
const t = i / SR;
|
|
176
|
+
const f = f1 + (f0 - f1) * Math.exp(-t / (glide / 4));
|
|
177
|
+
ph += (TAU * f) / SR;
|
|
178
|
+
ph2 += (TAU * f * 2) / SR;
|
|
179
|
+
const env = rise(t, 0.002) * decay(t, t60);
|
|
180
|
+
const low = Math.tanh(drive * Math.sin(ph) * env) / Math.tanh(drive);
|
|
181
|
+
const mid = body * Math.sin(ph2) * rise(t, 0.002) * decay(t, t60 * 0.35);
|
|
182
|
+
out[i] = low + mid;
|
|
183
|
+
}
|
|
184
|
+
if (click) {
|
|
185
|
+
const c = buffer(0.012);
|
|
186
|
+
for (let i = 0; i < c.length; i++) c[i] = noise() * decay(i / SR, 0.006);
|
|
187
|
+
const soft = filter(c, 'lp', 2400, 0.7);
|
|
188
|
+
for (let i = 0; i < soft.length; i++) out[i] += soft[i] * click;
|
|
189
|
+
}
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A felt knock, for a heartbeat a phone's speaker can play: a muffled hit around `freq` whose pitch sags as it
|
|
195
|
+
* fades, over a breath of noise in the same band.
|
|
196
|
+
*/
|
|
197
|
+
function knock(freq, { t60 = 0.12 } = {}) {
|
|
198
|
+
const out = buffer(t60 + 0.02);
|
|
199
|
+
const burst = buffer(t60 + 0.02);
|
|
200
|
+
for (let i = 0; i < S(6); i++) burst[i] = noise() * decay(i / SR, 0.006);
|
|
201
|
+
const felt = filter(burst, 'bp', freq, 1.8);
|
|
202
|
+
let ph = 0;
|
|
203
|
+
for (let i = 0; i < out.length; i++) {
|
|
204
|
+
const t = i / SR;
|
|
205
|
+
ph += (TAU * freq * (1 + 0.35 * Math.exp(-t / 0.015))) / SR;
|
|
206
|
+
out[i] = Math.sin(ph) * rise(t, 0.0015) * decay(t, t60) + felt[i] * 1.4;
|
|
207
|
+
}
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** A pulse at `at` seconds: up in 12 ms, gone in about half a second. */
|
|
212
|
+
const pulse = (t, at) => (t < at ? 0 : (1 - Math.exp(-(t - at) / 0.012)) * Math.exp(-(t - at) / 0.16));
|
|
213
|
+
|
|
214
|
+
/** A soft vibraphone bar: the fundamental rings on; its 4th and 10th partials give the strike and fade fast. */
|
|
215
|
+
function bar(f, { t60 = 1.8, bright = 1 } = {}) {
|
|
216
|
+
const out = buffer(t60 + 0.02);
|
|
217
|
+
const partials = [
|
|
218
|
+
[1, 1, 1],
|
|
219
|
+
[2, 0.05, 0.4],
|
|
220
|
+
[4, 0.3 * bright, 0.2],
|
|
221
|
+
[10, 0.08 * bright, 0.06],
|
|
222
|
+
];
|
|
223
|
+
for (const [r, a, d] of partials) {
|
|
224
|
+
if (f * r > SR * 0.42) continue;
|
|
225
|
+
const w = (TAU * f * r) / SR;
|
|
226
|
+
const t60r = t60 * d;
|
|
227
|
+
for (let i = 0; i < out.length; i++) out[i] += a * Math.sin(w * i) * decay(i / SR, t60r);
|
|
228
|
+
}
|
|
229
|
+
// the mallet: a few ms of felt
|
|
230
|
+
const felt = buffer(0.01);
|
|
231
|
+
for (let i = 0; i < felt.length; i++) felt[i] = noise() * decay(i / SR, 0.004);
|
|
232
|
+
const soft = filter(felt, 'lp', Math.min(3500, f * 6), 0.7);
|
|
233
|
+
for (let i = 0; i < out.length; i++) {
|
|
234
|
+
out[i] *= rise(i / SR, 0.0012);
|
|
235
|
+
if (i < soft.length) out[i] += soft[i] * 0.25;
|
|
236
|
+
}
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** A glass bell (FM, 1 : 3.5): bright as it's struck, mellowing to a pure tone. */
|
|
241
|
+
function bell(f, { t60 = 1.2, index = 2 } = {}) {
|
|
242
|
+
const out = buffer(t60);
|
|
243
|
+
const idx = index * Math.min(1, 1800 / f);
|
|
244
|
+
for (let i = 0; i < out.length; i++) {
|
|
245
|
+
const t = i / SR;
|
|
246
|
+
const I = idx * Math.exp(-t / 0.16);
|
|
247
|
+
out[i] = Math.sin(TAU * f * t + I * Math.sin(TAU * f * 3.5 * t)) * decay(t, t60) * rise(t, 0.0015);
|
|
248
|
+
}
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* A warm pad: three slightly detuned voices per note, each a saw rolled off above `cutoff`, spread across the
|
|
254
|
+
* stereo field. `shape(t)` scales its level over time (its swell and heartbeat).
|
|
255
|
+
*/
|
|
256
|
+
function pad(notes, { dur, attack = 0.15, release = 1, cutoff = 900, detune = 6, shape = () => 1 }) {
|
|
257
|
+
const n = Math.ceil((dur + release) * SR);
|
|
258
|
+
const L = new Float64Array(n);
|
|
259
|
+
const R = new Float64Array(n);
|
|
260
|
+
const voices = [
|
|
261
|
+
[-detune, -0.6],
|
|
262
|
+
[0, 0],
|
|
263
|
+
[detune, 0.6],
|
|
264
|
+
];
|
|
265
|
+
for (const f0 of notes) {
|
|
266
|
+
for (const [cents, pan] of voices) {
|
|
267
|
+
const f = f0 * Math.pow(2, cents / 1200);
|
|
268
|
+
const gl = Math.cos(((pan + 1) * Math.PI) / 4) * Math.SQRT2;
|
|
269
|
+
const gr = Math.sin(((pan + 1) * Math.PI) / 4) * Math.SQRT2;
|
|
270
|
+
for (let h = 1; h * f < 7000; h++) {
|
|
271
|
+
const amp = 1 / h / Math.sqrt(1 + Math.pow((h * f) / cutoff, 4));
|
|
272
|
+
if (amp < 0.003) break;
|
|
273
|
+
const ph = (noise() + 1) * Math.PI;
|
|
274
|
+
const w = (TAU * h * f) / SR;
|
|
275
|
+
for (let i = 0; i < n; i++) {
|
|
276
|
+
const v = amp * Math.sin(ph + w * i);
|
|
277
|
+
L[i] += v * gl;
|
|
278
|
+
R[i] += v * gr;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const k = 1 / (notes.length * voices.length);
|
|
284
|
+
for (let i = 0; i < n; i++) {
|
|
285
|
+
const t = i / SR;
|
|
286
|
+
let e = rise(t, attack) * shape(t) * k;
|
|
287
|
+
if (t > dur) e *= decay(t - dur, release);
|
|
288
|
+
L[i] *= e;
|
|
289
|
+
R[i] *= e;
|
|
290
|
+
}
|
|
291
|
+
return { L, R };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Air: noise through a moving band, its own on each side so it spreads. `band(t)` and `level(t)` over seconds. */
|
|
295
|
+
function air(sec, band, level, q = 0.9) {
|
|
296
|
+
const make = () => {
|
|
297
|
+
const x = buffer(sec);
|
|
298
|
+
for (let i = 0; i < x.length; i++) x[i] = noise();
|
|
299
|
+
const y = filter(x, 'bp', band, q);
|
|
300
|
+
for (let i = 0; i < y.length; i++) y[i] *= level(i / SR);
|
|
301
|
+
return y;
|
|
302
|
+
};
|
|
303
|
+
return { L: make(), R: make() };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/* ---------------------------------------------------------------------------------------------- the room */
|
|
307
|
+
|
|
308
|
+
/** Freeverb (Jezar's), stereo: eight damped combs and four allpasses a side. */
|
|
309
|
+
function reverb(L, R, { room = 0.82, damp = 0.35, predelay = 0.018 } = {}) {
|
|
310
|
+
const comb = [1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617];
|
|
311
|
+
const allpass = [556, 441, 341, 225];
|
|
312
|
+
const spread = 23;
|
|
313
|
+
const fb = room * 0.28 + 0.7;
|
|
314
|
+
const dmp = damp * 0.4;
|
|
315
|
+
const make = (len) => ({ buf: new Float64Array(len), i: 0, store: 0 });
|
|
316
|
+
const side = (offset) => ({
|
|
317
|
+
combs: comb.map((c) => make(c + offset)),
|
|
318
|
+
passes: allpass.map((a) => make(a + offset)),
|
|
319
|
+
});
|
|
320
|
+
const sides = [side(0), side(spread)];
|
|
321
|
+
const pd = S(predelay * 1000);
|
|
322
|
+
const out = [new Float64Array(L.length), new Float64Array(L.length)];
|
|
323
|
+
for (let n = 0; n < L.length; n++) {
|
|
324
|
+
const j = n - pd;
|
|
325
|
+
const input = j >= 0 ? (L[j] + R[j]) * 0.015 : 0;
|
|
326
|
+
for (let s = 0; s < 2; s++) {
|
|
327
|
+
const { combs, passes } = sides[s];
|
|
328
|
+
let acc = 0;
|
|
329
|
+
for (const c of combs) {
|
|
330
|
+
const o = c.buf[c.i];
|
|
331
|
+
c.store = o * (1 - dmp) + c.store * dmp;
|
|
332
|
+
c.buf[c.i] = input + c.store * fb;
|
|
333
|
+
if (++c.i >= c.buf.length) c.i = 0;
|
|
334
|
+
acc += o;
|
|
335
|
+
}
|
|
336
|
+
for (const p of passes) {
|
|
337
|
+
const b = p.buf[p.i];
|
|
338
|
+
const o = -acc + b;
|
|
339
|
+
p.buf[p.i] = acc + b * 0.5;
|
|
340
|
+
if (++p.i >= p.buf.length) p.i = 0;
|
|
341
|
+
acc = o;
|
|
342
|
+
}
|
|
343
|
+
out[s][n] = acc * 3;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return { L: out[0], R: out[1] };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/* ---------------------------------------------------------------------------------------------- the desk */
|
|
350
|
+
|
|
351
|
+
/** A stereo mix with a send to the room. */
|
|
352
|
+
class Mix {
|
|
353
|
+
constructor(sec) {
|
|
354
|
+
this.n = Math.ceil(sec * SR);
|
|
355
|
+
this.dry = [new Float64Array(this.n), new Float64Array(this.n)];
|
|
356
|
+
this.send = [new Float64Array(this.n), new Float64Array(this.n)];
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** A mono voice at `ms`, `gain` and `pan` (-1 to 1), `send` of it to the room. */
|
|
360
|
+
add(x, ms, { gain = 1, pan = 0, send = 0 } = {}) {
|
|
361
|
+
const a = ((pan + 1) * Math.PI) / 4;
|
|
362
|
+
const g = [gain * Math.cos(a) * Math.SQRT2, gain * Math.sin(a) * Math.SQRT2];
|
|
363
|
+
const o = S(ms);
|
|
364
|
+
for (let i = 0; i < x.length; i++) {
|
|
365
|
+
const j = o + i;
|
|
366
|
+
if (j < 0 || j >= this.n) continue;
|
|
367
|
+
for (let s = 0; s < 2; s++) {
|
|
368
|
+
this.dry[s][j] += x[i] * g[s];
|
|
369
|
+
this.send[s][j] += x[i] * g[s] * send;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** A stereo voice ({L, R}) at `ms`. */
|
|
375
|
+
addStereo({ L, R }, ms, { gain = 1, send = 0 } = {}) {
|
|
376
|
+
const o = S(ms);
|
|
377
|
+
for (let i = 0; i < L.length; i++) {
|
|
378
|
+
const j = o + i;
|
|
379
|
+
if (j < 0 || j >= this.n) continue;
|
|
380
|
+
this.dry[0][j] += L[i] * gain;
|
|
381
|
+
this.dry[1][j] += R[i] * gain;
|
|
382
|
+
this.send[0][j] += L[i] * gain * send;
|
|
383
|
+
this.send[1][j] += R[i] * gain * send;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Dry plus room. The room hears no lows (they stay tight) and no harsh highs. */
|
|
388
|
+
bounce(roomOpts = {}) {
|
|
389
|
+
const low = (x) => filter(filter(x, 'hp', 280, 0.6), 'lp', 7500, 0.6);
|
|
390
|
+
const wet = reverb(low(this.send[0]), low(this.send[1]), roomOpts);
|
|
391
|
+
return [0, 1].map((s) => {
|
|
392
|
+
const y = new Float64Array(this.n);
|
|
393
|
+
for (let i = 0; i < this.n; i++) y[i] = this.dry[s][i] + wet[s === 0 ? 'L' : 'R'][i];
|
|
394
|
+
return y;
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** A high shelf (RBJ), for the K-weighting below. */
|
|
400
|
+
function shelf(x, f, gainDb, q) {
|
|
401
|
+
const A = Math.pow(10, gainDb / 40);
|
|
402
|
+
const w = (TAU * f) / SR;
|
|
403
|
+
const cw = Math.cos(w);
|
|
404
|
+
const alpha = Math.sin(w) / (2 * q);
|
|
405
|
+
const r = 2 * Math.sqrt(A) * alpha;
|
|
406
|
+
const a0 = A + 1 - (A - 1) * cw + r;
|
|
407
|
+
const c = {
|
|
408
|
+
b0: (A * (A + 1 + (A - 1) * cw + r)) / a0,
|
|
409
|
+
b1: (-2 * A * (A - 1 + (A + 1) * cw)) / a0,
|
|
410
|
+
b2: (A * (A + 1 + (A - 1) * cw - r)) / a0,
|
|
411
|
+
a1: (2 * (A - 1 - (A + 1) * cw)) / a0,
|
|
412
|
+
a2: (A + 1 - (A - 1) * cw - r) / a0,
|
|
413
|
+
};
|
|
414
|
+
const y = new Float64Array(x.length);
|
|
415
|
+
let x1 = 0;
|
|
416
|
+
let x2 = 0;
|
|
417
|
+
let y1 = 0;
|
|
418
|
+
let y2 = 0;
|
|
419
|
+
for (let i = 0; i < x.length; i++) {
|
|
420
|
+
const v = c.b0 * x[i] + c.b1 * x1 + c.b2 * x2 - c.a1 * y1 - c.a2 * y2;
|
|
421
|
+
x2 = x1;
|
|
422
|
+
x1 = x[i];
|
|
423
|
+
y2 = y1;
|
|
424
|
+
y1 = v;
|
|
425
|
+
y[i] = v;
|
|
426
|
+
}
|
|
427
|
+
return y;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* How loud it plays on a phone: ITU-R BS.1770 loudness (K-weighted, 400 ms blocks, gated) of what is left above
|
|
432
|
+
* 300 Hz, roughly all an iPhone's own speaker can play. In LUFS.
|
|
433
|
+
*/
|
|
434
|
+
function phoneLoudness(chans) {
|
|
435
|
+
const weighted = chans.map((c) => shelf(filter(filter(c, 'hp', 300, 0.54), 'hp', 300, 1.31), 1681.97, 4, 0.7072));
|
|
436
|
+
const block = S(400);
|
|
437
|
+
const step = S(100);
|
|
438
|
+
const blocks = [];
|
|
439
|
+
for (let s = 0; s + block <= weighted[0].length; s += step) {
|
|
440
|
+
let sum = 0;
|
|
441
|
+
for (const c of weighted) for (let i = s; i < s + block; i++) sum += c[i] * c[i];
|
|
442
|
+
blocks.push(sum / block);
|
|
443
|
+
}
|
|
444
|
+
const lufs = (z) => -0.691 + 10 * Math.log10(z);
|
|
445
|
+
const loud = blocks.filter((z) => lufs(z) > -70);
|
|
446
|
+
const mean = (zs) => zs.reduce((a, z) => a + z, 0) / zs.length;
|
|
447
|
+
const relative = lufs(mean(loud)) - 10;
|
|
448
|
+
return lufs(mean(loud.filter((z) => lufs(z) > relative)));
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* The master: below 30 Hz out, the tail trimmed where it falls under `floor` dB (with a short fade), and the whole
|
|
453
|
+
* set to `lufs` as a phone plays it (phoneLoudness), never peaking above -1 dBFS.
|
|
454
|
+
*/
|
|
455
|
+
function master(chans, { lufs, floor = -60, fade = 0.15 }) {
|
|
456
|
+
const hp = chans.map((c) => filter(filter(c, 'hp', 30, 0.707), 'hp', 30, 0.707));
|
|
457
|
+
let top = 0;
|
|
458
|
+
for (const c of hp) for (const v of c) top = Math.max(top, Math.abs(v));
|
|
459
|
+
const gate = top * dB(floor);
|
|
460
|
+
let end = 0;
|
|
461
|
+
for (const c of hp) for (let i = c.length - 1; i > end; i--) if (Math.abs(c[i]) > gate) end = i;
|
|
462
|
+
const len = Math.min(hp[0].length, end + S(fade * 1000));
|
|
463
|
+
const k = Math.min(dB(lufs - phoneLoudness(hp)), dB(-1) / top);
|
|
464
|
+
return hp.map((c) => {
|
|
465
|
+
const y = c.slice(0, len);
|
|
466
|
+
for (let i = 0; i < len; i++) {
|
|
467
|
+
y[i] *= k;
|
|
468
|
+
const left = (len - i) / SR;
|
|
469
|
+
if (left < fade) y[i] *= 0.5 - 0.5 * Math.cos((Math.PI * left) / fade);
|
|
470
|
+
}
|
|
471
|
+
return y;
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** 16-bit PCM WAV, TPDF-dithered. */
|
|
476
|
+
function wav(chans) {
|
|
477
|
+
const len = chans[0].length;
|
|
478
|
+
const ch = chans.length;
|
|
479
|
+
const data = Buffer.alloc(len * ch * 2);
|
|
480
|
+
for (let i = 0; i < len; i++) {
|
|
481
|
+
for (let c = 0; c < ch; c++) {
|
|
482
|
+
const dither = (noise() + noise()) / 2 / 32768;
|
|
483
|
+
const v = Math.max(-1, Math.min(1, chans[c][i] + dither));
|
|
484
|
+
data.writeInt16LE(Math.round(v * 32767), (i * ch + c) * 2);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const head = Buffer.alloc(44);
|
|
488
|
+
head.write('RIFF', 0);
|
|
489
|
+
head.writeUInt32LE(36 + data.length, 4);
|
|
490
|
+
head.write('WAVE', 8);
|
|
491
|
+
head.write('fmt ', 12);
|
|
492
|
+
head.writeUInt32LE(16, 16);
|
|
493
|
+
head.writeUInt16LE(1, 20);
|
|
494
|
+
head.writeUInt16LE(ch, 22);
|
|
495
|
+
head.writeUInt32LE(SR, 24);
|
|
496
|
+
head.writeUInt32LE(SR * ch * 2, 28);
|
|
497
|
+
head.writeUInt16LE(ch * 2, 32);
|
|
498
|
+
head.writeUInt16LE(16, 34);
|
|
499
|
+
head.write('data', 36);
|
|
500
|
+
head.writeUInt32LE(data.length, 40);
|
|
501
|
+
return Buffer.concat([head, data]);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/* ---------------------------------------------------------------------------------------------- the cues */
|
|
505
|
+
|
|
506
|
+
/** Where a tick sits on the dial, as a pan: twelve and six in the middle, three to the right, nine to the left. */
|
|
507
|
+
const dialPan = (index) => Math.sin((index * 6 * Math.PI) / 180) * 0.35;
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* The power-on (2.3 s, then a ring-out). The twelve hour ticks light with the ring, faster and louder, rising from
|
|
511
|
+
* the dark on a breath of air; the minute hand clicks home; a beat of silence; Lucy lights with a thoom, the chord
|
|
512
|
+
* blooming out with the cream and a glass shimmer on the white flash; her heart beats twice through the chord; it
|
|
513
|
+
* settles as she sinks into the pin, and the clock's first tock hands over to the welcome.
|
|
514
|
+
*/
|
|
515
|
+
function powerOn() {
|
|
516
|
+
const m = new Mix(3.8);
|
|
517
|
+
const { click, ignite, beats, sink } = POWER_ON;
|
|
518
|
+
|
|
519
|
+
// The ring lighting: an hour tick every five, its pitch and weight climbing as they close in.
|
|
520
|
+
for (let k = 0; k < 12; k++) {
|
|
521
|
+
const i = k * 5;
|
|
522
|
+
const f = 1650 * Math.pow(3000 / 1650, k / 11);
|
|
523
|
+
m.add(tick(f), tickLitAt(i), { gain: 0.17 + 0.3 * Math.pow(k / 11, 1.4), pan: dialPan(i), send: 0.25 });
|
|
524
|
+
}
|
|
525
|
+
// Under them, air and a low chord rising into the click, cut dead by it.
|
|
526
|
+
const swell = 0.62;
|
|
527
|
+
const lift = air(
|
|
528
|
+
swell,
|
|
529
|
+
(t) => 700 * Math.pow(5000 / 700, t / swell),
|
|
530
|
+
(t) => 0.05 * Math.pow(t / swell, 2.2),
|
|
531
|
+
0.8,
|
|
532
|
+
);
|
|
533
|
+
m.addStereo(lift, click - swell * 1000, { send: 0.3 });
|
|
534
|
+
const dusk = pad([N.Db3, N.Ab3, N.Db4], {
|
|
535
|
+
dur: 0.6,
|
|
536
|
+
attack: 0.55,
|
|
537
|
+
release: 0.004,
|
|
538
|
+
cutoff: 700,
|
|
539
|
+
shape: (t) => Math.pow(Math.min(1, t / 0.55), 1.5),
|
|
540
|
+
});
|
|
541
|
+
m.addStereo(dusk, click - 600, { gain: 0.5, send: 0.2 });
|
|
542
|
+
|
|
543
|
+
m.add(latch(), click, { gain: 0.95, send: 0.35 });
|
|
544
|
+
|
|
545
|
+
// Lucy lights up: the thoom, and the chord struck from a low D-flat whose overtones give it weight on a phone.
|
|
546
|
+
m.add(thump({ f0: 160, f1: 52, glide: 0.2, t60: 0.75, drive: 2.2, body: 0.42, click: 0.3 }), ignite, {
|
|
547
|
+
gain: 0.42,
|
|
548
|
+
});
|
|
549
|
+
m.add(bar(N.Db3, { t60: 1.6, bright: 1.5 }), ignite, { gain: 0.26, send: 0.3 });
|
|
550
|
+
const chord = [N.Ab3, N.Db4, N.F4, N.C5, N.Eb5, N.Ab5];
|
|
551
|
+
chord.forEach((f, k) => {
|
|
552
|
+
m.add(bar(f, { t60: 1.7, bright: 1.2 }), ignite + k * 4, { gain: 0.23, pan: (k - 2.5) * 0.12, send: 0.35 });
|
|
553
|
+
});
|
|
554
|
+
[N.Db6, N.F6, N.Ab6, N.Eb6].forEach((f, k) => {
|
|
555
|
+
m.add(bell(f, { t60: 1.1 }), ignite + 4 + k * 12, { gain: 0.13, pan: [-0.45, 0.35, -0.15, 0.5][k], send: 0.6 });
|
|
556
|
+
});
|
|
557
|
+
const [b0, b1] = beats.map((b) => (b - ignite) / 1000);
|
|
558
|
+
const glow = pad([N.Db3, N.Ab3, N.F4, N.C5], {
|
|
559
|
+
dur: (sink - ignite) / 1000,
|
|
560
|
+
attack: 0.28,
|
|
561
|
+
release: 0.85,
|
|
562
|
+
cutoff: 1100,
|
|
563
|
+
// her heartbeat glows through the chord as well as thumping under it
|
|
564
|
+
shape: (t) => 1 + 2.2 * pulse(t, b0) + 1.4 * pulse(t, b1),
|
|
565
|
+
});
|
|
566
|
+
m.addStereo(glow, ignite, { gain: 0.55, send: 0.45 });
|
|
567
|
+
// The cream flooding out: a breath that opens and spreads.
|
|
568
|
+
const flood = 0.7;
|
|
569
|
+
m.addStereo(
|
|
570
|
+
air(
|
|
571
|
+
flood,
|
|
572
|
+
(t) => 500 + 2600 * Math.sin(Math.PI * Math.min(1, t / flood)),
|
|
573
|
+
(t) => 0.035 * bump(t, 0.2, 0.17),
|
|
574
|
+
0.7,
|
|
575
|
+
),
|
|
576
|
+
ignite + 20,
|
|
577
|
+
{ send: 0.4 },
|
|
578
|
+
);
|
|
579
|
+
|
|
580
|
+
// Her heartbeat: lub, dub. A thump for headphones and a felt knock for the phone's own speaker.
|
|
581
|
+
m.add(thump({ f0: 120, f1: 58, glide: 0.08, t60: 0.3, drive: 2, body: 0.5, click: 0.12 }), beats[0], { gain: 0.5 });
|
|
582
|
+
m.add(knock(420, { t60: 0.14 }), beats[0], { gain: 0.6, send: 0.2 });
|
|
583
|
+
m.add(thump({ f0: 108, f1: 55, glide: 0.07, t60: 0.26, drive: 1.8, body: 0.5, click: 0.1 }), beats[1], {
|
|
584
|
+
gain: 0.34,
|
|
585
|
+
});
|
|
586
|
+
m.add(knock(380, { t60: 0.12 }), beats[1], { gain: 0.4, send: 0.2 });
|
|
587
|
+
|
|
588
|
+
// She sinks into the pin, the chord settling a step down; the clock's first tock.
|
|
589
|
+
m.add(bar(N.F4, { t60: 1.3, bright: 0.6 }), sink, { gain: 0.06, pan: -0.15, send: 0.6 });
|
|
590
|
+
m.add(bar(N.Db4, { t60: 1.4, bright: 0.6 }), sink + 70, { gain: 0.06, pan: 0.15, send: 0.6 });
|
|
591
|
+
m.add(tick(1250, { ring: 0.06, knock: 0.55 }), POWER_ON.done - 30, { gain: 0.22, send: 0.4 });
|
|
592
|
+
|
|
593
|
+
return master(m.bounce({ room: 0.62, damp: 0.32 }), { lufs: -22 });
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Winding back (the intro's third beat): the ticks light anticlockwise, falling in pitch, as the chord is drawn
|
|
598
|
+
* backwards into the moment the ring is whole, the way a tape sounds rewinding.
|
|
599
|
+
*/
|
|
600
|
+
function windBack() {
|
|
601
|
+
const { count, every, start, lit } = WIND_BACK;
|
|
602
|
+
const m = new Mix(1.7);
|
|
603
|
+
for (let k = 0; k < count; k++) {
|
|
604
|
+
const at = start + k * every;
|
|
605
|
+
const index = -((at / lit) * 60);
|
|
606
|
+
const f = 3000 * Math.pow(1700 / 3000, k / (count - 1));
|
|
607
|
+
m.add(tick(f, { ring: 0.035 }), at, { gain: 0.3, pan: dialPan(index), send: 0.3 });
|
|
608
|
+
}
|
|
609
|
+
// The chord, struck and left to ring in a big room, then reversed so it swells up into `lit`.
|
|
610
|
+
const struck = new Mix(1.25);
|
|
611
|
+
[N.Db5, N.F5, N.Ab5, N.C6].forEach((f, k) =>
|
|
612
|
+
struck.add(bar(f, { t60: 1.1 }), k * 6, { gain: 0.2, pan: (k - 1.5) * 0.25, send: 0.9 }),
|
|
613
|
+
);
|
|
614
|
+
struck.add(bell(N.F6, { t60: 0.9 }), 10, { gain: 0.06, send: 1 });
|
|
615
|
+
const [sl, sr] = struck.bounce({ room: 0.9, damp: 0.25, predelay: 0.004 });
|
|
616
|
+
const reversed = { L: sl.slice().reverse(), R: sr.slice().reverse() };
|
|
617
|
+
// Gather it in slowly: quiet at first, so the reverse is felt rather than heard as a trick.
|
|
618
|
+
for (const side of [reversed.L, reversed.R]) {
|
|
619
|
+
for (let i = 0; i < side.length; i++) side[i] *= Math.pow(i / side.length, 1.3);
|
|
620
|
+
}
|
|
621
|
+
m.addStereo(reversed, lit - (sl.length / SR) * 1000, { gain: 0.9 });
|
|
622
|
+
return master(m.bounce({ room: 0.7, damp: 0.4 }), { lufs: -26 });
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/** Meeting Lucy (the intro's last beat): a soft landing, then her three notes rising into her chord as she grows. */
|
|
626
|
+
function meetLucy() {
|
|
627
|
+
const m = new Mix(2.6);
|
|
628
|
+
m.add(thump({ f0: 170, f1: 70, glide: 0.12, t60: 0.35, drive: 1.5, body: 0.5, click: 0.1 }), 0, { gain: 0.3 });
|
|
629
|
+
[N.Ab4, N.Db5, N.F5].forEach((f, k) => {
|
|
630
|
+
m.add(bar(f, { t60: 1.7 }), 40 + k * 120, { gain: 0.27, pan: (k - 1) * 0.2, send: 0.5 });
|
|
631
|
+
m.add(bell(f * 2, { t60: 0.8 }), 40 + k * 120, { gain: 0.045, pan: (1 - k) * 0.3, send: 0.8 });
|
|
632
|
+
});
|
|
633
|
+
const warm = pad([N.Db4, N.F4, N.Ab4, N.C5], { dur: 0.95, attack: 0.45, release: 1, cutoff: 1000 });
|
|
634
|
+
m.addStereo(warm, 260, { gain: 0.75, send: 0.5 });
|
|
635
|
+
return master(m.bounce({ room: 0.62, damp: 0.32 }), { lufs: -24.5 });
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** The hours back landing (the good news): the last digit locks, and the chord opens up bright and warm. */
|
|
639
|
+
function hoursBack() {
|
|
640
|
+
const m = new Mix(2.6);
|
|
641
|
+
m.add(latch(), 0, { gain: 0.35, send: 0.3 });
|
|
642
|
+
m.add(thump({ f0: 150, f1: 62, glide: 0.1, t60: 0.4, drive: 1.6, body: 0.45, click: 0.1 }), 0, { gain: 0.4 });
|
|
643
|
+
[N.F4, N.Ab4, N.Db5, N.Eb5, N.F5, N.Ab5].forEach((f, k) =>
|
|
644
|
+
m.add(bar(f, { t60: 1.9 }), 10 + k * 16, { gain: 0.16, pan: (k - 2.5) * 0.14, send: 0.5 }),
|
|
645
|
+
);
|
|
646
|
+
[N.Db6, N.F6].forEach((f, k) =>
|
|
647
|
+
m.add(bell(f, { t60: 1.1 }), 60 + k * 40, { gain: 0.06, pan: k ? 0.4 : -0.4, send: 0.8 }),
|
|
648
|
+
);
|
|
649
|
+
const open = pad([N.Db4, N.F4, N.Ab4, N.C5, N.Eb5], { dur: 0.7, attack: 0.08, release: 1.1, cutoff: 1300 });
|
|
650
|
+
m.addStereo(open, 0, { gain: 0.8, send: 0.5 });
|
|
651
|
+
return master(m.bounce({ room: 0.62, damp: 0.32 }), { lufs: -23.5 });
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* You're in: a burst of air as the icons fly out, a glass run up the chord as they scatter, and the whole chord
|
|
656
|
+
* underneath, swelling with the two rings and fading as the burst does.
|
|
657
|
+
*/
|
|
658
|
+
function youreIn() {
|
|
659
|
+
const m = new Mix(3.4);
|
|
660
|
+
m.addStereo(
|
|
661
|
+
air(
|
|
662
|
+
0.4,
|
|
663
|
+
(t) => 3200 * Math.pow(900 / 3200, t / 0.4),
|
|
664
|
+
(t) => 0.08 * rise(t, 0.01) * decay(t, 0.4),
|
|
665
|
+
0.8,
|
|
666
|
+
),
|
|
667
|
+
0,
|
|
668
|
+
{ send: 0.4 },
|
|
669
|
+
);
|
|
670
|
+
m.add(thump({ f0: 150, f1: 55, glide: 0.14, t60: 0.55, drive: 2, body: 0.45, click: 0.18 }), 0, { gain: 0.55 });
|
|
671
|
+
const run = [N.Db5, N.F5, N.Ab5, N.C6, N.Db6, N.F6, N.Ab6];
|
|
672
|
+
run.forEach((f, k) => {
|
|
673
|
+
const pan = (k % 2 ? 1 : -1) * (0.15 + k * 0.06);
|
|
674
|
+
m.add(bell(f, { t60: 1.3 }), 20 + k * 48, { gain: 0.11 - k * 0.008, pan, send: 0.75 });
|
|
675
|
+
m.add(bar(f, { t60: 1.2, bright: 0.7 }), 20 + k * 48, { gain: 0.1, pan: -pan * 0.5, send: 0.5 });
|
|
676
|
+
});
|
|
677
|
+
[N.Ab3, N.Db4, N.F4, N.Ab4, N.C5].forEach((f, k) =>
|
|
678
|
+
m.add(bar(f, { t60: 2.2 }), k * 7, { gain: 0.13, pan: (k - 2) * 0.12, send: 0.5 }),
|
|
679
|
+
);
|
|
680
|
+
const bloom = pad([N.Db3, N.Ab3, N.F4, N.C5, N.Eb5], {
|
|
681
|
+
dur: 1.75,
|
|
682
|
+
attack: 0.15,
|
|
683
|
+
release: 0.9,
|
|
684
|
+
cutoff: 1200,
|
|
685
|
+
shape: (t) => 1 + 0.35 * bump(t, 0.3, 0.12) + 0.25 * bump(t, 0.6, 0.14),
|
|
686
|
+
});
|
|
687
|
+
m.addStereo(bloom, 0, { gain: 0.9, send: 0.55 });
|
|
688
|
+
return master(m.bounce({ room: 0.66, damp: 0.3 }), { lufs: -22.5 });
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/* ---------------------------------------------------------------------------------------------- render */
|
|
692
|
+
|
|
693
|
+
const CUES = {
|
|
694
|
+
'power-on': powerOn,
|
|
695
|
+
'wind-back': windBack,
|
|
696
|
+
'meet-lucy': meetLucy,
|
|
697
|
+
'hours-back': hoursBack,
|
|
698
|
+
'youre-in': youreIn,
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
const only = process.argv.slice(2);
|
|
702
|
+
mkdirSync(OUT, { recursive: true });
|
|
703
|
+
const scratch = mkdtempSync(join(tmpdir(), 'clockbook-sounds-'));
|
|
704
|
+
for (const [name, render] of Object.entries(CUES)) {
|
|
705
|
+
if (only.length && !only.includes(name)) continue;
|
|
706
|
+
// each cue its own noise, so one renders the same whether or not the others do
|
|
707
|
+
seed = [...name].reduce((h, ch) => Math.imul(h ^ ch.charCodeAt(0), 0x01000193), 0x811c9dc5);
|
|
708
|
+
const chans = render();
|
|
709
|
+
const pcm = join(KEEP_WAV ? OUT : scratch, `${name}.wav`);
|
|
710
|
+
writeFileSync(pcm, wav(chans));
|
|
711
|
+
// AAC at 160 kb/s, a tenth of the WAV's size. The file records the encoder's priming, which iOS and Android
|
|
712
|
+
// both skip, so playback still starts on the first sample (checked against Apple's decoder: 0 samples late).
|
|
713
|
+
const file = join(OUT, `${name}.m4a`);
|
|
714
|
+
execFileSync('afconvert', ['-f', 'm4af', '-d', 'aac', '-b', '160000', '-q', '127', pcm, file]);
|
|
715
|
+
let peak = 0;
|
|
716
|
+
let sum = 0;
|
|
717
|
+
for (const c of chans) {
|
|
718
|
+
for (const v of c) {
|
|
719
|
+
peak = Math.max(peak, Math.abs(v));
|
|
720
|
+
sum += v * v;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
const rms = Math.sqrt(sum / (chans.length * chans[0].length));
|
|
724
|
+
const db = (v) => (20 * Math.log10(v)).toFixed(1);
|
|
725
|
+
const lufs = phoneLoudness(chans).toFixed(1);
|
|
726
|
+
console.log(
|
|
727
|
+
`${name.padEnd(11)} ${(chans[0].length / SR).toFixed(2)} s ${lufs} LUFS on a phone peak ${db(peak)} dBFS rms ${db(rms)} dBFS -> ${file}`,
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
rmSync(scratch, { recursive: true, force: true });
|