+
+
+
diff --git a/experiments/intelligent-terrarium/web/spatial-audio.mjs b/experiments/intelligent-terrarium/web/spatial-audio.mjs
new file mode 100644
index 0000000000..521b74692b
--- /dev/null
+++ b/experiments/intelligent-terrarium/web/spatial-audio.mjs
@@ -0,0 +1,25 @@
+export function spatialize(source, listener, radius = 12) {
+ const dx = Number(source[0]) - Number(listener.x || 0);
+ const dy = Number(source[1]) - Number(listener.y || 0);
+ const dz = Number(source[2]) - Number(listener.z || 0);
+ const yaw = Number(listener.yaw || 0);
+ const right = dx * Math.cos(yaw) - dz * Math.sin(yaw);
+ const distance = Math.hypot(dx, dy, dz);
+ const pan = Math.max(-1, Math.min(1, right / Math.max(1, Math.hypot(dx, dz))));
+ const gain = Math.max(0, Math.min(1, 1 - distance / Math.max(0.001, radius)));
+ return { pan, gain, distance };
+}
+
+export class SonicDeduper {
+ constructor(limit = 256) {
+ this.limit = limit;
+ this.ids = new Set();
+ }
+
+ accept(id) {
+ if (this.ids.has(id)) return false;
+ this.ids.add(id);
+ if (this.ids.size > this.limit) this.ids.delete(this.ids.values().next().value);
+ return true;
+ }
+}
--
2.51.2
From 711d9b33a5367e7a6437d3bbb5ec740a6a504f41 Mon Sep 17 00:00:00 2001
From: "prompt.ac/@jeffrey"