@open-take/compositor 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/dist/cdp-CzT5BKNY.js +3 -0
  2. package/dist/cdp-QXbQfXna.js +373 -0
  3. package/dist/cdp-QXbQfXna.js.map +1 -0
  4. package/dist/index.d.ts +4327 -195
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +26282 -160
  7. package/dist/index.js.map +1 -1
  8. package/dist/server-841PMF2H.js +163 -0
  9. package/dist/server-841PMF2H.js.map +1 -0
  10. package/dist/server-C2aVv4-t.js +3 -0
  11. package/kit/audio.mjs +2366 -0
  12. package/kit/camera.js +587 -0
  13. package/kit/cursor.js +264 -0
  14. package/kit/cut.js +427 -0
  15. package/kit/draw.js +346 -0
  16. package/kit/look.js +589 -0
  17. package/kit/map.js +170 -0
  18. package/kit/media.js +3568 -0
  19. package/kit/motion.js +1115 -0
  20. package/kit/seams.js +1006 -0
  21. package/kit/stage.js +923 -0
  22. package/kit/time.js +812 -0
  23. package/kit/world.js +1072 -0
  24. package/package.json +7 -3
  25. package/src/ffmpeg.ts +63 -0
  26. package/src/film/beats.ts +1285 -0
  27. package/src/film/carry.ts +221 -0
  28. package/src/film/changes.ts +330 -0
  29. package/src/film/check.ts +996 -0
  30. package/src/film/clock.ts +2530 -0
  31. package/src/film/components-probe.ts +809 -0
  32. package/src/film/components.ts +1566 -0
  33. package/src/film/frames.ts +389 -0
  34. package/src/film/gallery.ts +3276 -0
  35. package/src/film/kit.ts +515 -0
  36. package/src/film/layout.ts +701 -0
  37. package/src/film/listen.ts +1979 -0
  38. package/src/film/look.ts +3829 -0
  39. package/src/film/materials.ts +976 -0
  40. package/src/film/moving.ts +248 -0
  41. package/src/film/part-files.ts +729 -0
  42. package/src/film/picture.ts +74 -0
  43. package/src/film/probe-text.ts +843 -0
  44. package/src/film/probe.ts +3456 -0
  45. package/src/film/provenance.ts +596 -0
  46. package/src/film/render.ts +2447 -0
  47. package/src/film/report.ts +1631 -0
  48. package/src/film/sheet.ts +156 -0
  49. package/src/film/study-declared.ts +123 -0
  50. package/src/film/study-picture.ts +791 -0
  51. package/src/film/study-sound.ts +416 -0
  52. package/src/film/study.ts +864 -0
  53. package/src/film/tuning.ts +155 -0
  54. package/src/film/viewer.ts +174 -0
  55. package/src/html/cdp.ts +575 -0
  56. package/src/html/server.ts +208 -0
  57. package/src/index.ts +202 -0
  58. package/src/launch-render.ts +3 -2
  59. package/src/math.ts +3 -3
  60. package/src/mjpeg-matroska.ts +228 -0
  61. package/src/render.ts +6 -4
  62. package/src/state-diff.ts +215 -0
  63. package/src/state-index.ts +99 -0
  64. package/src/types.ts +59 -1
  65. package/starter/PLAN.md +84 -0
  66. package/starter/START.md +460 -0
  67. package/starter/lib/anim.js +760 -0
  68. package/starter/lib/devices.js +1402 -0
  69. package/starter/lib/handoff.js +421 -0
  70. package/starter/lib/hud.js +1879 -0
  71. package/starter/lib/measure.mjs +154 -0
  72. package/starter/lib/moves.js +1095 -0
  73. package/starter/lib/palette.mjs +803 -0
  74. package/starter/lib/physics-seeds.mjs +198 -0
  75. package/starter/lib/physics.js +738 -0
  76. package/starter/lib/sampler.mjs +242 -0
  77. package/starter/lib/solid.js +727 -0
  78. package/starter/lib/space.js +1227 -0
  79. package/starter/lib/swarm.js +1398 -0
  80. package/starter/reference/motion.md +276 -0
  81. package/starter/reference/structure.md +466 -0
  82. package/starter/reference/travel/motion.md +433 -0
  83. package/starter/reference/travel/sound.md +241 -0
  84. package/starter/reference/travel/structure.md +518 -0
  85. package/starter/samples/NOTICE.txt +55 -0
  86. package/starter/samples/celli/celli_24_1.opus +0 -0
  87. package/starter/samples/celli/celli_24_3.opus +0 -0
  88. package/starter/samples/celli/celli_28_1.opus +0 -0
  89. package/starter/samples/celli/celli_28_3.opus +0 -0
  90. package/starter/samples/celli/celli_31_1.opus +0 -0
  91. package/starter/samples/celli/celli_31_3.opus +0 -0
  92. package/starter/samples/celli/celli_35_1.opus +0 -0
  93. package/starter/samples/celli/celli_35_3.opus +0 -0
  94. package/starter/samples/celli/celli_38_1.opus +0 -0
  95. package/starter/samples/celli/celli_38_3.opus +0 -0
  96. package/starter/samples/celli/celli_41_1.opus +0 -0
  97. package/starter/samples/celli/celli_41_3.opus +0 -0
  98. package/starter/samples/celli/celli_45_1.opus +0 -0
  99. package/starter/samples/celli/celli_45_3.opus +0 -0
  100. package/starter/samples/celli/celli_48_1.opus +0 -0
  101. package/starter/samples/celli/celli_48_3.opus +0 -0
  102. package/starter/samples/celli/celli_52_1.opus +0 -0
  103. package/starter/samples/celli/celli_52_3.opus +0 -0
  104. package/starter/samples/celli/celli_55_1.opus +0 -0
  105. package/starter/samples/celli/celli_55_3.opus +0 -0
  106. package/starter/samples/celli/celli_59_1.opus +0 -0
  107. package/starter/samples/celli/celli_59_3.opus +0 -0
  108. package/starter/samples/celli/celli_62_1.opus +0 -0
  109. package/starter/samples/celli/celli_62_3.opus +0 -0
  110. package/starter/samples/celli/celli_65_1.opus +0 -0
  111. package/starter/samples/celli/celli_65_3.opus +0 -0
  112. package/starter/samples/crash/crash_f_1.flac +0 -0
  113. package/starter/samples/crash/crash_fff_1.flac +0 -0
  114. package/starter/samples/ebass/ebass_0_x.flac +0 -0
  115. package/starter/samples/ebass/ebass_10_x.flac +0 -0
  116. package/starter/samples/ebass/ebass_11_x.flac +0 -0
  117. package/starter/samples/ebass/ebass_1_x.flac +0 -0
  118. package/starter/samples/ebass/ebass_2_x.flac +0 -0
  119. package/starter/samples/ebass/ebass_3_x.flac +0 -0
  120. package/starter/samples/ebass/ebass_4_x.flac +0 -0
  121. package/starter/samples/ebass/ebass_5_x.flac +0 -0
  122. package/starter/samples/ebass/ebass_6_x.flac +0 -0
  123. package/starter/samples/ebass/ebass_7_x.flac +0 -0
  124. package/starter/samples/ebass/ebass_8_x.flac +0 -0
  125. package/starter/samples/ebass/ebass_9_x.flac +0 -0
  126. package/starter/samples/ek_clap/ek_clap_1_1.flac +0 -0
  127. package/starter/samples/ek_hat/ek_hat_1_1.flac +0 -0
  128. package/starter/samples/ek_hat/ek_hat_1_2.flac +0 -0
  129. package/starter/samples/ek_kick/ek_kick_1_1.flac +0 -0
  130. package/starter/samples/ek_kick/ek_kick_1_2.flac +0 -0
  131. package/starter/samples/glock/glock_67_x.flac +0 -0
  132. package/starter/samples/glock/glock_72_x.flac +0 -0
  133. package/starter/samples/glock/glock_79_x.flac +0 -0
  134. package/starter/samples/glock/glock_84_x.flac +0 -0
  135. package/starter/samples/glock/glock_91_x.flac +0 -0
  136. package/starter/samples/glock/glock_96_x.flac +0 -0
  137. package/starter/samples/harp/harp_101_f.opus +0 -0
  138. package/starter/samples/harp/harp_28_f.opus +0 -0
  139. package/starter/samples/harp/harp_31_mp.opus +0 -0
  140. package/starter/samples/harp/harp_35_mf.opus +0 -0
  141. package/starter/samples/harp/harp_38_mf.opus +0 -0
  142. package/starter/samples/harp/harp_41_mf.opus +0 -0
  143. package/starter/samples/harp/harp_45_mf.opus +0 -0
  144. package/starter/samples/harp/harp_48_mf.opus +0 -0
  145. package/starter/samples/harp/harp_52_mf.opus +0 -0
  146. package/starter/samples/harp/harp_55_mf.opus +0 -0
  147. package/starter/samples/harp/harp_59_mf.opus +0 -0
  148. package/starter/samples/harp/harp_62_mf.opus +0 -0
  149. package/starter/samples/harp/harp_65_mf.opus +0 -0
  150. package/starter/samples/harp/harp_69_mf.opus +0 -0
  151. package/starter/samples/harp/harp_72_mf.opus +0 -0
  152. package/starter/samples/harp/harp_76_mf.opus +0 -0
  153. package/starter/samples/harp/harp_79_mf.opus +0 -0
  154. package/starter/samples/harp/harp_83_mf.opus +0 -0
  155. package/starter/samples/harp/harp_86_mf.opus +0 -0
  156. package/starter/samples/harp/harp_89_mf.opus +0 -0
  157. package/starter/samples/harp/harp_93_mf.opus +0 -0
  158. package/starter/samples/harp/harp_95_mf.opus +0 -0
  159. package/starter/samples/harp/harp_98_f.opus +0 -0
  160. package/starter/samples/manifest.json +2951 -0
  161. package/starter/samples/marimba/marimba_29_x.flac +0 -0
  162. package/starter/samples/marimba/marimba_36_x.flac +0 -0
  163. package/starter/samples/marimba/marimba_43_x.flac +0 -0
  164. package/starter/samples/marimba/marimba_47_x.flac +0 -0
  165. package/starter/samples/marimba/marimba_53_x.flac +0 -0
  166. package/starter/samples/marimba/marimba_60_x.flac +0 -0
  167. package/starter/samples/marimba/marimba_67_x.flac +0 -0
  168. package/starter/samples/marimba/marimba_71_x.flac +0 -0
  169. package/starter/samples/marimba/marimba_77_x.flac +0 -0
  170. package/starter/samples/marimba/marimba_84_x.flac +0 -0
  171. package/starter/samples/piano/piano_102_12.opus +0 -0
  172. package/starter/samples/piano/piano_102_16.opus +0 -0
  173. package/starter/samples/piano/piano_102_4.opus +0 -0
  174. package/starter/samples/piano/piano_102_8.opus +0 -0
  175. package/starter/samples/piano/piano_105_12.opus +0 -0
  176. package/starter/samples/piano/piano_105_16.opus +0 -0
  177. package/starter/samples/piano/piano_105_4.opus +0 -0
  178. package/starter/samples/piano/piano_105_8.opus +0 -0
  179. package/starter/samples/piano/piano_108_12.opus +0 -0
  180. package/starter/samples/piano/piano_108_16.opus +0 -0
  181. package/starter/samples/piano/piano_108_4.opus +0 -0
  182. package/starter/samples/piano/piano_108_8.opus +0 -0
  183. package/starter/samples/piano/piano_21_12.opus +0 -0
  184. package/starter/samples/piano/piano_21_16.opus +0 -0
  185. package/starter/samples/piano/piano_21_4.opus +0 -0
  186. package/starter/samples/piano/piano_21_8.opus +0 -0
  187. package/starter/samples/piano/piano_24_12.opus +0 -0
  188. package/starter/samples/piano/piano_24_16.opus +0 -0
  189. package/starter/samples/piano/piano_24_4.opus +0 -0
  190. package/starter/samples/piano/piano_24_8.opus +0 -0
  191. package/starter/samples/piano/piano_27_12.opus +0 -0
  192. package/starter/samples/piano/piano_27_16.opus +0 -0
  193. package/starter/samples/piano/piano_27_4.opus +0 -0
  194. package/starter/samples/piano/piano_27_8.opus +0 -0
  195. package/starter/samples/piano/piano_30_12.opus +0 -0
  196. package/starter/samples/piano/piano_30_16.opus +0 -0
  197. package/starter/samples/piano/piano_30_4.opus +0 -0
  198. package/starter/samples/piano/piano_30_8.opus +0 -0
  199. package/starter/samples/piano/piano_33_12.opus +0 -0
  200. package/starter/samples/piano/piano_33_16.opus +0 -0
  201. package/starter/samples/piano/piano_33_4.opus +0 -0
  202. package/starter/samples/piano/piano_33_8.opus +0 -0
  203. package/starter/samples/piano/piano_36_12.opus +0 -0
  204. package/starter/samples/piano/piano_36_16.opus +0 -0
  205. package/starter/samples/piano/piano_36_4.opus +0 -0
  206. package/starter/samples/piano/piano_36_8.opus +0 -0
  207. package/starter/samples/piano/piano_39_12.opus +0 -0
  208. package/starter/samples/piano/piano_39_16.opus +0 -0
  209. package/starter/samples/piano/piano_39_4.opus +0 -0
  210. package/starter/samples/piano/piano_39_8.opus +0 -0
  211. package/starter/samples/piano/piano_42_12.opus +0 -0
  212. package/starter/samples/piano/piano_42_16.opus +0 -0
  213. package/starter/samples/piano/piano_42_4.opus +0 -0
  214. package/starter/samples/piano/piano_42_8.opus +0 -0
  215. package/starter/samples/piano/piano_45_12.opus +0 -0
  216. package/starter/samples/piano/piano_45_16.opus +0 -0
  217. package/starter/samples/piano/piano_45_4.opus +0 -0
  218. package/starter/samples/piano/piano_45_8.opus +0 -0
  219. package/starter/samples/piano/piano_48_12.opus +0 -0
  220. package/starter/samples/piano/piano_48_16.opus +0 -0
  221. package/starter/samples/piano/piano_48_4.opus +0 -0
  222. package/starter/samples/piano/piano_48_8.opus +0 -0
  223. package/starter/samples/piano/piano_51_12.opus +0 -0
  224. package/starter/samples/piano/piano_51_16.opus +0 -0
  225. package/starter/samples/piano/piano_51_4.opus +0 -0
  226. package/starter/samples/piano/piano_51_8.opus +0 -0
  227. package/starter/samples/piano/piano_54_12.opus +0 -0
  228. package/starter/samples/piano/piano_54_16.opus +0 -0
  229. package/starter/samples/piano/piano_54_4.opus +0 -0
  230. package/starter/samples/piano/piano_54_8.opus +0 -0
  231. package/starter/samples/piano/piano_57_12.opus +0 -0
  232. package/starter/samples/piano/piano_57_16.opus +0 -0
  233. package/starter/samples/piano/piano_57_4.opus +0 -0
  234. package/starter/samples/piano/piano_57_8.opus +0 -0
  235. package/starter/samples/piano/piano_60_12.opus +0 -0
  236. package/starter/samples/piano/piano_60_16.opus +0 -0
  237. package/starter/samples/piano/piano_60_4.opus +0 -0
  238. package/starter/samples/piano/piano_60_8.opus +0 -0
  239. package/starter/samples/piano/piano_63_12.opus +0 -0
  240. package/starter/samples/piano/piano_63_16.opus +0 -0
  241. package/starter/samples/piano/piano_63_4.opus +0 -0
  242. package/starter/samples/piano/piano_63_8.opus +0 -0
  243. package/starter/samples/piano/piano_66_12.opus +0 -0
  244. package/starter/samples/piano/piano_66_16.opus +0 -0
  245. package/starter/samples/piano/piano_66_4.opus +0 -0
  246. package/starter/samples/piano/piano_66_8.opus +0 -0
  247. package/starter/samples/piano/piano_69_12.opus +0 -0
  248. package/starter/samples/piano/piano_69_16.opus +0 -0
  249. package/starter/samples/piano/piano_69_4.opus +0 -0
  250. package/starter/samples/piano/piano_69_8.opus +0 -0
  251. package/starter/samples/piano/piano_72_12.opus +0 -0
  252. package/starter/samples/piano/piano_72_16.opus +0 -0
  253. package/starter/samples/piano/piano_72_4.opus +0 -0
  254. package/starter/samples/piano/piano_72_8.opus +0 -0
  255. package/starter/samples/piano/piano_75_12.opus +0 -0
  256. package/starter/samples/piano/piano_75_16.opus +0 -0
  257. package/starter/samples/piano/piano_75_4.opus +0 -0
  258. package/starter/samples/piano/piano_75_8.opus +0 -0
  259. package/starter/samples/piano/piano_78_12.opus +0 -0
  260. package/starter/samples/piano/piano_78_16.opus +0 -0
  261. package/starter/samples/piano/piano_78_4.opus +0 -0
  262. package/starter/samples/piano/piano_78_8.opus +0 -0
  263. package/starter/samples/piano/piano_81_12.opus +0 -0
  264. package/starter/samples/piano/piano_81_16.opus +0 -0
  265. package/starter/samples/piano/piano_81_4.opus +0 -0
  266. package/starter/samples/piano/piano_81_8.opus +0 -0
  267. package/starter/samples/piano/piano_84_12.opus +0 -0
  268. package/starter/samples/piano/piano_84_16.opus +0 -0
  269. package/starter/samples/piano/piano_84_4.opus +0 -0
  270. package/starter/samples/piano/piano_84_8.opus +0 -0
  271. package/starter/samples/piano/piano_87_12.opus +0 -0
  272. package/starter/samples/piano/piano_87_16.opus +0 -0
  273. package/starter/samples/piano/piano_87_4.opus +0 -0
  274. package/starter/samples/piano/piano_87_8.opus +0 -0
  275. package/starter/samples/piano/piano_90_12.opus +0 -0
  276. package/starter/samples/piano/piano_90_16.opus +0 -0
  277. package/starter/samples/piano/piano_90_4.opus +0 -0
  278. package/starter/samples/piano/piano_90_8.opus +0 -0
  279. package/starter/samples/piano/piano_93_12.opus +0 -0
  280. package/starter/samples/piano/piano_93_16.opus +0 -0
  281. package/starter/samples/piano/piano_93_4.opus +0 -0
  282. package/starter/samples/piano/piano_93_8.opus +0 -0
  283. package/starter/samples/piano/piano_96_12.opus +0 -0
  284. package/starter/samples/piano/piano_96_16.opus +0 -0
  285. package/starter/samples/piano/piano_96_4.opus +0 -0
  286. package/starter/samples/piano/piano_96_8.opus +0 -0
  287. package/starter/samples/piano/piano_99_12.opus +0 -0
  288. package/starter/samples/piano/piano_99_16.opus +0 -0
  289. package/starter/samples/piano/piano_99_4.opus +0 -0
  290. package/starter/samples/piano/piano_99_8.opus +0 -0
  291. package/starter/samples/piano/piano_rel_102_x.opus +0 -0
  292. package/starter/samples/piano/piano_rel_105_x.opus +0 -0
  293. package/starter/samples/piano/piano_rel_108_x.opus +0 -0
  294. package/starter/samples/piano/piano_rel_21_x.opus +0 -0
  295. package/starter/samples/piano/piano_rel_24_x.opus +0 -0
  296. package/starter/samples/piano/piano_rel_27_x.opus +0 -0
  297. package/starter/samples/piano/piano_rel_30_x.opus +0 -0
  298. package/starter/samples/piano/piano_rel_33_x.opus +0 -0
  299. package/starter/samples/piano/piano_rel_36_x.opus +0 -0
  300. package/starter/samples/piano/piano_rel_39_x.opus +0 -0
  301. package/starter/samples/piano/piano_rel_42_x.opus +0 -0
  302. package/starter/samples/piano/piano_rel_45_x.opus +0 -0
  303. package/starter/samples/piano/piano_rel_48_x.opus +0 -0
  304. package/starter/samples/piano/piano_rel_51_x.opus +0 -0
  305. package/starter/samples/piano/piano_rel_54_x.opus +0 -0
  306. package/starter/samples/piano/piano_rel_57_x.opus +0 -0
  307. package/starter/samples/piano/piano_rel_60_x.opus +0 -0
  308. package/starter/samples/piano/piano_rel_63_x.opus +0 -0
  309. package/starter/samples/piano/piano_rel_66_x.opus +0 -0
  310. package/starter/samples/piano/piano_rel_69_x.opus +0 -0
  311. package/starter/samples/piano/piano_rel_72_x.opus +0 -0
  312. package/starter/samples/piano/piano_rel_75_x.opus +0 -0
  313. package/starter/samples/piano/piano_rel_78_x.opus +0 -0
  314. package/starter/samples/piano/piano_rel_81_x.opus +0 -0
  315. package/starter/samples/piano/piano_rel_84_x.opus +0 -0
  316. package/starter/samples/piano/piano_rel_87_x.opus +0 -0
  317. package/starter/samples/piano/piano_rel_90_x.opus +0 -0
  318. package/starter/samples/piano/piano_rel_93_x.opus +0 -0
  319. package/starter/samples/piano/piano_rel_96_x.opus +0 -0
  320. package/starter/samples/piano/piano_rel_99_x.opus +0 -0
  321. package/starter/samples/pizz/pizz_24_2.flac +0 -0
  322. package/starter/samples/pizz/pizz_28_2.flac +0 -0
  323. package/starter/samples/pizz/pizz_31_2.flac +0 -0
  324. package/starter/samples/pizz/pizz_35_2.flac +0 -0
  325. package/starter/samples/pizz/pizz_38_2.flac +0 -0
  326. package/starter/samples/pizz/pizz_41_2.flac +0 -0
  327. package/starter/samples/pizz/pizz_45_2.flac +0 -0
  328. package/starter/samples/pizz/pizz_48_2.flac +0 -0
  329. package/starter/samples/pizz/pizz_52_2.flac +0 -0
  330. package/starter/samples/pizz/pizz_57_2.flac +0 -0
  331. package/starter/samples/pizz/pizz_60_2.flac +0 -0
  332. package/starter/samples/pizz/pizz_64_2.flac +0 -0
  333. package/starter/samples/pizz/pizz_67_2.flac +0 -0
  334. package/starter/samples/pizz/pizz_71_2.flac +0 -0
  335. package/starter/samples/pizz/pizz_74_2.flac +0 -0
  336. package/starter/samples/pk_hat/pk_hat_2_1.flac +0 -0
  337. package/starter/samples/pk_hat/pk_hat_2_2.flac +0 -0
  338. package/starter/samples/pk_hat/pk_hat_6_1.flac +0 -0
  339. package/starter/samples/pk_hat/pk_hat_6_2.flac +0 -0
  340. package/starter/samples/pk_kick/pk_kick_3_1.flac +0 -0
  341. package/starter/samples/pk_kick/pk_kick_3_2.flac +0 -0
  342. package/starter/samples/pk_kick/pk_kick_7_1.flac +0 -0
  343. package/starter/samples/pk_kick/pk_kick_7_2.flac +0 -0
  344. package/starter/samples/pk_ohat/pk_ohat_3_1.flac +0 -0
  345. package/starter/samples/pk_ohat/pk_ohat_3_2.flac +0 -0
  346. package/starter/samples/pk_ohat/pk_ohat_6_1.flac +0 -0
  347. package/starter/samples/pk_ohat/pk_ohat_6_2.flac +0 -0
  348. package/starter/samples/pk_rim/pk_rim_2_1.flac +0 -0
  349. package/starter/samples/pk_rim/pk_rim_2_2.flac +0 -0
  350. package/starter/samples/pk_rim/pk_rim_5_1.flac +0 -0
  351. package/starter/samples/pk_rim/pk_rim_5_2.flac +0 -0
  352. package/starter/samples/pk_snare/pk_snare_3_1.flac +0 -0
  353. package/starter/samples/pk_snare/pk_snare_3_2.flac +0 -0
  354. package/starter/samples/pk_snare/pk_snare_7_1.flac +0 -0
  355. package/starter/samples/pk_snare/pk_snare_7_2.flac +0 -0
  356. package/starter/samples/shaker/shaker_1_1.flac +0 -0
  357. package/starter/samples/shaker/shaker_2_1.flac +0 -0
  358. package/starter/samples/snap/snap_r_1.flac +0 -0
  359. package/starter/samples/snap/snap_r_2.flac +0 -0
  360. package/starter/samples/snap/snap_r_3.flac +0 -0
  361. package/starter/samples/snap/snap_r_4.flac +0 -0
  362. package/starter/samples/snap/snap_r_5.flac +0 -0
  363. package/starter/samples/snap/snap_r_6.flac +0 -0
  364. package/starter/samples/tom/tom_3_1.flac +0 -0
  365. package/starter/samples/tom/tom_3_2.flac +0 -0
  366. package/starter/samples/tom/tom_4_1.flac +0 -0
  367. package/starter/samples/tom/tom_4_2.flac +0 -0
  368. package/starter/samples/vibes/vibes_41_1.opus +0 -0
  369. package/starter/samples/vibes/vibes_41_2.opus +0 -0
  370. package/starter/samples/vibes/vibes_45_1.opus +0 -0
  371. package/starter/samples/vibes/vibes_45_2.opus +0 -0
  372. package/starter/samples/vibes/vibes_48_1.opus +0 -0
  373. package/starter/samples/vibes/vibes_48_2.opus +0 -0
  374. package/starter/samples/vibes/vibes_52_1.opus +0 -0
  375. package/starter/samples/vibes/vibes_52_2.opus +0 -0
  376. package/starter/samples/vibes/vibes_55_1.opus +0 -0
  377. package/starter/samples/vibes/vibes_55_2.opus +0 -0
  378. package/starter/samples/vibes/vibes_59_1.opus +0 -0
  379. package/starter/samples/vibes/vibes_59_2.opus +0 -0
  380. package/starter/samples/vibes/vibes_62_1.opus +0 -0
  381. package/starter/samples/vibes/vibes_62_2.opus +0 -0
  382. package/starter/samples/vibes/vibes_65_1.opus +0 -0
  383. package/starter/samples/vibes/vibes_65_2.opus +0 -0
  384. package/starter/samples/vibes/vibes_69_1.opus +0 -0
  385. package/starter/samples/vibes/vibes_69_2.opus +0 -0
  386. package/starter/samples/vibes/vibes_72_1.opus +0 -0
  387. package/starter/samples/vibes/vibes_72_2.opus +0 -0
  388. package/starter/samples/vibes/vibes_76_1.opus +0 -0
  389. package/starter/samples/vibes/vibes_76_2.opus +0 -0
  390. package/starter/samples/violas/violas_36_1.opus +0 -0
  391. package/starter/samples/violas/violas_36_2.opus +0 -0
  392. package/starter/samples/violas/violas_38_1.opus +0 -0
  393. package/starter/samples/violas/violas_38_2.opus +0 -0
  394. package/starter/samples/violas/violas_40_1.opus +0 -0
  395. package/starter/samples/violas/violas_40_2.opus +0 -0
  396. package/starter/samples/violas/violas_43_1.opus +0 -0
  397. package/starter/samples/violas/violas_43_2.opus +0 -0
  398. package/starter/samples/violas/violas_47_1.opus +0 -0
  399. package/starter/samples/violas/violas_47_2.opus +0 -0
  400. package/starter/samples/violas/violas_50_1.opus +0 -0
  401. package/starter/samples/violas/violas_50_2.opus +0 -0
  402. package/starter/samples/violas/violas_53_1.opus +0 -0
  403. package/starter/samples/violas/violas_53_2.opus +0 -0
  404. package/starter/samples/violas/violas_57_1.opus +0 -0
  405. package/starter/samples/violas/violas_57_2.opus +0 -0
  406. package/starter/samples/violas/violas_60_1.opus +0 -0
  407. package/starter/samples/violas/violas_60_2.opus +0 -0
  408. package/starter/samples/violas/violas_64_1.opus +0 -0
  409. package/starter/samples/violas/violas_64_2.opus +0 -0
  410. package/starter/samples/violas/violas_67_1.opus +0 -0
  411. package/starter/samples/violas/violas_67_2.opus +0 -0
  412. package/starter/samples/violas/violas_71_1.opus +0 -0
  413. package/starter/samples/violas/violas_71_2.opus +0 -0
  414. package/starter/samples/violas/violas_74_1.opus +0 -0
  415. package/starter/samples/violas/violas_74_2.opus +0 -0
  416. package/starter/samples/violins/violins_43_1.opus +0 -0
  417. package/starter/samples/violins/violins_43_2.opus +0 -0
  418. package/starter/samples/violins/violins_45_1.opus +0 -0
  419. package/starter/samples/violins/violins_45_2.opus +0 -0
  420. package/starter/samples/violins/violins_47_1.opus +0 -0
  421. package/starter/samples/violins/violins_47_2.opus +0 -0
  422. package/starter/samples/violins/violins_50_1.opus +0 -0
  423. package/starter/samples/violins/violins_50_2.opus +0 -0
  424. package/starter/samples/violins/violins_54_1.opus +0 -0
  425. package/starter/samples/violins/violins_54_2.opus +0 -0
  426. package/starter/samples/violins/violins_57_1.opus +0 -0
  427. package/starter/samples/violins/violins_57_2.opus +0 -0
  428. package/starter/samples/violins/violins_60_1.opus +0 -0
  429. package/starter/samples/violins/violins_60_2.opus +0 -0
  430. package/starter/samples/violins/violins_64_1.opus +0 -0
  431. package/starter/samples/violins/violins_64_2.opus +0 -0
  432. package/starter/samples/violins/violins_67_1.opus +0 -0
  433. package/starter/samples/violins/violins_67_2.opus +0 -0
  434. package/starter/samples/violins/violins_71_1.opus +0 -0
  435. package/starter/samples/violins/violins_71_2.opus +0 -0
  436. package/starter/samples/violins/violins_74_1.opus +0 -0
  437. package/starter/samples/violins/violins_74_2.opus +0 -0
  438. package/starter/samples/woodblock/woodblock_f_1.flac +0 -0
  439. package/starter/samples/woodblock/woodblock_f_2.flac +0 -0
@@ -0,0 +1,803 @@
1
+ // @ts-check
2
+ // palette.mjs — a score's low foundation, sounds that land on picture, and a
3
+ // card to compare its balance, movement and stereo width. The card comes
4
+ // from six films' soundtracks, read with measure(); its ranges are the span
5
+ // those six covered (see REELS), not a target to mix into.
6
+ //
7
+ // bed(seconds, o) Channels to mix into a bus yourself: a sub on
8
+ // the roots (MIDI note numbers, one per bar)
9
+ // hit(o) a small or big impact as Channels
10
+ // hit(bus, at, o) an impact with its fastest rise on at, lifted
11
+ // 4.8 dB over what the bus already holds there
12
+ // (mix the bed first); `over: [buses]` names what
13
+ // to stand above instead, `over: []` plays `gain`
14
+ // as given
15
+ // hits(bus, moves, o) small hits at camera starts and landings, lifted
16
+ // the same way; a move is { start, end } or
17
+ // { t0, t1 } in seconds
18
+ // build(bus, from, to, o) a rising tone and noise leading into to
19
+ // drop(bus, at, o) the hit on a reveal and a sub glide beneath it
20
+ // whoosh(o) a swept sound; place its loudest moment with
21
+ // play(bus, sound, at, { align: "peak", pan })
22
+ // measure(channels) the figures for a mono or stereo mix
23
+ // score(figures, card?) each figure beside the card's range
24
+ // REELS the six soundtracks' figures and their ranges
25
+ // node lib/palette.mjs [--json] score.wav [other.wav …]
26
+ //
27
+ // The kit's subIn(bus, at) holds the low band (under 80 Hz) down from the
28
+ // start of the bus until at and brings it in 18.3 dB; give it `since` to hold
29
+ // it down only from then. dropOut(bus, at) takes it 19.4 dB down for 1.4 s
30
+ // (`full: true`: the whole bus, 22 dB).
31
+ import { existsSync, realpathSync } from "node:fs";
32
+ import { fileURLToPath } from "node:url";
33
+
34
+ // The fallback finds the kit when Node reads lib/ in place under starter/.
35
+ const localKit = new URL("../kit/audio.mjs", import.meta.url);
36
+ const { biquad, buffer, fade, filterOpen, hitOf, load, loudness, mix, osc, play, rng } =
37
+ /** @type {typeof import("../kit/audio.mjs")} */ (await import(
38
+ existsSync(localKit) ? localKit.href : new URL("../../kit/audio.mjs", import.meta.url).href
39
+ ));
40
+
41
+ /** @typedef {import("../kit/audio.mjs").Channels} Channels */
42
+ /** @typedef {import("../kit/audio.mjs").Signal} Signal */
43
+
44
+ const RATE = 48000;
45
+ /** @param {number} u */
46
+ const clamp = (u) => Math.max(0, Math.min(1, u));
47
+ /** @param {number} u */
48
+ const ease = (u) => (1 - Math.cos(Math.PI * clamp(u))) / 2;
49
+
50
+ /**
51
+ * Sub on MIDI roots, one per bar, repeated. The same rounded sine goes to both
52
+ * sides. `texture` is a faint grain on top of the sub and `harmonic` adds a
53
+ * soft overtone. Leave the mix's grit to the instruments and effects.
54
+ * In DdT1-vziRp3, 0–59.561 s, sub is 4.5 dB below the total, active in 79%
55
+ * of 50 ms windows, with L/R correlation 0.976. Returns stereo Channels of
56
+ * `seconds`; mix them into a bus: mix(bus, bed(seconds)).
57
+ * @param {number} seconds
58
+ * @param {{ roots?: readonly number[], bar?: number, sub?: number, texture?: number,
59
+ * harmonic?: number, width?: number, sampleRate?: number, seed?: number }} [o]
60
+ */
61
+ export function bed(seconds, { roots = [28, 24, 31, 35], bar = 2, sub = 0.12, texture = 0.004,
62
+ harmonic = 0.015, width = 0.65, sampleRate = RATE, seed = 1 } = {}) {
63
+ if (!roots.length || !(bar > 0) || !Number.isFinite(bar)) throw new Error("bed: give it roots and a positive bar length");
64
+ const out = buffer(seconds, { sampleRate });
65
+ const random = rng(seed);
66
+ const grain = biquad("bed grain", "bandpass", { freq: 2200, q: 0.6 }, sampleRate);
67
+ const [left, right] = /** @type {[Signal, Signal]} */ (out);
68
+ const blend = Math.min(0.05, bar / 4);
69
+ for (let b = 0; b * bar < seconds; b++) {
70
+ const at = b * bar;
71
+ const length = Math.min(bar + blend, seconds - at);
72
+ const root = /** @type {number} */ (roots[b % roots.length]);
73
+ const pitch = 440 * 2 ** ((root - 69) / 12);
74
+ const wave = osc("sine", pitch, length, { sampleRate });
75
+ const start = Math.round(at * sampleRate);
76
+ for (let i = 0; i < wave.length && start + i < left.length; i++) {
77
+ const t = i / sampleRate;
78
+ const edge = ease(t / blend) * (1 - ease((t - bar) / blend));
79
+ const sine = wave[i] ?? 0;
80
+ const tone = edge * (sub * Math.tanh(1.25 * sine) + harmonic * (4 * sine ** 3 - 3 * sine));
81
+ left[start + i] = (left[start + i] ?? 0) + tone;
82
+ right[start + i] = (right[start + i] ?? 0) + tone;
83
+ }
84
+ }
85
+ if (texture) {
86
+ for (let i = 0; i < left.length; i++) {
87
+ const shared = texture * grain(2 * random() - 1);
88
+ left[i] = (left[i] ?? 0) + shared + texture * width * grain(2 * random() - 1, 1);
89
+ right[i] = (right[i] ?? 0) + shared + texture * width * grain(2 * random() - 1, 2);
90
+ }
91
+ }
92
+ return fade(out, { in: 0.03, out: 0.12 });
93
+ }
94
+
95
+ /** @typedef {{ size?: "small" | "big", gain?: number, body?: number, sampleRate?: number, seed?: number,
96
+ * over?: Channels | readonly Channels[] | null, lift?: number }} HitOptions */
97
+
98
+ /** what a hit into `bus` stands above: the buses named, nothing for `[]` or
99
+ * null, or — not said — what the bus itself holds before it is struck
100
+ * @param {Channels} bus @param {Channels | readonly Channels[] | null | undefined} over
101
+ * @returns {Channels | readonly Channels[]} */
102
+ const above = (bus, over) => (over === undefined ? [bus] : over === null ? [] : over);
103
+
104
+ /**
105
+ * The gain that lifts the first 10 ms after a hit point `lift` dB over what
106
+ * the buses in `over` hold at `at` (their mid, from 50 ms before to 50 ms
107
+ * after), both across the band and above 1.5 kHz, where its edge is heard;
108
+ * never below `gain`.
109
+ * @param {Channels} sound @param {number} at @param {Channels | readonly Channels[]} over
110
+ * @param {number} lift @param {number} gain
111
+ */
112
+ function liftedGain(sound, at, over, lift, gain) {
113
+ const sampleRate = sound.sampleRate ?? RATE;
114
+ const point = Math.round((hitOf(sound) ?? 0) * sampleRate);
115
+ const own = levels(/** @type {Signal} */ (sound[0]), point, point + Math.round(0.01 * sampleRate), sampleRate);
116
+ const buses = /** @type {readonly Channels[]} */ (Array.isArray(over[0]) || over.length === 0 ? over : [over]);
117
+ const under = [0, 0];
118
+ for (const bus of buses) {
119
+ const fs = bus.sampleRate ?? RATE;
120
+ if (fs !== sampleRate) throw new Error(`hit: over is at ${fs} Hz and the hit at ${sampleRate} Hz`);
121
+ const mid = new Float64Array(bus[0]?.length ?? 0);
122
+ for (const ch of bus) for (let i = 0; i < mid.length; i++) mid[i] = (mid[i] ?? 0) + (ch[i] ?? 0) / bus.length;
123
+ const [full, high] = levels(mid, Math.round((at - 0.05) * fs), Math.round((at + 0.05) * fs), fs);
124
+ under[0] = (under[0] ?? 0) + full;
125
+ under[1] = (under[1] ?? 0) + high;
126
+ }
127
+ // in power, the hit and what is under it add: own·g² + under = under · 10^(lift/10)
128
+ const needed = own.map((mine, i) => (mine > 0 ? Math.sqrt(((under[i] ?? 0) * (10 ** (lift / 10) - 1)) / mine) : 0));
129
+ return Math.max(gain, ...needed);
130
+ }
131
+
132
+ /**
133
+ * The mean square of `from`–`to`, whole and above 1.5 kHz (a highpass that
134
+ * starts 20 ms early to settle).
135
+ * @param {Signal} x @param {number} from @param {number} to @param {number} fs
136
+ * @returns {[number, number]}
137
+ */
138
+ function levels(x, from, to, fs) {
139
+ const a = Math.max(0, from), b = Math.min(x.length, to);
140
+ if (b <= a) return [0, 0];
141
+ const early = Math.max(0, a - Math.round(0.02 * fs));
142
+ const high = biquad("hit lift", "highpass", { freq: 1500 }, fs).run(Float64Array.from(x.subarray(early, b)));
143
+ return [power(x, a, b), power(high, a - early, b - early)];
144
+ }
145
+
146
+ /**
147
+ * A falling low thump, a struck body and a noise edge, with the attack in
148
+ * the first samples. DdT1-vziRp3 at 11.042 s: a +4.8 dB full-band impact;
149
+ * at 4.958 s: a +14.5 dB impact with the low end coming in. A sound on its
150
+ * own is mono, with its hit point at kit hitOf(sound). `gain` is linear and
151
+ * absolute: 1 peaks near −9 dBFS small and −4 dBFS big, before the master
152
+ * is normalized.
153
+ * @overload
154
+ * @param {HitOptions} [o]
155
+ * @returns {Channels}
156
+ */
157
+ /**
158
+ * Mix the impact into a bus, lining up its hit point at `at` (seconds).
159
+ * Its gain rises until its first 10 ms stand `lift` dB over what is under
160
+ * it there, across the band and above 1.5 kHz; `gain` is then the least it
161
+ * plays at. What is under it is what the bus already holds (mix the bed and
162
+ * the music in first), or the buses given as `over` when the hit has a bus
163
+ * of its own; `over: []` (or null) plays `gain` as given, absolute. The
164
+ * 4.8 dB default is the smaller of DdT1-vziRp3's impacts at 11.042 s (10 ms
165
+ * windows against the 100 ms before; the one at 47.625 s stands 13 dB out).
166
+ * @overload
167
+ * @param {Channels} bus @param {number} at @param {HitOptions} [o]
168
+ * @returns {ReturnType<typeof play>}
169
+ */
170
+ /**
171
+ * @param {Channels | HitOptions} [busOrOptions]
172
+ * @param {number} [at] @param {HitOptions} [o]
173
+ */
174
+ export function hit(busOrOptions = {}, at, o = {}) {
175
+ const bus = Array.isArray(busOrOptions) ? busOrOptions : undefined;
176
+ const options = Array.isArray(busOrOptions) ? o : busOrOptions;
177
+ const { size = "small", body = 1, gain = 1, seed = 2 } = options;
178
+ const sampleRate = bus?.sampleRate ?? options.sampleRate ?? RATE;
179
+ const big = size === "big";
180
+ const length = big ? 0.45 : 0.19;
181
+ const wave = osc("sine", (t) => (big ? 37 : 56) + 90 * Math.exp(-t / 0.028), length, { sampleRate });
182
+ const ring = osc("sine", big ? 165 : 240, length, { sampleRate });
183
+ const random = rng(seed);
184
+ const noise = biquad("hit edge", "bandpass", { freq: big ? 2600 : 3700, q: 0.7 }, sampleRate);
185
+ for (let i = 0; i < wave.length; i++) {
186
+ const t = i / sampleRate;
187
+ const thump = (wave[i] ?? 0) * (big ? 0.43 : 0.2) * Math.exp(-t / (big ? 0.095 : 0.042));
188
+ const strike = body * (ring[i] ?? 0) * (big ? 0.18 : 0.12) * Math.exp(-t / 0.025);
189
+ const edge = noise(2 * random() - 1) * (big ? 0.23 : 0.15) * Math.exp(-t / 0.008);
190
+ wave[i] = gain * (thump + strike + edge);
191
+ }
192
+ const sound = Object.assign([wave], { sampleRate });
193
+ const soft = fade(sound, { in: 0.001, out: 0.03 });
194
+ if (!bus) return soft;
195
+ if (at === undefined || !Number.isFinite(at)) throw new Error("hit: give a bus a time in seconds: hit(bus, at, o)");
196
+ const lifted = liftedGain(soft, at, above(bus, options.over), options.lift ?? 4.8, 1);
197
+ return play(bus, soft, at, { align: "hit", gain: lifted });
198
+ }
199
+
200
+ /** @typedef {{ start: number, end: number } | { t0: number, t1: number }} Move */
201
+
202
+ /**
203
+ * Strike the start and landing of each move: `{ start, end }` or
204
+ * `{ t0, t1 }` in seconds, as the moves helpers give them. Landings take the
205
+ * space first when events are closer than `spacing` seconds; a time outside
206
+ * the bus is left out and takes no space. Returns the times struck, in order.
207
+ * DdT1-vziRp3 at 47.625 and 47.750 s: two impacts with a whoosh under the
208
+ * move, 125 ms apart. Each landing stands `lift` dB over what is under it
209
+ * (see hit: the bus as it was before these hits, or `over`) and each start
210
+ * `startGain / endGain` of that, never below the gains themselves; with
211
+ * `over: []` (or null) the gains are absolute.
212
+ * @param {Channels} bus @param {readonly Move[]} moves
213
+ * @param {{ starts?: boolean, startGain?: number, endGain?: number, spacing?: number, seed?: number,
214
+ * over?: Channels | readonly Channels[] | null, lift?: number }} [o]
215
+ */
216
+ export function hits(bus, moves, { starts = true, startGain = 0.32, endGain = 0.48, spacing = 0.1, seed = 3, over, lift = 4.8 } = {}) {
217
+ const ends = endGain === 0 ? [] : moves.map((m) => ({ at: "end" in m ? m.end : m.t1, kind: /** @type {const} */ ("end") }));
218
+ const beginnings = starts && startGain !== 0 ? moves.map((m) => ({ at: "start" in m ? m.start : m.t0, kind: /** @type {const} */ ("start") })) : [];
219
+ /** @param {{ at: number }} a @param {{ at: number }} b */
220
+ const byTime = (a, b) => a.at - b.at;
221
+ /** @type {(typeof ends[number] | typeof beginnings[number])[]} */
222
+ const placed = [];
223
+ const length = (bus[0]?.length ?? 0) / (bus.sampleRate ?? RATE);
224
+ for (const e of [...ends.sort(byTime), ...beginnings.sort(byTime)]) {
225
+ if (!Number.isFinite(e.at)) throw new Error("hits: every move needs a start and end in seconds");
226
+ if (e.at < 0 || e.at >= length) continue;
227
+ if (!placed.some((p) => p.at === e.at || Math.abs(p.at - e.at) + 1e-9 < spacing)) placed.push(e);
228
+ }
229
+ // the bus as it is before any of these hits: one hit's tail is not what
230
+ // the next must stand above
231
+ const under = above(over === undefined ? Object.assign(bus.map((ch) => Float32Array.from(ch)), { sampleRate: bus.sampleRate }) : bus, over);
232
+ placed.sort(byTime).forEach(({ at, kind }, i) => {
233
+ const gain = kind === "start" ? startGain : endGain;
234
+ // the lift a landing here would need, given to a start in proportion
235
+ const unit = hit({ seed: seed + i, sampleRate: bus.sampleRate });
236
+ const lifted = endGain > 0 ? liftedGain(unit, at, under, lift, endGain) * gain / endGain : gain;
237
+ play(bus, unit, at, { align: "hit", gain: lifted });
238
+ });
239
+ return placed;
240
+ }
241
+
242
+ /**
243
+ * Rising filtered noise and a rising saw, growing as time to the power of
244
+ * 2.2 and releasing into `to`. A `filterBus` stays dry until `from`, closes
245
+ * briefly and then opens toward its high cutoff at `to`. DdT1-vziRp3 at
246
+ * 9.375 s has an upsweep into a boom and Df-JzBcCrDo at
247
+ * 1.7 s: the high end opens. The shared cue at 6–10 s rises three octaves.
248
+ * @param {Channels} bus @param {number} from @param {number} to
249
+ * @param {{ gain?: number, seed?: number, filterBus?: Channels }} [o]
250
+ */
251
+ export function build(bus, from, to, { gain = 0.45, seed = 4, filterBus } = {}) {
252
+ const duration = to - from;
253
+ if (!(duration > 0) || !Number.isFinite(duration)) throw new Error("build: to must be after from");
254
+ const sampleRate = bus.sampleRate ?? RATE;
255
+ const wave = osc("saw", (t) => 110 * 8 ** (t / duration), duration, { sampleRate });
256
+ const random = rng(seed);
257
+ const tone = biquad("build tone", "lowpass", { freq: 400 }, sampleRate);
258
+ const noise = biquad("build noise", "bandpass", { freq: 300, q: 2.5 }, sampleRate);
259
+ for (let i = 0; i < wave.length; i++) {
260
+ const u = i / wave.length;
261
+ if (i % 32 === 0) {
262
+ tone.set({ freq: 400 * 17.5 ** u });
263
+ noise.set({ freq: 300 * 30 ** u });
264
+ }
265
+ wave[i] = (0.12 * tone(wave[i] ?? 0) + 0.55 * noise(2 * random() - 1)) * u ** 2.2;
266
+ }
267
+ const sound = Object.assign([wave], { sampleRate });
268
+ if (filterBus) {
269
+ const close = Math.min(0.04, duration / 2);
270
+ filterOpen(filterBus, from + close, to, { since: from, fade: close });
271
+ }
272
+ return play(bus, fade(sound, { in: 0, out: 0.012 }), from, { gain });
273
+ }
274
+
275
+ /**
276
+ * The hit at a reveal, plus a falling sine under it. DdT1-vziRp3 at 4.958 s:
277
+ * +14.5 dB across the mix and +27.9 dB below 80 Hz. The shared cue at 16 s
278
+ * lets the low sine fall from 95 to 27 Hz over 1.6 s. `gain` is the hit's,
279
+ * absolute: it is not lifted over what the bus holds.
280
+ * @param {Channels} bus @param {number} at
281
+ * @param {{ gain?: number, sub?: number, duration?: number, seed?: number }} [o]
282
+ */
283
+ export function drop(bus, at, { gain = 0.8, sub = 0.18, duration = 1.6, seed = 5 } = {}) {
284
+ const sampleRate = bus.sampleRate ?? RATE;
285
+ const wave = osc("sine", (t) => 95 * (27 / 95) ** (t / duration), duration, { sampleRate });
286
+ for (let i = 0; i < wave.length; i++)
287
+ wave[i] = sub * Math.tanh(1.25 * (wave[i] ?? 0)) * Math.exp(-3 * i / wave.length);
288
+ mix(bus, fade(Object.assign([wave], { sampleRate }), { in: 0.008, out: 0.08 }), at);
289
+ // the reveal's hit lands on the build and the sub under it: its gain is
290
+ // the level, not a lift over them
291
+ return hit(bus, at, { size: "big", gain, seed, over: null });
292
+ }
293
+
294
+ /**
295
+ * A mono sweep from low to high and back, about a second wide. DdT1-vziRp3
296
+ * at 14.875 s: a whoosh and +8.6 dB below 80 Hz. Place its strongest sample
297
+ * with play(bus, sound, at, { align: "peak", pan }) and make `pan` follow
298
+ * the move in film time.
299
+ * @param {{ duration?: number, gain?: number, seed?: number, sampleRate?: number }} [o]
300
+ */
301
+ export function whoosh({ duration = 0.85, gain = 0.42, seed = 6, sampleRate = RATE } = {}) {
302
+ const sound = buffer(duration, { channels: 1, sampleRate });
303
+ const wave = /** @type {Signal} */ (sound[0]);
304
+ const random = rng(seed);
305
+ const filter = biquad("whoosh", "bandpass", { freq: 420, q: 0.78 }, sampleRate);
306
+ for (let i = 0; i < wave.length; i++) {
307
+ const arc = Math.sin(Math.PI * i / Math.max(1, wave.length - 1));
308
+ if (i % 32 === 0) filter.set({ freq: 420 * 11 ** arc });
309
+ wave[i] = gain * arc ** 3 * filter(2 * random() - 1);
310
+ }
311
+ return sound;
312
+ }
313
+
314
+ /** @typedef {[b0: number, b1: number, b2: number, a1: number, a2: number]} Section */
315
+
316
+ /**
317
+ * The two conjugate pole pairs of a fourth-order Butterworth. For a band,
318
+ * turn each lowpass pole into two bandpass poles before the bilinear transform.
319
+ * @param {number} lo @param {number} hi @param {number} fs @returns {Section[]}
320
+ */
321
+ function butterworth(lo, hi, fs) {
322
+ const low = Math.tan(Math.PI * lo / fs);
323
+ const high = Math.tan(Math.PI * hi / fs);
324
+ const center = Math.sqrt(low * high);
325
+ /** @type {Section[]} */
326
+ const sections = [];
327
+ for (const angle of [Math.PI / 8, 3 * Math.PI / 8]) {
328
+ if (lo === 0 || hi === fs / 2) {
329
+ const cutoff = lo === 0 ? high : low;
330
+ const norm = 1 / (1 + 2 * Math.sin(angle) * cutoff + cutoff ** 2);
331
+ const b = norm * (lo === 0 ? cutoff ** 2 : 1);
332
+ sections.push([b, (lo === 0 ? 2 : -2) * b, b,
333
+ 2 * (cutoff ** 2 - 1) * norm, (1 - 2 * Math.sin(angle) * cutoff + cutoff ** 2) * norm]);
334
+ continue;
335
+ }
336
+ const width = high - low;
337
+ const re = -Math.sin(angle) * width;
338
+ const im = Math.cos(angle) * width;
339
+ const x = re ** 2 - im ** 2 - 4 * center ** 2;
340
+ const y = 2 * re * im;
341
+ const magnitude = Math.hypot(x, y);
342
+ const rootRe = Math.sqrt(Math.max(0, (magnitude + x) / 2));
343
+ const rootIm = -Math.sqrt((magnitude - x) / 2);
344
+ const omega = 2 * Math.atan(center);
345
+ for (const sign of [-1, 1]) {
346
+ const u = (re + sign * rootRe) / 2;
347
+ const v = (im + sign * rootIm) / 2;
348
+ const d = (1 - u) ** 2 + v ** 2;
349
+ const a1 = -2 * (1 - u ** 2 - v ** 2) / d;
350
+ const a2 = ((1 + u) ** 2 + v ** 2) / d;
351
+ const b = Math.hypot((1 + a2) * Math.cos(omega) + a1, (1 - a2) * Math.sin(omega)) /
352
+ (2 * Math.sin(omega));
353
+ sections.push([b, 0, -b, a1, a2]);
354
+ }
355
+ }
356
+ return sections;
357
+ }
358
+
359
+ /**
360
+ * Run a band forwards and backwards with the sound mirrored at its ends.
361
+ * The second pass removes the phase shift so window levels stay in time.
362
+ * The mirror is eight periods of the lowest cutoff long, so the filter has
363
+ * settled before it reaches the sound, and a mirror (not a reflection about
364
+ * the end sample) adds no offset when a sound ends mid-cycle: read
365
+ * backwards, a sound gives the same figures.
366
+ * @param {Signal} source @param {number} lo @param {number} hi @param {number} fs
367
+ */
368
+ function band(source, lo, hi, fs) {
369
+ const n = source.length;
370
+ if (lo >= fs / 2 || n === 0) return new Float64Array(n);
371
+ if (lo === 0 && hi >= fs / 2) return source;
372
+ const sections = butterworth(lo, Math.min(hi, fs / 2), fs);
373
+ const pad = Math.min(n - 1, Math.ceil((8 * fs) / (lo > 0 ? lo : hi)));
374
+ const x = new Float64Array(n + 2 * pad);
375
+ x.set(source, pad);
376
+ for (let i = 1; i <= pad; i++) {
377
+ x[pad - i] = source[i] ?? 0;
378
+ x[pad + n - 1 + i] = source[n - 1 - i] ?? 0;
379
+ }
380
+ for (let pass = 0; pass < 2; pass++) {
381
+ for (const [b0, b1, b2, a1, a2] of sections) {
382
+ let x1 = x[0] ?? 0, x2 = x1;
383
+ let y1 = x1 * (b0 + b1 + b2) / (1 + a1 + a2), y2 = y1;
384
+ for (let i = 0; i < x.length; i++) {
385
+ const v = x[i] ?? 0;
386
+ const y = b0 * v + b1 * x1 + b2 * x2 - a1 * y1 - a2 * y2;
387
+ x[i] = y;
388
+ x2 = x1;
389
+ x1 = v;
390
+ y2 = y1;
391
+ y1 = y;
392
+ }
393
+ }
394
+ x.reverse();
395
+ }
396
+ return x.subarray(pad, pad + n);
397
+ }
398
+
399
+ /** @param {number} p */
400
+ const powerDb = (p) => 10 * Math.log10(Math.max(p, 1e-20));
401
+ /** Mean square below this (−70 dB, the absolute gate of BS.1770) is silence: a
402
+ * window or frame of it is left out of the level spread, centroid and flatness. */
403
+ const SILENT = 1e-7;
404
+ /** @param {Signal} x @param {number} [from] @param {number} [to] */
405
+ function power(x, from = 0, to = x.length) {
406
+ let sum = 0;
407
+ for (let i = from; i < to; i++) sum += (x[i] ?? 0) ** 2;
408
+ return sum / Math.max(1, to - from);
409
+ }
410
+
411
+ /** @param {Signal} left @param {Signal} right */
412
+ function correlation(left, right) {
413
+ let cross = 0, l2 = 0, r2 = 0;
414
+ for (let i = 0; i < left.length; i++) {
415
+ const l = left[i] ?? 0, r = right[i] ?? 0;
416
+ cross += l * r;
417
+ l2 += l * l;
418
+ r2 += r * r;
419
+ }
420
+ return l2 && r2 ? Math.max(-1, Math.min(1, cross / Math.sqrt(l2 * r2))) : 0;
421
+ }
422
+
423
+ /** @param {number[]} sorted ascending @param {number} q */
424
+ function percentile(sorted, q) {
425
+ if (!sorted.length) return 0;
426
+ const j = (sorted.length - 1) * q;
427
+ const i = Math.floor(j);
428
+ const below = sorted[i] ?? 0;
429
+ return below + (j - i) * ((sorted[Math.ceil(j)] ?? below) - below);
430
+ }
431
+
432
+ /**
433
+ * A Hann window and a radix-2 FFT of real samples, centred at the named
434
+ * sample and zero-padded past the ends. Reuse the work arrays for each hop.
435
+ * @param {Signal} signal @param {number} n
436
+ */
437
+ function spectrum(signal, n) {
438
+ const order = new Uint16Array(n);
439
+ const window = new Float64Array(n);
440
+ const re = new Float64Array(n), im = new Float64Array(n);
441
+ const cos = new Float64Array(n / 2), sin = new Float64Array(n / 2);
442
+ const powers = new Float64Array(n / 2 + 1);
443
+ for (let i = 0; i < n; i++) {
444
+ order[i] = ((order[i >> 1] ?? 0) >> 1) | ((i & 1) * (n / 2));
445
+ window[i] = 0.5 - 0.5 * Math.cos(2 * Math.PI * i / n);
446
+ }
447
+ for (let k = 0; k < n / 2; k++) {
448
+ cos[k] = Math.cos(-2 * Math.PI * k / n);
449
+ sin[k] = Math.sin(-2 * Math.PI * k / n);
450
+ }
451
+ /** @param {number} center */
452
+ return (center) => {
453
+ const first = center - n / 2;
454
+ for (let i = 0; i < n; i++) re[order[i] ?? 0] = (signal[first + i] ?? 0) * (window[i] ?? 0);
455
+ im.fill(0);
456
+ for (let span = 2; span <= n; span *= 2) {
457
+ const half = span / 2, stride = n / span;
458
+ for (let from = 0; from < n; from += span) {
459
+ for (let j = 0; j < half; j++) {
460
+ const a = from + j, b = a + half, k = j * stride;
461
+ const rb = re[b] ?? 0, ib = im[b] ?? 0;
462
+ const ra = re[a] ?? 0, ia = im[a] ?? 0;
463
+ const c = cos[k] ?? 0, s = sin[k] ?? 0;
464
+ const r = c * rb - s * ib;
465
+ const v = s * rb + c * ib;
466
+ re[b] = ra - r;
467
+ im[b] = ia - v;
468
+ re[a] = ra + r;
469
+ im[a] = ia + v;
470
+ }
471
+ }
472
+ }
473
+ for (let k = 0; k < powers.length; k++) powers[k] = ((re[k] ?? 0) ** 2 + (im[k] ?? 0) ** 2) * (2 / n) ** 2;
474
+ return powers;
475
+ };
476
+ }
477
+
478
+ /** @param {Signal} mid @param {number} fs @returns {[number, number]} */
479
+ function brightness(mid, fs) {
480
+ const n = 4096, hop = 2048;
481
+ const read = spectrum(mid, n);
482
+ // the frame's mean square as the window weighs it (3/8 is the mean of a Hann window squared)
483
+ /** @param {number} center */
484
+ const weighed = (center) => {
485
+ let sum = 0;
486
+ for (let j = Math.max(0, center - n / 2); j < Math.min(mid.length, center + n / 2); j++)
487
+ sum += ((mid[j] ?? 0) * (0.5 - 0.5 * Math.cos((2 * Math.PI * (j - center + n / 2)) / n))) ** 2;
488
+ return sum / (n * 3 / 8);
489
+ };
490
+ const lo = Math.ceil(200 * n / fs), hi = Math.min(n / 2, Math.floor(8000 * n / fs));
491
+ /** @type {number[]} */
492
+ const centroids = [], flatness = [];
493
+ for (let i = 0; i < Math.ceil(mid.length / hop) * hop + 1; i += hop) {
494
+ if (weighed(i) < SILENT) continue;
495
+ const p = read(i);
496
+ let total = 0, weighted = 0, sum = 0, logs = 0;
497
+ for (let k = 0; k < p.length; k++) {
498
+ const energy = p[k] ?? 0;
499
+ total += energy;
500
+ weighted += k * energy;
501
+ if (k >= lo && k <= hi) {
502
+ const bin = energy + 1e-20;
503
+ sum += bin;
504
+ logs += Math.log(bin);
505
+ }
506
+ }
507
+ centroids.push((fs / n) * weighted / (total + 1e-20));
508
+ const bins = hi - lo + 1;
509
+ if (bins > 0) flatness.push(Math.exp(logs / bins) / (sum / bins));
510
+ }
511
+ return [percentile(centroids.sort((a, b) => a - b), 0.5),
512
+ percentile(flatness.sort((a, b) => a - b), 0.5)];
513
+ }
514
+
515
+ /**
516
+ * Positive spectral flux on log-compressed magnitudes (1024 Hann, 256 hop
517
+ * at 48 kHz). Keep peaks above their local mean plus half a standard
518
+ * deviation and a small floor, with at least 45 ms between peaks. The
519
+ * compression is relative to the track RMS, so gain alone leaves the count.
520
+ * @param {Signal} mid @param {number} fs @param {number} energy
521
+ */
522
+ function onsetRate(mid, fs, energy) {
523
+ if (!energy) return 0;
524
+ const n = Math.max(16, Math.min(32768, 2 ** Math.round(Math.log2(fs * 1024 / RATE))));
525
+ const hop = n / 4;
526
+ const read = spectrum(mid, n);
527
+ const previous = new Float64Array(n / 2 + 1);
528
+ const flux = new Float64Array(Math.ceil(mid.length / hop));
529
+ const scale = 12 / Math.sqrt(energy);
530
+ for (let i = 0; i < flux.length; i++) {
531
+ const p = read(i * hop);
532
+ let rise = 0;
533
+ for (let k = 1; k < p.length; k++) {
534
+ const value = Math.log1p(scale * Math.sqrt(p[k] ?? 0));
535
+ rise += Math.max(0, value - (previous[k] ?? 0));
536
+ previous[k] = value;
537
+ }
538
+ flux[i] = rise / (p.length - 1);
539
+ }
540
+ const radius = Math.max(1, Math.round(0.12 * fs / hop));
541
+ const gap = Math.ceil(0.045 * fs / hop);
542
+ let count = 0, last = -gap;
543
+ for (let i = 0; i < flux.length; i++) {
544
+ const value = flux[i] ?? 0;
545
+ if (i - last < gap || value <= (flux[i - 1] ?? 0) || value < (flux[i + 1] ?? 0)) continue;
546
+ let sum = 0, squares = 0, size = 0;
547
+ for (let j = Math.max(0, i - radius); j <= Math.min(flux.length - 1, i + radius); j++) {
548
+ const other = flux[j] ?? 0;
549
+ sum += other;
550
+ squares += other ** 2;
551
+ size++;
552
+ }
553
+ const mean = sum / size;
554
+ if (value > mean + 0.5 * Math.sqrt(Math.max(0, squares / size - mean ** 2)) + 0.003) {
555
+ count++;
556
+ last = i;
557
+ }
558
+ }
559
+ return count * fs / mid.length;
560
+ }
561
+
562
+ const figures = /** @type {const} */ ([
563
+ ["lufs", "Integrated", "LUFS", 1],
564
+ ["levelSpread", "1 s p95−p10", "dB", 1],
565
+ ["sub", "Sub <60 Hz", "dB", 1],
566
+ ["low", "Low 60–250 Hz", "dB", 1],
567
+ ["mid", "Mid 250 Hz–2 kHz", "dB", 1],
568
+ ["presence", "Presence 2–6 kHz", "dB", 1],
569
+ ["air", "Air 6–16 kHz", "dB", 1],
570
+ ["subActive", "Sub active share", "%", 1],
571
+ ["subCrest", "Sub crest", "dB", 1],
572
+ ["centroid", "Median centroid", "Hz", 0],
573
+ ["flatness", "Median flatness", "", 4],
574
+ ["onsets", "Onsets", "/s", 2],
575
+ ["correlation", "L/R correlation", "", 3],
576
+ ["subCorrelation", "Sub L/R correlation", "", 3],
577
+ ["sideMid", "Side − mid", "dB", 1],
578
+ ]);
579
+
580
+ /** @typedef {typeof figures[number][0]} Figure */
581
+ /** @typedef {Record<Figure, number>} Figures */
582
+ /** @typedef {Record<Figure, readonly [number, number]>} Ranges */
583
+ /** @typedef {{ range: Ranges, openAbove?: readonly Figure[] }} Card */
584
+
585
+ /**
586
+ * Mono or stereo, measured at its own rate (48 kHz if absent). Energy and
587
+ * spectra are of the stereo mid, (L+R)/2; band balance is against the entire
588
+ * mid. Sub activity and crest use the 20–60 Hz band, in 50 ms windows, and
589
+ * activity counts windows less than 20 dB below p99. The level spread uses
590
+ * 1 s windows with a 0.5 s hop. The spread, centroid and flatness leave out
591
+ * windows and frames quieter than −70 dB, so a silent lead-in or tail does not
592
+ * count as the film's quietest moment or darkest sound. Correlation is the
593
+ * dot product divided by the two lengths. Silence has zero correlation, no
594
+ * active sub, no onsets and zero spread, centroid and flatness; integrated
595
+ * loudness can be −Infinity, as in kit loudness().
596
+ * @param {Channels} channels @returns {Figures}
597
+ */
598
+ export function measure(channels) {
599
+ const fs = channels.sampleRate ?? RATE;
600
+ if (!(fs > 0) || !Number.isFinite(fs)) throw new Error("measure: give it a positive sample rate");
601
+ const [left, right = left] = channels;
602
+ if (!left || !right || channels.length > 2) throw new Error("measure: give it mono or stereo");
603
+ if (left.length !== right.length) throw new Error("measure: channels need the same length");
604
+ const mid = new Float64Array(left.length);
605
+ let side = 0;
606
+ for (let i = 0; i < mid.length; i++) {
607
+ const l = left[i] ?? 0, r = right[i] ?? 0;
608
+ if (!Number.isFinite(l) || !Number.isFinite(r)) throw new Error("measure: diagnose the nonfinite samples first");
609
+ mid[i] = (l + r) / 2;
610
+ side += ((l - r) / 2) ** 2;
611
+ }
612
+ const total = power(mid);
613
+ const zeroSub = band(left, 0, 60, fs);
614
+ const subRight = right === left ? zeroSub : band(right, 0, 60, fs);
615
+ const [centroid, flatness] = brightness(mid, fs);
616
+ const sub = band(mid, 20, 60, fs);
617
+ /** @type {number[]} */
618
+ const subLevels = [], levels = [];
619
+ const w = Math.max(1, Math.round(0.05 * fs));
620
+ for (let i = 0; i + w <= sub.length; i += w) subLevels.push(power(sub, i, i + w));
621
+ subLevels.sort((a, b) => a - b);
622
+ const p99 = percentile(subLevels, 0.99);
623
+ const second = Math.max(1, Math.round(fs));
624
+ for (let i = 0; i + second <= mid.length; i += Math.max(1, Math.round(fs / 2))) {
625
+ const level = power(mid, i, i + second);
626
+ if (level >= SILENT) levels.push(powerDb(level));
627
+ }
628
+ levels.sort((a, b) => a - b);
629
+ /** @param {number} lo @param {number} hi */
630
+ const balance = (lo, hi) => powerDb(power(band(mid, lo, hi, fs))) - powerDb(total);
631
+ return {
632
+ lufs: loudness(channels).lufs,
633
+ levelSpread: percentile(levels, 0.95) - percentile(levels, 0.10),
634
+ sub: balance(0, 60),
635
+ low: balance(60, 250),
636
+ mid: balance(250, 2000),
637
+ presence: balance(2000, 6000),
638
+ air: balance(6000, 16000),
639
+ subActive: p99 > 1e-20 ? subLevels.filter((p) => p > p99 / 100).length / subLevels.length : 0,
640
+ subCrest: powerDb(p99) - powerDb(percentile(subLevels, 0.5)),
641
+ centroid,
642
+ flatness,
643
+ onsets: onsetRate(mid, fs, total),
644
+ correlation: correlation(left, right),
645
+ subCorrelation: correlation(zeroSub, subRight),
646
+ sideMid: powerDb(side / Math.max(1, mid.length)) - powerDb(total),
647
+ };
648
+ }
649
+
650
+ // Read with measure() from six Higgsfield films' soundtracks (stereo, 48 kHz,
651
+ // decoded from AAC): three reels (Dfj2vYxC1pE, Df-JzBcCrDo, DdT1-vziRp3) and
652
+ // three product introductions (dots-creative-crew, mangaka,
653
+ // opus55-monster-truck). Python's other onset detector counted 9.39, 5.91
654
+ // and 10.98/s on the three reels; its flux and peak picking use different
655
+ // windows and thresholds.
656
+ const reels = /** @type {Record<string, Figures>} */ ({
657
+ Dfj2vYxC1pE: {
658
+ lufs: -6.911419472941821, levelSpread: 8.902107971431848, sub: -5.9470804487973865,
659
+ low: -6.144053271312181, mid: -4.6122744713375905, presence: -14.228089168761617, air: -21.79291665375893,
660
+ subActive: 0.7100068073519401, subCrest: 14.617564115420896, centroid: 588.8829945194445,
661
+ flatness: 0.023150936108495883, onsets: 6.748982252455818, correlation: 0.6409066269369512,
662
+ subCorrelation: 0.8605066267322765, sideMid: -6.594788540925656,
663
+ },
664
+ "Df-JzBcCrDo": {
665
+ lufs: -5.382372064878215, levelSpread: 2.477016110042035, sub: -10.014264030884277,
666
+ low: -4.523070158472883, mid: -5.180523933938083, presence: -8.97282585885085, air: -15.895319211405248,
667
+ subActive: 0.8957597173144877, subCrest: 10.542656965010497, centroid: 1087.5252037115679,
668
+ flatness: 0.12320052053314569, onsets: 8.384678530895195, correlation: 0.6779534689956599,
669
+ subCorrelation: 0.9028305000529029, sideMid: -7.167748792819349,
670
+ },
671
+ "DdT1-vziRp3": {
672
+ lufs: -14.137213201872706, levelSpread: 6.5363841073814495, sub: -4.529622642647862,
673
+ low: -6.2946024509613885, mid: -8.359582246449023, presence: -14.042793833069247, air: -16.38062662747727,
674
+ subActive: 0.7858942065491183, subCrest: 7.8091155304128, centroid: 549.7500635210537,
675
+ flatness: 0.13933812087766764, onsets: 9.922666303824291, correlation: 0.8711856222678308,
676
+ subCorrelation: 0.9760010660763156, sideMid: -11.620843836607769,
677
+ },
678
+ "dots-creative-crew": {
679
+ lufs: -7.523354104489741, levelSpread: 5.79022036260552, sub: -11.81376256639109, low: -3.914476066636132,
680
+ mid: -5.822247387482848, presence: -11.133487096255285, air: -12.862823817782102,
681
+ subActive: 0.7432885906040269, subCrest: 12.247565388935802, centroid: 1168.4929261377074,
682
+ flatness: 0.19654763330500222, onsets: 9.14020572450805, correlation: 0.6695650280679405,
683
+ subCorrelation: 0.8848033594436251, sideMid: -7.034946005881418,
684
+ },
685
+ mangaka: {
686
+ lufs: -8.521110214624766, levelSpread: 9.646150385092424, sub: -9.627392605539532,
687
+ low: -3.930063788569898, mid: -6.080412268000535, presence: -10.433405372088346, air: -15.950772360425328,
688
+ subActive: 0.3688394276629571, subCrest: 25.44485250340977, centroid: 904.4275548914877,
689
+ flatness: 0.12717058307958895, onsets: 8.040254237288135, correlation: 0.7077655518879712,
690
+ subCorrelation: 0.9487258190680528, sideMid: -7.664509466698389,
691
+ },
692
+ "opus55-monster-truck": {
693
+ lufs: -7.523351805070418, levelSpread: 4.516415065687423, sub: -8.452518659265385,
694
+ low: -3.0484715770723287, mid: -8.495858853159161, presence: -12.777064956443615,
695
+ air: -15.716355317543618, subActive: 0.5169491525423728, subCrest: 19.465556070845786,
696
+ centroid: 629.9628915111149, flatness: 0.1925545468742373, onsets: 8.062693698347108,
697
+ correlation: 0.8746699524965276, subCorrelation: 0.9821821551281439, sideMid: -11.74869178406115,
698
+ },
699
+ });
700
+ const keys = figures.map(([key]) => key);
701
+
702
+ /**
703
+ * The six soundtracks, the lowest and highest each figure reached among
704
+ * them (n = 6), and where a higher value fits. A range is only the span six
705
+ * films happened to cover, not a norm: rebuilt from any five, each left-out
706
+ * film has 3 to 8 of its 14 figures outside (Dfj2vYxC1pE 8, DdT1-vziRp3 5,
707
+ * dots-creative-crew and opus55-monster-truck 4, Df-JzBcCrDo and mangaka 3).
708
+ * Inside says a figure is somewhere one of these films went; outside, by a
709
+ * little, is as common among them as inside. Read a score as where to look,
710
+ * then listen; mixing to put every figure inside can make a score worse.
711
+ */
712
+ export const REELS = {
713
+ reels,
714
+ range: /** @type {Ranges} */ (Object.fromEntries(keys.map((key) => {
715
+ const values = Object.values(reels).map((reel) => reel[key]);
716
+ return [key, /** @type {const} */ ([Math.min(...values), Math.max(...values)])];
717
+ }))),
718
+ // Bass can be fully mono. Keep sub activity two-sided to show a floor
719
+ // that holds nearly all the time, including through changes in level.
720
+ openAbove: /** @type {readonly Figure[]} */ (["subCorrelation"]),
721
+ };
722
+
723
+ // Keep loudness for comparison because the film master is set to −16 LUFS.
724
+ const loudnessNote = "film scores are mastered to −16 LUFS";
725
+
726
+ /** @param {number} value @param {typeof figures[number]} row */
727
+ function number(value, [, , unit, places]) {
728
+ const scaled = unit === "%" ? 100 * value : value;
729
+ return scaled.toFixed(places).replace("-", "−");
730
+ }
731
+
732
+ /**
733
+ * Read each figure against the card. `distance` is zero inside the inclusive
734
+ * bounds, otherwise the distance to the nearest bound in the figure's units
735
+ * (subActive is a share). `openAbove` names figures with no upper scoring
736
+ * limit. Loudness is shown with null for `inside`, `distance` and `direction`.
737
+ * Pass a different card to compare other films.
738
+ * @param {Figures} values @param {Card} [card]
739
+ * @returns {Record<Figure, { value: number, range: readonly [number, number], inside: boolean | null,
740
+ * openAbove: boolean, distance: number | null, direction: "above" | "below" | null, reading: string }>}
741
+ */
742
+ export function score(values, card = REELS) {
743
+ return /** @type {ReturnType<typeof score>} */ (Object.fromEntries(figures.map((row) => {
744
+ const [key, label, unit] = row;
745
+ const value = values[key];
746
+ const range = card.range[key];
747
+ const [lo, hi] = range;
748
+ const suffix = unit === "%" || unit === "/s" ? unit : unit ? " " + unit : "";
749
+ const comparison = `${label}: ${number(value, row)}${suffix}, the six films ${number(lo, row)}…${number(hi, row)}${suffix}`;
750
+ if (key === "lufs") return [key, { value, range, inside: null, openAbove: false,
751
+ distance: null, direction: null, reading: `${comparison} (informational because ${loudnessNote})` }];
752
+ if (Number.isNaN(value) || typeof value !== "number") throw new Error(`score: ${key} is ${value}, not a number`);
753
+ const openAbove = card.openAbove?.includes(key) ?? false;
754
+ const direction = value < lo ? "below" : !openAbove && value > hi ? "above" : null;
755
+ const distance = direction === "below" ? lo - value : direction === "above" ? value - hi : 0;
756
+ const amount = unit === "%" ? `${number(distance, row)} percentage points` : number(distance, row) + suffix;
757
+ const reading = `${comparison}; ` + (direction ? `${amount} ${direction} the range` : "in range") +
758
+ (openAbove ? " (higher values fit)" : "");
759
+ return [key, { value, range, inside: direction === null, openAbove, distance, direction, reading }];
760
+ })));
761
+ }
762
+
763
+ /** @param {string[]} args */
764
+ function main(args) {
765
+ const paths = args.filter((arg) => arg !== "--json");
766
+ if (paths.length === 0) {
767
+ console.error("usage: node lib/palette.mjs [--json] score.wav [other.wav …]");
768
+ process.exitCode = 1;
769
+ return;
770
+ }
771
+ const files = paths.map((path) => {
772
+ const measured = measure(load(path));
773
+ return { path, figures: measured, score: score(measured) };
774
+ });
775
+ if (args.includes("--json")) {
776
+ console.log(JSON.stringify({ range: REELS.range, openAbove: REELS.openAbove, files }, (_, value) =>
777
+ typeof value === "number" && !Number.isFinite(value) ? String(value) : value, 2));
778
+ return;
779
+ }
780
+ files.forEach(({ path }, i) => {
781
+ console.log(`[${i + 1}] ${path}`);
782
+ });
783
+ const width = 11;
784
+ console.log("");
785
+ console.log("Figure".padEnd(27) + "Six films".padEnd(21) +
786
+ files.map((_, i) => `[${i + 1}]`.padStart(width)).join(""));
787
+ for (const row of figures) {
788
+ const [key, label, unit] = row;
789
+ const [lo, hi] = REELS.range[key];
790
+ const span = `${number(lo, row)}…${number(hi, row)}${REELS.openAbove.includes(key) ? " ↑" : ""}`;
791
+ console.log((unit ? `${label} (${unit})` : label).padEnd(27) + span.padEnd(21) +
792
+ files.map((file) => {
793
+ const { inside } = file.score[key];
794
+ const status = inside === null ? "info" : inside ? "in" : "out";
795
+ return `${number(file.figures[key], row)} ${status}`.padStart(width);
796
+ }).join(""));
797
+ }
798
+ console.log(`\n↑ Higher values are in range. Integrated loudness is informational because ${loudnessNote}.`);
799
+ }
800
+
801
+ if (process.argv[1] && existsSync(process.argv[1]) &&
802
+ realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url)))
803
+ main(process.argv.slice(2));