@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,221 @@
1
+ // What crossed each boundary of the beat sheet, read from the events file:
2
+ // a segment's `carry` (kit/time.js) names the one thing meant to live
3
+ // through the cut at its end, and the render followed that thing's box
4
+ // frame by frame, from 1 s before to 0.4 s after (the curves
5
+ // `carry@<to>:x|y|w|h|o|fw|fh`). Each boundary is then one of:
6
+ // - carried: the thing was still on screen 0.25 s past the boundary (at
7
+ // half its opacity or more), or grew from under half the frame to fill
8
+ // it on its way there, and
9
+ // it moved (≥ 2 % of the frame's diagonal) or changed size (≥ 10 %) —
10
+ // the thing pressed became the result, a card turned into the map;
11
+ // - anchored: it stayed across, unchanged — or only dissolved across,
12
+ // still faintly there 0.25 s past the boundary (a scene sliding away
13
+ // while the next comes in);
14
+ // - bare: gone by then, or never on screen;
15
+ // and a boundary whose segment names no carry is "cut" (its handoff says so,
16
+ // on purpose, a "hidden-cut" under motion among them), "lift" (the segment
17
+ // is declared as a layer moving on its own, nothing to follow across),
18
+ // "words" (a handoff in words, nothing named to follow) or "unwritten". Thresholds after onetake's probe (references/rhythm.md: a
19
+ // survivor that moves 2 % of the diagonal or scales 10 % is carried), here
20
+ // on the one element the page names rather than guessed from the picture,
21
+ // so a carry built from two elements is seen as the one the page names.
22
+ // Facts, not a grade: nothing here says a boundary should be carried.
23
+
24
+ import { type FilmEvents, type FilmSegment, handoffIs } from "./render";
25
+
26
+ /** how long before a boundary a carry is followed, and after (s): kit/time.js */
27
+ export const CARRY_BEFORE = 1;
28
+ export const CARRY_AFTER = 0.4;
29
+ /** still there this long past the boundary, at this opacity, it crossed */
30
+ export const CARRY_STAYS = 0.25;
31
+ const STAYS_OPACITY = 0.5;
32
+ /** a survivor that moves this share of the frame's diagonal has moved */
33
+ export const CARRY_MOVE = 0.02;
34
+ /** …or changes its size (√ of its area) by this share */
35
+ export const CARRY_SCALE = 0.1;
36
+ /** it fills the frame when it covers this share of it */
37
+ export const CARRY_FILL = 0.85;
38
+ /** drawn at less than this opacity it is not on screen */
39
+ const SEEN_OPACITY = 0.1;
40
+
41
+ export type CarryKind = "carried" | "anchored" | "bare";
42
+
43
+ export type BoundaryCarry = {
44
+ /** the boundary, s on the film's own clock */
45
+ at: number;
46
+ /** the handoff written on the segment ending here, if any */
47
+ handoff?: string;
48
+ /** what the segment named to follow, if anything */
49
+ carry?: string;
50
+ how:
51
+ | { kind: CarryKind; measured: true; scale: number; move: number; fill: number; note?: string }
52
+ | { kind: "cut" | "lift" | "words" | "unwritten" | "not rendered"; measured: false };
53
+ };
54
+
55
+ export type CarrySample = { t: number; x: number; y: number; w: number; h: number; o: number };
56
+
57
+ /** the curve a carry is written as (kit/time.js carryCurve) */
58
+ export const carryCurve = (at: number, field: string) => `carry@${+at.toFixed(3)}:${field}`;
59
+
60
+ /** a boundary's samples from the events file's curves, in time order */
61
+ export function carrySamples(
62
+ ev: Pick<FilmEvents, "curves">,
63
+ at: number,
64
+ ): {
65
+ samples: CarrySample[];
66
+ frame: { w: number; h: number } | null;
67
+ } {
68
+ const { names, t0, dt, rows } = ev.curves;
69
+ const col = (f: string) => names.indexOf(carryCurve(at, f));
70
+ const [ix, iy, iw, ih, io, ifw, ifh] = ["x", "y", "w", "h", "o", "fw", "fh"].map(col);
71
+ const samples: CarrySample[] = [];
72
+ let frame: { w: number; h: number } | null = null;
73
+ if (ix! < 0) return { samples, frame };
74
+ rows.forEach((r, i) => {
75
+ const v = [ix, iy, iw, ih, io].map((k) => (k! >= 0 ? r[k!] : null));
76
+ if (v.some((x) => x == null)) return;
77
+ const [x, y, w, h, o] = v as number[];
78
+ samples.push({ t: t0 + i * dt, x: x!, y: y!, w: w!, h: h!, o: o! });
79
+ const fw = ifw! >= 0 ? r[ifw!] : null;
80
+ const fh = ifh! >= 0 ? r[ifh!] : null;
81
+ if (!frame && fw != null && fh != null && fw > 0 && fh > 0) frame = { w: fw, h: fh };
82
+ });
83
+ return { samples, frame };
84
+ }
85
+
86
+ /** how much of the frame a box covers, 0..1 */
87
+ function cover(s: CarrySample, f: { w: number; h: number }): number {
88
+ const w = Math.max(0, Math.min(s.x + s.w, f.w) - Math.max(s.x, 0));
89
+ const h = Math.max(0, Math.min(s.y + s.h, f.h) - Math.max(s.y, 0));
90
+ return (w * h) / (f.w * f.h);
91
+ }
92
+
93
+ /** what one followed thing did across its boundary */
94
+ export function classifyCarry(
95
+ samples: readonly CarrySample[],
96
+ at: number,
97
+ frame: { w: number; h: number },
98
+ dt: number,
99
+ ): { kind: CarryKind; scale: number; move: number; fill: number; note?: string } {
100
+ const seen = samples.filter((s) => s.o >= SEEN_OPACITY && s.w * s.h > 0 && cover(s, frame) > 0);
101
+ const fill = seen.length ? Math.max(...seen.map((s) => cover(s, frame))) : 0;
102
+ if (!seen.length)
103
+ return { kind: "bare", scale: 1, move: 0, fill: 0, note: "not on screen near the boundary" };
104
+ // the far side starts a little past the boundary: a frame on it can still
105
+ // be the outgoing side's last, drawn on the shutter
106
+ const before = seen.filter((s) => s.t < at - dt / 2);
107
+ // a scene sliding out while it fades is not one that crossed
108
+ const after = seen.filter((s) => s.t >= at + CARRY_STAYS - 1e-6 && s.o >= STAYS_OPACITY);
109
+ const ref = before[0] ?? seen[0]!;
110
+ const diag = Math.hypot(frame.w, frame.h);
111
+ const size = (s: CarrySample) => Math.sqrt(s.w * s.h);
112
+ let scale = 1;
113
+ let move = 0;
114
+ for (const s of seen) {
115
+ const k = size(s) / size(ref);
116
+ if (Math.abs(Math.log(k)) > Math.abs(Math.log(scale))) scale = k;
117
+ move = Math.max(
118
+ move,
119
+ Math.hypot(s.x + s.w / 2 - (ref.x + ref.w / 2), s.y + s.h / 2 - (ref.y + ref.h / 2)) / diag,
120
+ );
121
+ }
122
+ const r = (v: number) => Math.round(v * 100) / 100;
123
+ const out = { scale: r(scale), move: r(move), fill: r(fill) };
124
+ if (!before.length)
125
+ return { kind: "bare", ...out, note: "first on screen only after the boundary" };
126
+ // filling the frame counts when it grew to: a whole scene fills it anyway
127
+ const grewToFill = fill >= CARRY_FILL && cover(ref, frame) < 0.5;
128
+ const across = after.length > 0 || grewToFill;
129
+ if (!across) {
130
+ // still drawn, faintly, past the boundary: it dissolved across rather than left
131
+ const fading = seen.some((s) => s.t >= at + CARRY_STAYS - 1e-6);
132
+ return fading
133
+ ? { kind: "anchored", ...out, note: "fading out across the boundary" }
134
+ : { kind: "bare", ...out, note: `gone ${CARRY_STAYS} s past the boundary` };
135
+ }
136
+ const changed = move >= CARRY_MOVE || Math.abs(scale - 1) >= CARRY_SCALE;
137
+ return { kind: changed ? "carried" : "anchored", ...out };
138
+ }
139
+
140
+ /** a handoff that says the boundary is a cut on purpose: a cut, a hard cut,
141
+ * or a cut hidden under motion (kit/time.js) */
142
+ const isCut = (h: string | undefined) => !!h && /^\s*(hard\s+|hidden-)?cut\s*$/i.test(h);
143
+
144
+ /** every boundary of the beat sheet inside the film (a segment's end before
145
+ * the film's), and what crossed it; `from` is where the film starts on the
146
+ * page's timeline (a render of part of it) */
147
+ export function boundaryCarries(
148
+ ev: Pick<FilmEvents, "curves" | "segments" | "duration" | "fps"> & { range?: [number, number] },
149
+ from = 0,
150
+ ): BoundaryCarry[] {
151
+ const end = ev.range ? ev.range[1] : ev.duration;
152
+ const start = ev.range ? ev.range[0] : 0;
153
+ const byAt = new Map<number, FilmSegment>();
154
+ for (const s of ev.segments as FilmSegment[]) {
155
+ if (!(s.to < ev.duration - 1e-6)) continue;
156
+ const k = +s.to.toFixed(3);
157
+ const had = byAt.get(k);
158
+ // two segments ending together name one boundary: the first carry and the
159
+ // first handoff written for it (time.js follows that first carry)
160
+ byAt.set(
161
+ k,
162
+ had
163
+ ? {
164
+ ...had,
165
+ ...(had.carry || !s.carry ? {} : { carry: s.carry }),
166
+ ...(had.handoff || !s.handoff ? {} : { handoff: s.handoff }),
167
+ }
168
+ : s,
169
+ );
170
+ }
171
+ const out: BoundaryCarry[] = [];
172
+ for (const [at, s] of [...byAt].sort((a, b) => a[0] - b[0])) {
173
+ const base = {
174
+ at: +(at - from).toFixed(3),
175
+ ...(s.handoff ? { handoff: s.handoff } : {}),
176
+ ...(s.carry ? { carry: s.carry } : {}),
177
+ };
178
+ if (!s.carry) {
179
+ out.push({
180
+ ...base,
181
+ how: {
182
+ kind: isCut(s.handoff)
183
+ ? "cut"
184
+ : handoffIs(s, "lift")
185
+ ? "lift"
186
+ : s.handoff
187
+ ? "words"
188
+ : "unwritten",
189
+ measured: false,
190
+ },
191
+ });
192
+ continue;
193
+ }
194
+ if (at < start - 1e-6 || at > end + 1e-6) {
195
+ out.push({ ...base, how: { kind: "not rendered", measured: false } });
196
+ continue;
197
+ }
198
+ const { samples, frame } = carrySamples(ev, at);
199
+ if (!samples.length || !frame) {
200
+ out.push({ ...base, how: { kind: "not rendered", measured: false } });
201
+ continue;
202
+ }
203
+ out.push({
204
+ ...base,
205
+ how: { measured: true, ...classifyCarry(samples, at, frame, 1 / ev.fps) },
206
+ });
207
+ }
208
+ return out;
209
+ }
210
+
211
+ /** a boundary's change in words: "grew ×4.2 to fill the frame", "moved 12 % of the frame" */
212
+ export function carryChange(b: BoundaryCarry): string {
213
+ if (!b.how.measured) return "";
214
+ const { scale, move, fill } = b.how;
215
+ const parts: string[] = [];
216
+ if (Math.abs(scale - 1) >= CARRY_SCALE)
217
+ parts.push(scale > 1 ? `grew ×${scale.toFixed(1)}` : `shrank to ×${scale.toFixed(2)}`);
218
+ if (move >= CARRY_MOVE) parts.push(`moved ${Math.round(move * 100)}% of the diagonal`);
219
+ if (fill >= CARRY_FILL && Math.abs(scale - 1) >= CARRY_SCALE) parts.push("filled the frame");
220
+ return parts.join(", ");
221
+ }
@@ -0,0 +1,330 @@
1
+ // Where a film's sound changes at once, and what changed: at each moment, the
2
+ // two seconds after it set against the two before — how often the low, middle
3
+ // and high bands are struck, which part of the spectrum gained or lost a
4
+ // sound, the harmony, the level — and whether anything led into it (a rise,
5
+ // a fill) or it simply switched. A change in one of these is a film moving
6
+ // on; several at once with nothing leading in is heard as another piece of
7
+ // music starting. Information only: no threshold says a change is wrong.
8
+
9
+ import {
10
+ BANDS,
11
+ bandOnsetStrength,
12
+ chromagram,
13
+ FLOOR_DB,
14
+ HIGH_HZ,
15
+ LISTEN_RATE,
16
+ LOW_HZ,
17
+ pickOnsets,
18
+ spectrum,
19
+ } from "./beats";
20
+
21
+ export type SoundChange = {
22
+ /** s, on the nearest onset */
23
+ t: number;
24
+ /** against the film's sharpest change (1) */
25
+ size: number;
26
+ /** what changed there, each in words with its numbers */
27
+ parts: string[];
28
+ /** what led into it in the 1.5 s before, or null: nothing did */
29
+ leadIn: string | null;
30
+ };
31
+
32
+ type Win = {
33
+ rates: [number, number, number];
34
+ /** the period the low band's hits repeat at, s (null: no clear one) */
35
+ pulse: number | null;
36
+ bands: Float64Array;
37
+ level: number;
38
+ chroma: Float64Array;
39
+ };
40
+
41
+ const REGIONS: [string, number, number][] = [
42
+ ["low", 40, 200],
43
+ ["middle", 200, 2000],
44
+ ["high", 2000, 10_000],
45
+ ];
46
+ const bandHz = (k: number) => LOW_HZ * (HIGH_HZ / LOW_HZ) ** (k / BANDS);
47
+ const dbMean = (xs: number[]) =>
48
+ xs.length ? 10 * Math.log10(xs.reduce((a, v) => a + 10 ** (v / 10), 0) / xs.length) : FLOOR_DB;
49
+ const hz = (v: number) => (v >= 1000 ? `${(v / 1000).toFixed(1)} kHz` : `${Math.round(v)} Hz`);
50
+
51
+ /** the sharpest changes in a sound (mono samples at LISTEN_RATE), largest
52
+ * first; null when the sound is too short to set `window` s either side of a
53
+ * moment (2·window + 1 s) — not measured, rather than measured and calm */
54
+ export function soundChanges(
55
+ pcm: Float32Array,
56
+ { window = 3, max = 5 }: { window?: number; max?: number } = {},
57
+ ): SoundChange[] | null {
58
+ const duration = pcm.length / LISTEN_RATE;
59
+ if (duration < 2 * window + 1) return null;
60
+ const s = spectrum(pcm);
61
+ const lowEnv = bandOnsetStrength(s, 40, 200);
62
+ const ch = chromagram(pcm);
63
+ const onsets = REGIONS.map(([, lo, hi]) => pickOnsets(s, bandOnsetStrength(s, lo, hi)));
64
+ const all = pickOnsets(s, bandOnsetStrength(s, LOW_HZ, HIGH_HZ));
65
+ const frames = (a: number, b: number) => {
66
+ const out: number[] = [];
67
+ for (let f = Math.max(0, Math.ceil(a / s.hopS)); f < Math.min(s.level.length, b / s.hopS); f++)
68
+ out.push(f);
69
+ return out;
70
+ };
71
+ const measure = (a: number, b: number): Win => {
72
+ const fs = frames(a, b);
73
+ const bands = new Float64Array(BANDS);
74
+ for (let k = 0; k < BANDS; k++) bands[k] = dbMean(fs.map((f) => s.bands[f]![k]!));
75
+ const chroma = new Float64Array(12);
76
+ for (let f = 0; f < ch.frames.length; f++) {
77
+ const t = ch.frameTime(f);
78
+ if (t >= a && t < b) for (let c = 0; c < 12; c++) chroma[c] = chroma[c]! + ch.frames[f]![c]!;
79
+ }
80
+ const len = Math.max(0.25, b - a);
81
+ return {
82
+ pulse: pulseOf(lowEnv, fs, s.hopS),
83
+ rates: onsets.map((xs) => xs.filter((t) => t >= a && t < b).length / len) as [
84
+ number,
85
+ number,
86
+ number,
87
+ ],
88
+ bands,
89
+ level: dbMean(fs.map((f) => s.level[f]!)),
90
+ chroma,
91
+ };
92
+ };
93
+ const step = 0.25;
94
+ type Cand = {
95
+ t: number;
96
+ d: number[];
97
+ before: Win;
98
+ after: Win;
99
+ };
100
+ const cands: Cand[] = [];
101
+ // only where both windows are whole: the film's first and last seconds are its music starting and ending
102
+ // each window serves as one moment's "after" and a later one's "before": measured once
103
+ const wins: Map<number, Win> = new Map();
104
+ const once = (a: number) => {
105
+ const k = Math.round(a / step);
106
+ let w = wins.get(k);
107
+ if (!w) {
108
+ w = measure(a, a + window);
109
+ wins.set(k, w);
110
+ }
111
+ return w;
112
+ };
113
+ for (let t = window; t <= duration - window; t += step) {
114
+ const before = once(t - window);
115
+ const after = once(t);
116
+ if (before.level <= FLOOR_DB + 10 && after.level <= FLOOR_DB + 10) continue;
117
+ const rate = (i: number) =>
118
+ Math.abs(Math.log2((after.rates[i]! + 0.25) / (before.rates[i]! + 0.25)));
119
+ // the spectrum's shape, the level taken out: which part gained or lost a sound
120
+ let mean = 0;
121
+ let n = 0;
122
+ for (let k = 0; k < BANDS; k++)
123
+ if (after.bands[k]! > FLOOR_DB || before.bands[k]! > FLOOR_DB) {
124
+ mean += after.bands[k]! - before.bands[k]!;
125
+ n++;
126
+ }
127
+ mean = n ? mean / n : 0;
128
+ let shape = 0;
129
+ for (let k = 0; k < BANDS; k++)
130
+ if (after.bands[k]! > FLOOR_DB || before.bands[k]! > FLOOR_DB)
131
+ shape += Math.abs(after.bands[k]! - before.bands[k]! - mean);
132
+ shape = n ? shape / n : 0;
133
+ let xy = 0;
134
+ let xx = 0;
135
+ let yy = 0;
136
+ for (let c = 0; c < 12; c++) {
137
+ xy += after.chroma[c]! * before.chroma[c]!;
138
+ xx += after.chroma[c]! ** 2;
139
+ yy += before.chroma[c]! ** 2;
140
+ }
141
+ const harmony = xx > 0 && yy > 0 ? 1 - xy / Math.sqrt(xx * yy) : 0;
142
+ // only a clear halving or doubling of the low pulse: half-time, double-time
143
+ const ratio = before.pulse && after.pulse ? after.pulse / before.pulse : 1;
144
+ const pulse = Math.abs(ratio - 2) < 0.25 || Math.abs(ratio - 0.5) < 0.07 ? 1 : 0;
145
+ cands.push({
146
+ t,
147
+ d: [rate(0), rate(1), rate(2), shape, harmony, Math.abs(after.level - before.level), pulse],
148
+ before,
149
+ after,
150
+ });
151
+ }
152
+ if (!cands.length) return [];
153
+ // each measure against how much it usually moves in this film, and a floor below which it is not a change
154
+ const FLOOR = [0.58, 0.58, 0.58, 3, 0.12, 3, 1];
155
+ const p90 = FLOOR.map((_, i) => {
156
+ const xs = cands.map((c) => c.d[i]!).sort((a, b) => a - b);
157
+ return Math.max(1e-6, xs[Math.floor(xs.length * 0.9)]!);
158
+ });
159
+ const changed = (c: Cand, i: number) => c.d[i]! >= FLOOR[i]! && c.d[i]! >= p90[i]!;
160
+ const score = (c: Cand) =>
161
+ c.d.reduce((a, v, i) => a + (changed(c, i) ? Math.min(3, v / p90[i]!) : 0), 0);
162
+ const scored = cands.map((c) => ({ c, v: score(c) })).filter((x) => x.v > 0);
163
+ // the strongest within ±1.5 s of each other count once
164
+ scored.sort((a, b) => b.v - a.v);
165
+ const kept: typeof scored = [];
166
+ for (const x of scored) if (!kept.some((k) => Math.abs(k.c.t - x.c.t) < 1.5)) kept.push(x);
167
+ // a switch keeps its measures past their usual for a while either side of
168
+ // it; the moment itself is where the measures that move smoothly (the
169
+ // spectrum's shape, the harmony, the level) set the two sides furthest apart
170
+ const loc = (c: Cand) => c.d[3]! / p90[3]! + c.d[4]! / p90[4]! + c.d[5]! / p90[5]!;
171
+ // moved only onto a moment that itself scored nearly as high, so what it says changed is what scored
172
+ const placed = kept.map((k) => {
173
+ let at = k.c;
174
+ for (const x of scored)
175
+ if (Math.abs(x.c.t - k.c.t) <= 1 && x.v >= k.v * 0.8 && loc(x.c) > loc(at)) at = x.c;
176
+ return { c: at, v: k.v };
177
+ });
178
+ const top: typeof placed = [];
179
+ for (const x of placed)
180
+ if (top.length < max && !top.some((k) => Math.abs(k.c.t - x.c.t) < 1.5)) top.push(x);
181
+ const best = top[0]?.v ?? 1;
182
+ const out = top.map(({ c, v }) => {
183
+ const parts: string[] = [];
184
+ REGIONS.forEach(([name], i) => {
185
+ if (!changed(c, i)) return;
186
+ const [b, a] = [c.before.rates[i]!, c.after.rates[i]!];
187
+ parts.push(`${name} hits ${b.toFixed(1)} → ${a.toFixed(1)} a second`);
188
+ });
189
+ if (changed(c, 3)) {
190
+ // the band region that gained (or lost) most against the level change
191
+ const lift = Array.from(
192
+ { length: BANDS },
193
+ (_, k) => c.after.bands[k]! - c.before.bands[k]! - (c.after.level - c.before.level),
194
+ );
195
+ // the stretch of 2–12 bands whose mean moved most that way (weighted to favour a wider stretch)
196
+ const run = (sign: 1 | -1) => {
197
+ let best: { lo: number; hi: number; db: number; w: number } | null = null;
198
+ for (let k0 = 0; k0 < BANDS; k0++) {
199
+ let sum = 0;
200
+ for (let k1 = k0 + 1; k1 <= Math.min(BANDS, k0 + 12); k1++) {
201
+ sum += sign * lift[k1 - 1]!;
202
+ const width = k1 - k0;
203
+ if (width < 2) continue;
204
+ const db = sum / width;
205
+ const w = db * Math.sqrt(width);
206
+ if (db > 0 && (!best || w > best.w)) best = { lo: k0, hi: k1, db, w };
207
+ }
208
+ }
209
+ return best;
210
+ };
211
+ const gain = run(1);
212
+ const loss = run(-1);
213
+ if (gain && gain.db >= 4)
214
+ parts.push(
215
+ `a sound comes in around ${hz(bandHz(gain.lo))}–${hz(bandHz(gain.hi))} (+${gain.db.toFixed(0)} dB there)`,
216
+ );
217
+ if (loss && loss.db >= 4)
218
+ parts.push(
219
+ `the sound around ${hz(bandHz(loss.lo))}–${hz(bandHz(loss.hi))} goes (−${loss.db.toFixed(0)} dB)`,
220
+ );
221
+ }
222
+ if (changed(c, 6)) {
223
+ const [b, a] = [c.before.pulse!, c.after.pulse!];
224
+ parts.push(
225
+ `the low pulse goes ${a > b ? "half-time" : "double-time"}: a hit every ${b.toFixed(2)} s → every ${a.toFixed(2)} s`,
226
+ );
227
+ }
228
+ if (changed(c, 4))
229
+ parts.push(`the harmony changes (pitch classes ${c.d[4]!.toFixed(2)} apart)`);
230
+ if (changed(c, 5)) {
231
+ const dl = c.after.level - c.before.level;
232
+ parts.push(`level ${dl > 0 ? "+" : "−"}${Math.abs(dl).toFixed(0)} dB`);
233
+ }
234
+ // on the onset nearest, when one is within 0.3 s
235
+ let t = c.t;
236
+ let near = 0.3;
237
+ for (const o of all)
238
+ if (Math.abs(o - c.t) < near) {
239
+ near = Math.abs(o - c.t);
240
+ t = o;
241
+ }
242
+ return {
243
+ t: Math.round(t * 100) / 100,
244
+ size: Math.round((v / best) * 100) / 100,
245
+ parts,
246
+ leadIn: leadIn(s, onsets[2]!, t),
247
+ };
248
+ });
249
+ return out.filter((c) => c.parts.length);
250
+ }
251
+
252
+ /** the lag (0.2–1.5 s) at which the low band's onset strength repeats best
253
+ * over these frames — the shortest of those within 85% of the best, so a
254
+ * steady beat is not read at twice its period — or null when nothing repeats
255
+ * clearly (correlation under 0.35) */
256
+ function pulseOf(env: Float32Array, fs: number[], hopS: number): number | null {
257
+ if (fs.length < 8) return null;
258
+ const x = fs.map((f) => env[f] ?? 0);
259
+ const mean = x.reduce((a, v) => a + v, 0) / x.length;
260
+ const y = x.map((v) => v - mean);
261
+ const zero = y.reduce((a, v) => a + v * v, 0);
262
+ if (!(zero > 0)) return null;
263
+ const lags: { lag: number; r: number }[] = [];
264
+ for (let L = Math.round(0.2 / hopS); L <= Math.min(Math.round(1.5 / hopS), y.length >> 1); L++) {
265
+ let r = 0;
266
+ for (let i = L; i < y.length; i++) r += y[i]! * y[i - L]!;
267
+ lags.push({ lag: L * hopS, r: r / zero });
268
+ }
269
+ // local maxima only
270
+ const peaks = lags.filter(
271
+ (p, i) => i > 0 && i < lags.length - 1 && p.r >= lags[i - 1]!.r && p.r >= lags[i + 1]!.r,
272
+ );
273
+ const best = Math.max(0, ...peaks.map((p) => p.r));
274
+ if (best < 0.35) return null;
275
+ return peaks.find((p) => p.r >= best * 0.85)?.lag ?? null;
276
+ }
277
+
278
+ /** a rise in level or in the high band over the 1.5 s before t, or a fill (the
279
+ * high hits thickening in the last second) — or null */
280
+ function leadIn(s: ReturnType<typeof spectrum>, high: readonly number[], t: number): string | null {
281
+ const a = Math.max(0, t - 1.5);
282
+ if (t - a < 0.75) return null;
283
+ const k0 = Math.floor((BANDS * Math.log(2000 / LOW_HZ)) / Math.log(HIGH_HZ / LOW_HZ));
284
+ const xs: number[] = [];
285
+ const lv: number[] = [];
286
+ const hb: number[] = [];
287
+ for (let f = Math.ceil(a / s.hopS); f < Math.min(s.level.length, t / s.hopS); f++) {
288
+ xs.push(f * s.hopS);
289
+ lv.push(Math.max(FLOOR_DB, s.level[f]!));
290
+ let e = 0;
291
+ for (let k = k0; k < BANDS; k++) e += 10 ** (s.bands[f]![k]! / 10);
292
+ hb.push(10 * Math.log10(e / (BANDS - k0) + 1e-12));
293
+ }
294
+ const slope = (ys: number[]) => {
295
+ const n = ys.length;
296
+ if (n < 4) return 0;
297
+ const mx = xs.reduce((p, v) => p + v, 0) / n;
298
+ const my = ys.reduce((p, v) => p + v, 0) / n;
299
+ let sxy = 0;
300
+ let sxx = 0;
301
+ for (let i = 0; i < n; i++) {
302
+ sxy += (xs[i]! - mx) * (ys[i]! - my);
303
+ sxx += (xs[i]! - mx) ** 2;
304
+ }
305
+ return sxx > 0 ? sxy / sxx : 0;
306
+ };
307
+ const span = t - a;
308
+ const lRise = slope(lv) * span;
309
+ const hRise = slope(hb) * span;
310
+ if (lRise >= 4)
311
+ return `the level rises ${lRise.toFixed(0)} dB over the ${span.toFixed(1)} s before`;
312
+ if (hRise >= 6)
313
+ return `the high band rises ${hRise.toFixed(0)} dB over the ${span.toFixed(1)} s before`;
314
+ const last = high.filter((x) => x >= t - 1 && x < t).length;
315
+ const prev = high.filter((x) => x >= t - 2 && x < t - 1).length;
316
+ if (last >= 4 && last >= prev * 1.5 + 1)
317
+ return `the high hits thicken in the second before (${prev} → ${last})`;
318
+ return null;
319
+ }
320
+
321
+ export function formatSoundChanges(cs: SoundChange[] | null): string[] {
322
+ if (!cs)
323
+ return ["- too short to set 3 s either side of a moment against each other (not measured)"];
324
+ if (!cs.length)
325
+ return ["- no change in the sound stood out from how it usually moves (not detected)"];
326
+ return cs.map(
327
+ (c, i) =>
328
+ `- ${c.t.toFixed(2)}s: ${c.parts.join("; ")} — ${c.leadIn ?? "nothing leads into it"}${i === 0 ? " — the sharpest in this film" : `, size ${c.size}`} (estimated)`,
329
+ );
330
+ }