Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(verse): real recorded CC0 sound effects for the duel, the lift, the HUD and each deck (#979)

Ruben Lütke8406dd4677c9
diff --git a/dodaios/ui/web/frontend/public/THIRD_PARTY_NOTICES.txt b/dodaios/ui/web/frontend/public/THIRD_PARTY_NOTICES.txt
index 7b73fa0bf4..ab1b747905 100644
--- a/dodaios/ui/web/frontend/public/THIRD_PARTY_NOTICES.txt
+++ b/dodaios/ui/web/frontend/public/THIRD_PARTY_NOTICES.txt
@@ -550,3 +550,12 @@ remaining public/provider-logos and public/agent-logos SVGs, or for
public/plugin-assets/slack-logo.svg. Their provenance remains unverified;
the source ledgers above do not assign a license to these separate files.
Vendor names and trademarks belong to their owners.
+
+----------------------------------------------------------------------
+
+Verse sound effects
+
+The recordings under public/verse/audio come from Freesound.org and the
+Kenney.nl Impact Sounds and RPG Audio packs, all released under CC0 1.0
+(https://creativecommons.org/publicdomain/zero/1.0/). Each source, its
+author and page are listed in public/verse/audio/CREDITS.md.
diff --git a/dodaios/ui/web/frontend/public/verse/audio/CREDITS.md b/dodaios/ui/web/frontend/public/verse/audio/CREDITS.md
new file mode 100644
index 0000000000..00bec18dde
--- /dev/null
+++ b/dodaios/ui/web/frontend/public/verse/audio/CREDITS.md
@@ -0,0 +1,76 @@
+# Verse sound effects: sources and licenses
+
+Every file in this folder is cut, layered, level-matched and encoded (Opus in
+Ogg, mono) from recordings released under **CC0 1.0 (public domain
+dedication)**: <https://creativecommons.org/publicdomain/zero/1.0/>. CC0 asks
+for no attribution; the authors are credited here anyway, with thanks. The
+license of each source was checked on its own page.
+
+Sources:
+
+| Key | Title | Author | Page | License |
+| --- | --- | --- | --- | --- |
+| FS701996 | Small Blaster shot 01 | xkeril | https://freesound.org/people/xkeril/sounds/701996/ | CC0 |
+| FS701997 | Blaster shot 02 | xkeril | https://freesound.org/people/xkeril/sounds/701997/ | CC0 |
+| FS701998 | Blaster shot 03 | xkeril | https://freesound.org/people/xkeril/sounds/701998/ | CC0 |
+| FS701999 | Blaster shot 04 | xkeril | https://freesound.org/people/xkeril/sounds/701999/ | CC0 |
+| FS466834 | enhanced blaster | MikeE63 | https://freesound.org/people/MikeE63/sounds/466834/ | CC0 |
+| FS136542 | ELECTRIC_ZAP_001 | JoelAudio | https://freesound.org/people/JoelAudio/sounds/136542/ | CC0 |
+| FS536741 | Zap (Jacob's ladder arc) | egomassive | https://freesound.org/people/egomassive/sounds/536741/ | CC0 |
+| FS30932 | bullet ricochet | aust_paul | https://freesound.org/people/aust_paul/sounds/30932/ | CC0 |
+| FS270588 | Anvil Hit 2 | michorvath | https://freesound.org/people/michorvath/sounds/270588/ | CC0 |
+| FS675760 | Tesla coil sparking and humming | craigsmith | https://freesound.org/people/craigsmith/sounds/675760/ | CC0 |
+| FS448394 | Fuze Switch Flick | LordForklift | https://freesound.org/people/LordForklift/sounds/448394/ | CC0 |
+| FS844244 | Electric Failure, High Voltage Power Down #2 | ATP2-kh | https://freesound.org/people/ATP2-kh/sounds/844244/ | CC0 |
+| FS189327 | missile lock on sound | Alxy | https://freesound.org/people/Alxy/sounds/189327/ | CC0 |
+| FS493558 | steam_safety_valve | Engineer_815 | https://freesound.org/people/Engineer_815/sounds/493558/ | CC0 |
+| FS60013 | Whoosh | qubodup | https://freesound.org/people/qubodup/sounds/60013/ | CC0 |
+| FS683101 | quick woosh | florianreichelt | https://freesound.org/people/florianreichelt/sounds/683101/ | CC0 |
+| FS749711 | Steps boots on metal surface | RFCaldas | https://freesound.org/people/RFCaldas/sounds/749711/ | CC0 |
+| FS673424 | Falling body hits the floor | courtneyeck | https://freesound.org/people/courtneyeck/sounds/673424/ | CC0 |
+| FS51126 | Activating Alarm Buttons Pressed Bleeps | RutgerMuller | https://freesound.org/people/RutgerMuller/sounds/51126/ | CC0 |
+| FS571317 | horn, hooter | specrad1 | https://freesound.org/people/specrad1/sounds/571317/ | CC0 |
+| FS832414 | Factory Warning Buzzer | qubodup | https://freesound.org/people/qubodup/sounds/832414/ | CC0 |
+| FS477846 | short-gas-leak | Astounded | https://freesound.org/people/Astounded/sounds/477846/ | CC0 |
+| FS161228 | Large Metal Lift Door Opening | lolamadeus | https://freesound.org/people/lolamadeus/sounds/161228/ | CC0 |
+| FS161230 | Large Metal Lift Door Closing | lolamadeus | https://freesound.org/people/lolamadeus/sounds/161230/ | CC0 |
+| FS221929 | Industrial lift ride-along | peridactyloptrix | https://freesound.org/people/peridactyloptrix/sounds/221929/ | CC0 |
+| FS619320 | Facility Hum Ambience Loopable | aSuperiorPotato | https://freesound.org/people/aSuperiorPotato/sounds/619320/ | CC0 |
+| FS429188 | Electrical server room | OSFX | https://freesound.org/people/OSFX/sounds/429188/ | CC0 |
+| FS749979 | Nuclear reactor | Bachsambora | https://freesound.org/people/Bachsambora/sounds/749979/ | CC0 |
+| FS587617 | low_machine_hum | Foxicity | https://freesound.org/people/Foxicity/sounds/587617/ | CC0 |
+| KI | Impact Sounds pack | Kenney (kenney.nl) | https://kenney.nl/assets/impact-sounds | CC0 |
+| KR | RPG Audio pack | Kenney (kenney.nl) | https://kenney.nl/assets/rpg-audio | CC0 |
+
+Files (what each is made of):
+
+| File | Used for | Made from |
+| --- | --- | --- |
+| shot_1.ogg … shot_4.ogg | blaster shot (round robin) | FS701996 … FS701999, each with the opening crack of FS466834 |
+| impact_metal_1.ogg … impact_metal_3.ogg | bolt hits a wall or the floor | KI impactMetal_heavy_000 … 002 with a short FS136542 sizzle |
+| body_hit_1.ogg … body_hit_3.ogg | bolt hits a body | KI impactPunch_heavy_000 … 002 with a short FS536741 arc |
+| marker.ogg | the shooter's hit tick | KR metalClick |
+| shield_block_1.ogg, shield_block_2.ogg | shield absorbs a bolt | FS136542; FS536741 |
+| deflect.ogg | a bolt glances off the shield | FS30932 (third take) |
+| parry.ogg | perfect parry, bolt reflected | FS270588 with FS136542 |
+| shield_hum.ogg | shield held up (loop) | FS675760 |
+| shield_up.ogg | shield raised | FS448394 with FS675760 |
+| shield_break.ogg | shield breaks | FS844244 |
+| overheat.ogg | blaster overheats | FS189327 |
+| vent.ogg | heat vent hiss | FS493558 |
+| vent_perfect.ogg | perfect vent | KR metalLatch |
+| vent_miss.ogg | missed vent | KI impactPlate_heavy_001 |
+| dodge_1.ogg, dodge_2.ogg | dodge roll | FS60013 with KR cloth1; FS683101 with KR cloth3 |
+| step_1.ogg … step_6.ogg | footsteps on deck plating, walk and run | FS749711 |
+| knockout.ogg | knocked out | FS673424 with KI impactPlate_heavy_000 |
+| beep.ogg | countdown | FS51126 |
+| round_start.ogg | round starts | FS571317 |
+| round_end.ogg | round ends | KI impactBell_heavy_000 |
+| surge.ogg | reactor surge warning | FS832414 |
+| ui_click.ogg | HUD panels open and close | FS448394 |
+| door_open.ogg, door_close.ogg | turbolift doors | FS477846 with FS161228; FS477846 with FS161230 |
+| lift_ride.ogg | turbolift ride (loop) | FS221929 |
+| amb_bridge.ogg | bridge ambience (loop) | FS619320 |
+| amb_ops.ogg | operations deck ambience (loop) | FS429188 |
+| amb_engineering.ogg | engineering ambience (loop) | FS749979 |
+| amb_hangar.ogg | hangar ambience (loop) | FS587617 |
diff --git a/dodaios/ui/web/frontend/public/verse/audio/amb_bridge.ogg b/dodaios/ui/web/frontend/public/verse/audio/amb_bridge.ogg
new file mode 100644
index 0000000000..f960a3cf3a
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/amb_bridge.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/amb_engineering.ogg b/dodaios/ui/web/frontend/public/verse/audio/amb_engineering.ogg
new file mode 100644
index 0000000000..2c2777210e
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/amb_engineering.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/amb_hangar.ogg b/dodaios/ui/web/frontend/public/verse/audio/amb_hangar.ogg
new file mode 100644
index 0000000000..1f25de2a2d
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/amb_hangar.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/amb_ops.ogg b/dodaios/ui/web/frontend/public/verse/audio/amb_ops.ogg
new file mode 100644
index 0000000000..d0ad38f03c
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/amb_ops.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/beep.ogg b/dodaios/ui/web/frontend/public/verse/audio/beep.ogg
new file mode 100644
index 0000000000..ea8eb336c9
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/beep.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/body_hit_1.ogg b/dodaios/ui/web/frontend/public/verse/audio/body_hit_1.ogg
new file mode 100644
index 0000000000..876362767d
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/body_hit_1.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/body_hit_2.ogg b/dodaios/ui/web/frontend/public/verse/audio/body_hit_2.ogg
new file mode 100644
index 0000000000..bf0129a325
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/body_hit_2.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/body_hit_3.ogg b/dodaios/ui/web/frontend/public/verse/audio/body_hit_3.ogg
new file mode 100644
index 0000000000..96d13c0752
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/body_hit_3.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/deflect.ogg b/dodaios/ui/web/frontend/public/verse/audio/deflect.ogg
new file mode 100644
index 0000000000..276164b62c
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/deflect.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/dodge_1.ogg b/dodaios/ui/web/frontend/public/verse/audio/dodge_1.ogg
new file mode 100644
index 0000000000..659a69ee3e
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/dodge_1.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/dodge_2.ogg b/dodaios/ui/web/frontend/public/verse/audio/dodge_2.ogg
new file mode 100644
index 0000000000..247599a98a
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/dodge_2.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/door_close.ogg b/dodaios/ui/web/frontend/public/verse/audio/door_close.ogg
new file mode 100644
index 0000000000..cdd4abf3c0
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/door_close.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/door_open.ogg b/dodaios/ui/web/frontend/public/verse/audio/door_open.ogg
new file mode 100644
index 0000000000..7bec1f0119
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/door_open.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/impact_metal_1.ogg b/dodaios/ui/web/frontend/public/verse/audio/impact_metal_1.ogg
new file mode 100644
index 0000000000..a89408f7ea
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/impact_metal_1.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/impact_metal_2.ogg b/dodaios/ui/web/frontend/public/verse/audio/impact_metal_2.ogg
new file mode 100644
index 0000000000..4cd145d003
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/impact_metal_2.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/impact_metal_3.ogg b/dodaios/ui/web/frontend/public/verse/audio/impact_metal_3.ogg
new file mode 100644
index 0000000000..b83ae14fc4
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/impact_metal_3.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/knockout.ogg b/dodaios/ui/web/frontend/public/verse/audio/knockout.ogg
new file mode 100644
index 0000000000..e5505f8709
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/knockout.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/lift_ride.ogg b/dodaios/ui/web/frontend/public/verse/audio/lift_ride.ogg
new file mode 100644
index 0000000000..d27937da88
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/lift_ride.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/marker.ogg b/dodaios/ui/web/frontend/public/verse/audio/marker.ogg
new file mode 100644
index 0000000000..f8cf2725df
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/marker.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/overheat.ogg b/dodaios/ui/web/frontend/public/verse/audio/overheat.ogg
new file mode 100644
index 0000000000..91d0f3f341
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/overheat.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/parry.ogg b/dodaios/ui/web/frontend/public/verse/audio/parry.ogg
new file mode 100644
index 0000000000..46964cc06c
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/parry.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/round_end.ogg b/dodaios/ui/web/frontend/public/verse/audio/round_end.ogg
new file mode 100644
index 0000000000..3e8642e33d
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/round_end.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/round_start.ogg b/dodaios/ui/web/frontend/public/verse/audio/round_start.ogg
new file mode 100644
index 0000000000..30c904f147
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/round_start.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/shield_block_1.ogg b/dodaios/ui/web/frontend/public/verse/audio/shield_block_1.ogg
new file mode 100644
index 0000000000..8e63f29d7b
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/shield_block_1.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/shield_block_2.ogg b/dodaios/ui/web/frontend/public/verse/audio/shield_block_2.ogg
new file mode 100644
index 0000000000..67bd57fefc
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/shield_block_2.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/shield_break.ogg b/dodaios/ui/web/frontend/public/verse/audio/shield_break.ogg
new file mode 100644
index 0000000000..a8e9c308b5
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/shield_break.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/shield_hum.ogg b/dodaios/ui/web/frontend/public/verse/audio/shield_hum.ogg
new file mode 100644
index 0000000000..4dc96b9493
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/shield_hum.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/shield_up.ogg b/dodaios/ui/web/frontend/public/verse/audio/shield_up.ogg
new file mode 100644
index 0000000000..951f818533
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/shield_up.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/shot_1.ogg b/dodaios/ui/web/frontend/public/verse/audio/shot_1.ogg
new file mode 100644
index 0000000000..8015840f44
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/shot_1.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/shot_2.ogg b/dodaios/ui/web/frontend/public/verse/audio/shot_2.ogg
new file mode 100644
index 0000000000..ddf6e89849
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/shot_2.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/shot_3.ogg b/dodaios/ui/web/frontend/public/verse/audio/shot_3.ogg
new file mode 100644
index 0000000000..9742351368
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/shot_3.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/shot_4.ogg b/dodaios/ui/web/frontend/public/verse/audio/shot_4.ogg
new file mode 100644
index 0000000000..419cd704b5
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/shot_4.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/step_1.ogg b/dodaios/ui/web/frontend/public/verse/audio/step_1.ogg
new file mode 100644
index 0000000000..2b744b5c4d
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/step_1.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/step_2.ogg b/dodaios/ui/web/frontend/public/verse/audio/step_2.ogg
new file mode 100644
index 0000000000..fadcbf62fd
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/step_2.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/step_3.ogg b/dodaios/ui/web/frontend/public/verse/audio/step_3.ogg
new file mode 100644
index 0000000000..7adaed9c5c
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/step_3.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/step_4.ogg b/dodaios/ui/web/frontend/public/verse/audio/step_4.ogg
new file mode 100644
index 0000000000..005fedff71
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/step_4.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/step_5.ogg b/dodaios/ui/web/frontend/public/verse/audio/step_5.ogg
new file mode 100644
index 0000000000..60dbc0b31d
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/step_5.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/step_6.ogg b/dodaios/ui/web/frontend/public/verse/audio/step_6.ogg
new file mode 100644
index 0000000000..4dfde120ec
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/step_6.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/surge.ogg b/dodaios/ui/web/frontend/public/verse/audio/surge.ogg
new file mode 100644
index 0000000000..34b5dd48df
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/surge.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/ui_click.ogg b/dodaios/ui/web/frontend/public/verse/audio/ui_click.ogg
new file mode 100644
index 0000000000..5b21aff905
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/ui_click.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/vent.ogg b/dodaios/ui/web/frontend/public/verse/audio/vent.ogg
new file mode 100644
index 0000000000..5afd1aca34
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/vent.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/vent_miss.ogg b/dodaios/ui/web/frontend/public/verse/audio/vent_miss.ogg
new file mode 100644
index 0000000000..a7ec3f4fb6
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/vent_miss.ogg differ
diff --git a/dodaios/ui/web/frontend/public/verse/audio/vent_perfect.ogg b/dodaios/ui/web/frontend/public/verse/audio/vent_perfect.ogg
new file mode 100644
index 0000000000..dd0c41bdf7
Binary files /dev/null and b/dodaios/ui/web/frontend/public/verse/audio/vent_perfect.ogg differ
diff --git a/dodaios/ui/web/frontend/src/components/society/verse/VerseStage.tsx b/dodaios/ui/web/frontend/src/components/society/verse/VerseStage.tsx
index 1c4c5f49d9..4408c7423f 100644
--- a/dodaios/ui/web/frontend/src/components/society/verse/VerseStage.tsx
+++ b/dodaios/ui/web/frontend/src/components/society/verse/VerseStage.tsx
@@ -72,6 +72,7 @@ import { CrewCard, type CrewCardInfo } from "./hud/CrewCard";
import { LiftPanel } from "./hud/LiftPanel";
import { TakeoverPanel } from "./hud/TakeoverPanel";
import { isTerminalFace } from "./effects/ScreensLayer";
+import { useStageAudio } from "./audio/useStageAudio";
import { DeckTitle, StatsReadout, Toolbar } from "./hud/DeckBar";
import { LauncherPanel } from "./hud/LauncherPanel";
import { SimulatorPanel } from "./hud/SimulatorPanel";
@@ -186,6 +187,7 @@ export function VerseStage({ onOpenLedger, onSelectAgent, onCreateAgent, onOpenG
const [messUntil, setMessUntil] = useState(0);
const [orders, setOrders] = useState<CommanderOrders>({ target: null, order: 0, fromLift: false });
+ useStageAudio({ awake, deckId, doors, panel, dueling });
useSyncCompanionPet();
useProgressionSync(awake, deckId);
const library = useCharacterLibrary(awake);
diff --git a/dodaios/ui/web/frontend/src/components/society/verse/audio/useStageAudio.ts b/dodaios/ui/web/frontend/src/components/society/verse/audio/useStageAudio.ts
new file mode 100644
index 0000000000..e68101ea14
--- /dev/null
+++ b/dodaios/ui/web/frontend/src/components/society/verse/audio/useStageAudio.ts
@@ -0,0 +1,107 @@
+/**
+ * The ship around the commander: each deck's air handling and machinery as a
+ * quiet loop, the turbolift's doors and ride, and a click when a HUD panel
+ * opens or closes. Loaded once the Verse is on screen; the loops stop while
+ * it is hidden. The level follows the Verse volume setting.
+ */
+import { useEffect, useRef, useState } from "react";
+import type { DeckId } from "../decks";
+import { useViewSettings } from "../engine/realtime/viewSettings";
+import { verseAudio, type SoundName, type Voice } from "./verseAudio";
+
+const AMBIENCE: Record<DeckId, SoundName> = {
+ bridge: "amb_bridge",
+ ops: "amb_ops",
+ engineering: "amb_engineering",
+ hangar: "amb_hangar",
+};
+
+const STAGE_SOUNDS: readonly SoundName[] = ["door_open", "door_close", "lift_ride", "ui_click", "ui_close"];
+
+const AMBIENCE_LEVEL = 0.32;
+/** The ambience steps back while a duel is fought. */
+const AMBIENCE_DUEL = 0.16;
+
+interface StageAudio {
+ /** The Verse is on screen. */
+ awake: boolean;
+ deckId: DeckId;
+ /** The deck the lift rides to while its doors are shut, else null. */
+ doors: DeckId | null;
+ /** The HUD panel that is open, else null. */
+ panel: string | null;
+ dueling: boolean;
+}
+
+export function useStageAudio({ awake, deckId, doors, panel, dueling }: StageAudio): void {
+ const volume = useViewSettings((s) => s.volume);
+ useEffect(() => { verseAudio().setVolume(volume); }, [volume]);
+
+ // Load the deck's sounds once the Verse is on screen; browsers start audio only after a gesture, so the first click wakes it.
+ /** The deck whose ambience has loaded. */
+ const [ambienceReady, setAmbienceReady] = useState<DeckId | null>(null);
+ useEffect(() => {
+ if (!awake) return;
+ const audio = verseAudio();
+ let live = true;
+ void audio.preload([...STAGE_SOUNDS, AMBIENCE[deckId]]).then(() => { if (live) setAmbienceReady(deckId); });
+ const wake = () => audio.resume();
+ window.addEventListener("pointerdown", wake, true);
+ window.addEventListener("keydown", wake, true);
+ return () => {
+ live = false;
+ window.removeEventListener("pointerdown", wake, true);
+ window.removeEventListener("keydown", wake, true);
+ };
+ }, [awake, deckId, setAmbienceReady]);
+
+ // The deck's ambience: one loop, crossfaded on a deck change, stopped while the Verse is hidden.
+ const loop = useRef<{ deck: DeckId; voice: Voice } | null>(null);
+ useEffect(() => {
+ const current = loop.current;
+ if (!awake) {
+ current?.voice.stop(0.4);
+ loop.current = null;
+ return;
+ }
+ if (current?.deck === deckId) {
+ current.voice.setGain(dueling ? AMBIENCE_DUEL : AMBIENCE_LEVEL, 0.6);
+ return;
+ }
+ if (ambienceReady !== deckId) return;
+ current?.voice.stop(0.8);
+ const voice = verseAudio().play(AMBIENCE[deckId], {
+ gain: dueling ? AMBIENCE_DUEL : AMBIENCE_LEVEL, loop: true, fadeIn: 1.2, pitchJitter: 0, gainJitter: 0,
+ });
+ loop.current = voice ? { deck: deckId, voice } : null;
+ }, [awake, deckId, dueling, ambienceReady]);
+ useEffect(() => () => { loop.current?.voice.stop(0.2); loop.current = null; }, []);
+
+ // The turbolift: the doors shut, the car rides while they stay shut, the doors open on the new deck.
+ const ride = useRef<Voice | null>(null);
+ const wasShut = useRef(false);
+ useEffect(() => {
+ const audio = verseAudio();
+ if (doors && !wasShut.current) {
+ wasShut.current = true;
+ audio.play("door_close", { gain: 0.6 });
+ ride.current?.stop(0.1);
+ ride.current = audio.play("lift_ride", { gain: 0.5, loop: true, fadeIn: 0.35, delay: 0.25, pitchJitter: 0.02 });
+ } else if (!doors && wasShut.current) {
+ wasShut.current = false;
+ ride.current?.stop(0.3);
+ ride.current = null;
+ audio.play("door_open", { gain: 0.6 });
+ }
+ }, [doors]);
+ useEffect(() => () => { ride.current?.stop(0.1); ride.current = null; }, []);
+
+ // A HUD panel opening or closing.
+ const lastPanel = useRef<string | null>(null);
+ useEffect(() => {
+ const before = lastPanel.current;
+ lastPanel.current = panel;
+ if (panel === before) return;
+ verseAudio().play(panel ? "ui_click" : "ui_close", { gain: 0.45, rate: panel ? 1 : 0.85, pitchJitter: 0.03 });
+ }, [panel]);
+}
diff --git a/dodaios/ui/web/frontend/src/components/society/verse/audio/verseAudio.test.ts b/dodaios/ui/web/frontend/src/components/society/verse/audio/verseAudio.test.ts
new file mode 100644
index 0000000000..0cba357080
--- /dev/null
+++ b/dodaios/ui/web/frontend/src/components/society/verse/audio/verseAudio.test.ts
@@ -0,0 +1,124 @@
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { DuelSound } from "../duel/duelSound";
+import type { PlayerView } from "../combat/view";
+import { DUEL_SOUNDS, SOUND_FILES, VerseAudio, spatial } from "./verseAudio";
+
+/** A WebAudio stand-in that records every buffer source started. */
+function fakeAudio() {
+ const started: { buffer: unknown; rate: number; loop: boolean }[] = [];
+ const param = () => ({
+ value: 1,
+ setValueAtTime: vi.fn(), linearRampToValueAtTime: vi.fn(), exponentialRampToValueAtTime: vi.fn(),
+ setTargetAtTime: vi.fn(), cancelScheduledValues: vi.fn(),
+ });
+ const node = () => ({ connect: vi.fn((n: unknown) => n), disconnect: vi.fn() });
+ class Ctx {
+ currentTime = 0;
+ state = "running";
+ destination = node();
+ createGain() { return { ...node(), gain: param() }; }
+ createStereoPanner() { return { ...node(), pan: param() }; }
+ createDynamicsCompressor() { return { ...node(), threshold: param(), ratio: param(), attack: param(), release: param() }; }
+ createBufferSource() {
+ const src = {
+ ...node(), buffer: null as unknown, loop: false, playbackRate: param(), onended: null,
+ start: vi.fn(() => { started.push({ buffer: src.buffer, rate: src.playbackRate.value, loop: src.loop }); }),
+ stop: vi.fn(),
+ };
+ return src;
+ }
+ decodeAudioData(data: ArrayBuffer) { return Promise.resolve({ duration: 0.3, tag: new Uint8Array(data)[0] }); }
+ resume() { return Promise.resolve(); }
+ suspend() { return Promise.resolve(); }
+ close() { return Promise.resolve(); }
+ }
+ vi.stubGlobal("AudioContext", Ctx);
+ return started;
+}
+
+afterEach(() => { vi.unstubAllGlobals(); });
+
+describe("verse audio", () => {
+ it("pans a sound to the side it happens on and fades it with distance", () => {
+ const l = { x: 0, z: 0, yaw: 0 };
+ const right = spatial({ x: -5, z: 0 }, l);
+ const left = spatial({ x: 5, z: 0 }, l);
+ expect(right.pan).toBeGreaterThan(0.5);
+ expect(left.pan).toBeLessThan(-0.5);
+ expect(spatial({ x: 0, z: 30 }, l).level).toBeLessThan(spatial({ x: 0, z: 3 }, l).level);
+ expect(spatial({ x: 0, z: 0.2 }, l)).toEqual({ level: 1, pan: 0 });
+ });
+
+ it("lists a file for every duel sound", () => {
+ for (const name of DUEL_SOUNDS) expect(SOUND_FILES[name].length).toBeGreaterThan(0);
+ });
+
+ it("loads lazily, plays the takes round robin and never one twice running", async () => {
+ const started = fakeAudio();
+ const fetcher = vi.fn(async (url: string) => new Uint8Array([Number(url.match(/shot_(\d)/)?.[1] ?? 0)]).buffer);
+ const audio = new VerseAudio(fetcher);
+ expect(audio.play("shot")).toBeNull();
+ expect(fetcher).not.toHaveBeenCalled();
+ await audio.preload(["shot"]);
+ expect(fetcher).toHaveBeenCalledTimes(SOUND_FILES.shot.length);
+ expect(fetcher.mock.calls[0][0]).toMatch(/verse\/audio\/shot_1\.ogg$/);
+ for (let i = 0; i < 12; i++) audio.play("shot");
+ expect(started).toHaveLength(12);
+ for (let i = 1; i < started.length; i++) expect(started[i].buffer).not.toBe(started[i - 1].buffer);
+ expect(new Set(started.map((s) => s.buffer)).size).toBe(SOUND_FILES.shot.length);
+ // Each play varies the pitch a little around the asked rate.
+ for (const s of started) expect(Math.abs(s.rate - 1)).toBeLessThanOrEqual(0.0401);
+ });
+
+ it("stays silent when the files cannot be fetched or there is no WebAudio", async () => {
+ const started = fakeAudio();
+ const debug = vi.spyOn(console, "debug").mockImplementation(() => undefined);
+ const audio = new VerseAudio(async () => { throw new Error("404"); });
+ await audio.preload(["shot", "step"]);
+ expect(audio.loaded("shot")).toBe(false);
+ expect(audio.play("shot")).toBeNull();
+ expect(started).toHaveLength(0);
+ debug.mockRestore();
+ vi.unstubAllGlobals();
+ vi.stubGlobal("AudioContext", undefined);
+ const none = new VerseAudio(async () => new ArrayBuffer(1));
+ await none.preload(["shot"]);
+ expect(none.play("shot")).toBeNull();
+ });
+});
+
+describe("duel sound", () => {
+ const player = (o: Partial<PlayerView>): PlayerView => ({
+ slot: 0, id: "p", local: true, side: 0, x: 0, z: 0, yaw: 0, pitch: 0, aimYaw: 0, aimPitch: 0, vx: 0, vz: 0, speed: 0,
+ alive: true, health: 100, healthMax: 100, shieldUp: false, shieldEnergy: 1, shieldBroken: false, parrying: false,
+ ads: 0, sprinting: false, dodging: false, dodgeProgress: 0, venting: false, overheated: false, heat: 0, ...o,
+ });
+
+ it("plays a footfall per stride while a player moves, none while they stand", async () => {
+ const started = fakeAudio();
+ const audio = new VerseAudio(async () => new ArrayBuffer(1));
+ await audio.preload(["step"]);
+ const sound = new DuelSound(audio);
+ const l = { x: 0, z: 0, yaw: 0 };
+ // Walking 4 m/s for one second at 60 fps covers about 2.7 strides.
+ for (let i = 0; i <= 60; i++) sound.play([], 0, l, [player({ z: (i * 4) / 60, speed: 4 })]);
+ expect(started.length).toBeGreaterThanOrEqual(2);
+ expect(started.length).toBeLessThanOrEqual(3);
+ const walked = started.length;
+ for (let i = 0; i < 60; i++) sound.play([], 0, l, [player({ z: 4, speed: 0 })]);
+ expect(started.length).toBe(walked);
+ });
+
+ it("keeps the shield's hum while it is up and stops it when the match pauses", async () => {
+ fakeAudio();
+ const audio = new VerseAudio(async () => new ArrayBuffer(1));
+ await audio.preload(["shield_hum", "shield_up"]);
+ const sound = new DuelSound(audio);
+ const stop = vi.fn();
+ const play = vi.spyOn(audio, "play").mockReturnValue({ stop, setGain: vi.fn(), setRate: vi.fn() });
+ sound.play([{ type: "shield_up", tick: 1, player: 0, seq: 1 }], 0, null);
+ expect(play).toHaveBeenCalledWith("shield_hum", expect.objectContaining({ loop: true }));
+ sound.silence();
+ expect(stop).toHaveBeenCalled();
+ });
+});
diff --git a/dodaios/ui/web/frontend/src/components/society/verse/audio/verseAudio.ts b/dodaios/ui/web/frontend/src/components/society/verse/audio/verseAudio.ts
new file mode 100644
index 0000000000..aeb4056f48
--- /dev/null
+++ b/dodaios/ui/web/frontend/src/components/society/verse/audio/verseAudio.ts
@@ -0,0 +1,336 @@
+/**
+ * The Verse's sound: recorded effects (public/verse/audio, credits in its
+ * CREDITS.md) played through one shared WebAudio context.
+ *
+ * Nothing is fetched until something asks for a sound: `preload` starts the
+ * download of a group (the duel's, the deck's), `play` plays a loaded sound
+ * and quietly skips one that is not there yet, failed to load, or when the
+ * browser has no WebAudio. Every play gets a small random pitch and level
+ * change and steps through a sound's recorded variants, so a burst of shots
+ * or footsteps never repeats the same take twice in a row. A sound placed in
+ * the world is panned and attenuated by where the listener stands.
+ *
+ * The level follows the person's Verse volume setting; UI sounds switched
+ * off for the app (`jarvis.ui.sound` = "off") silence the Verse too.
+ */
+
+/** Every sound and its recorded takes (files under public/verse/audio). */
+export const SOUND_FILES = {
+ shot: ["shot_1.ogg", "shot_2.ogg", "shot_3.ogg", "shot_4.ogg"],
+ impact: ["impact_metal_1.ogg", "impact_metal_2.ogg", "impact_metal_3.ogg"],
+ body_hit: ["body_hit_1.ogg", "body_hit_2.ogg", "body_hit_3.ogg"],
+ marker: ["marker.ogg"],
+ block: ["shield_block_1.ogg", "shield_block_2.ogg"],
+ deflect: ["deflect.ogg"],
+ parry: ["parry.ogg"],
+ shield_hum: ["shield_hum.ogg"],
+ shield_up: ["shield_up.ogg"],
+ shield_break: ["shield_break.ogg"],
+ overheat: ["overheat.ogg"],
+ vent: ["vent.ogg"],
+ vent_perfect: ["vent_perfect.ogg"],
+ vent_miss: ["vent_miss.ogg"],
+ dodge: ["dodge_1.ogg", "dodge_2.ogg"],
+ step: ["step_1.ogg", "step_2.ogg", "step_3.ogg", "step_4.ogg", "step_5.ogg", "step_6.ogg"],
+ death: ["knockout.ogg"],
+ beep: ["beep.ogg"],
+ round_start: ["round_start.ogg"],
+ round_end: ["round_end.ogg"],
+ surge: ["surge.ogg"],
+ ui_click: ["ui_click.ogg"],
+ ui_close: ["ui_click.ogg"],
+ door_open: ["door_open.ogg"],
+ door_close: ["door_close.ogg"],
+ lift_ride: ["lift_ride.ogg"],
+ amb_bridge: ["amb_bridge.ogg"],
+ amb_engineering: ["amb_engineering.ogg"],
+ amb_hangar: ["amb_hangar.ogg"],
+ amb_ops: ["amb_ops.ogg"],
+} as const satisfies Record<string, readonly string[]>;
+
+export type SoundName = keyof typeof SOUND_FILES;
+
+/** The sounds a duel uses (loaded when one starts). */
+export const DUEL_SOUNDS: readonly SoundName[] = [
+ "shot", "impact", "body_hit", "marker", "block", "deflect", "parry", "shield_hum", "shield_up", "shield_break",
+ "overheat", "vent", "vent_perfect", "vent_miss", "dodge", "step", "death", "beep", "round_start", "round_end", "surge",
+];
+
+/** Where the listener is: the camera's position and heading (yaw 0 faces +Z). */
+export interface Listener { x: number; z: number; yaw: number }
+
+export interface PlayOptions {
+ /** Linear level before the master volume (1 = as recorded). */
+ gain?: number;
+ /** Playback rate (1 = as recorded); the random variation is applied on top. */
+ rate?: number;
+ /** Random pitch spread, ± fraction of the rate (default 0.04). */
+ pitchJitter?: number;
+ /** Random level spread, ± fraction of the gain (default 0.1). */
+ gainJitter?: number;
+ /** Where the sound happens; with a listener it is panned and attenuated. */
+ at?: { x: number; z: number } | null;
+ listener?: Listener | null;
+ /** Loop the buffer until the voice is stopped. */
+ loop?: boolean;
+ /** Seconds of fade-in. */
+ fadeIn?: number;
+ /** Stop after this many seconds (with a short fade). */
+ duration?: number;
+ /** Seconds from now to start. */
+ delay?: number;
+}
+
+/** A sound that is playing; `stop` fades it out. */
+export interface Voice {
+ stop(fade?: number): void;
+ setGain(gain: number, ramp?: number): void;
+ setRate(rate: number, ramp?: number): void;
+}
+
+const UI_SOUND_KEY = "jarvis.ui.sound";
+const MASTER_LEVEL = 0.9;
+
+function uiSoundOn(): boolean {
+ try {
+ return typeof localStorage === "undefined" || localStorage.getItem(UI_SOUND_KEY) !== "off";
+ } catch {
+ return true;
+ }
+}
+
+/** Level and pan for a sound at `at` heard by `l`: quieter with distance, panned to its side. Pure. */
+export function spatial(at: { x: number; z: number }, l: Listener): { level: number; pan: number } {
+ const dx = at.x - l.x;
+ const dz = at.z - l.z;
+ const d = Math.hypot(dx, dz);
+ const level = 1 / (1 + Math.max(0, d - 2) / 9);
+ if (d <= 0.5) return { level, pan: 0 };
+ // Right of the heading is negative rel (yaw grows to the left), so the pan is -sin(rel).
+ const rel = Math.atan2(dx, dz) - l.yaw;
+ return { level, pan: Math.max(-0.85, Math.min(0.85, -Math.sin(rel))) };
+}
+
+export function audioBase(): string {
+ const base = (import.meta.env?.BASE_URL as string | undefined) ?? "/";
+ return `${base.endsWith("/") ? base : `${base}/`}verse/audio/`;
+}
+
+type Ctor = typeof AudioContext;
+
+export class VerseAudio {
+ private ctx: AudioContext | null = null;
+ private master: GainNode | null = null;
+ private failed = false;
+ private volume = 0.7;
+ private readonly buffers = new Map<SoundName, AudioBuffer[]>();
+ private readonly loading = new Map<SoundName, Promise<void>>();
+ private readonly turn = new Map<SoundName, number>();
+
+ constructor(private readonly fetcher: (url: string) => Promise<ArrayBuffer> = defaultFetch) {}
+
+ /** The context, made on first use; null without WebAudio. */
+ context(): AudioContext | null {
+ if (this.ctx || this.failed) return this.ctx;
+ try {
+ const w = window as unknown as { AudioContext?: Ctor; webkitAudioContext?: Ctor };
+ const AC = w.AudioContext ?? w.webkitAudioContext;
+ if (!AC) { this.failed = true; return null; }
+ const ctx = new AC();
+ const master = ctx.createGain();
+ master.gain.value = this.level();
+ // A gentle limiter keeps a burst of shots and impacts from clipping.
+ const comp = ctx.createDynamicsCompressor?.();
+ if (comp) {
+ comp.threshold.value = -10;
+ comp.ratio.value = 4;
+ comp.attack.value = 0.003;
+ comp.release.value = 0.15;
+ master.connect(comp).connect(ctx.destination);
+ } else {
+ master.connect(ctx.destination);
+ }
+ this.ctx = ctx;
+ this.master = master;
+ } catch {
+ this.failed = true;
+ }
+ return this.ctx;
+ }
+
+ private level(): number {
+ return uiSoundOn() ? this.volume * MASTER_LEVEL : 0;
+ }
+
+ /** The person's Verse volume, 0..1. */
+ setVolume(volume: number): void {
+ this.volume = Math.max(0, Math.min(1, Number.isFinite(volume) ? volume : 0.7));
+ const ctx = this.ctx;
+ if (ctx && this.master) this.master.gain.setTargetAtTime(this.level(), ctx.currentTime, 0.05);
+ }
+
+ /** Wake the audio (call from a user gesture). */
+ resume(): void {
+ const ctx = this.context();
+ if (ctx && ctx.state === "suspended") void ctx.resume().catch(() => undefined);
+ }
+
+ /** Let the audio hardware rest while nothing in the Verse plays. */
+ suspend(): void {
+ if (this.ctx && this.ctx.state === "running") void this.ctx.suspend().catch(() => undefined);
+ }
+
+ loaded(name: SoundName): boolean {
+ return (this.buffers.get(name)?.length ?? 0) > 0;
+ }
+
+ /** Start fetching and decoding these sounds (each once); resolves when all have settled. */
+ preload(names: readonly SoundName[]): Promise<void> {
+ const ctx = this.context();
+ if (!ctx) return Promise.resolve();
+ return Promise.all(names.map((name) => {
+ let pending = this.loading.get(name);
+ if (!pending) {
+ pending = this.load(ctx, name);
+ this.loading.set(name, pending);
+ }
+ return pending;
+ })).then(() => undefined);
+ }
+
+ private async load(ctx: AudioContext, name: SoundName): Promise<void> {
+ const base = audioBase();
+ const takes = await Promise.all(SOUND_FILES[name].map(async (file) => {
+ try {
+ const data = await this.fetcher(base + file);
+ return await decode(ctx, data);
+ } catch (error) {
+ console.debug(`Verse sound ${file} unavailable`, error);
+ return null;
+ }
+ }));
+ const ok = takes.filter((b): b is AudioBuffer => b !== null);
+ if (ok.length > 0) this.buffers.set(name, ok);
+ }
+
+ /** The next take of a sound: round robin from a random start, never the same take twice running. */
+ private take(name: SoundName): AudioBuffer | null {
+ const list = this.buffers.get(name);
+ if (!list || list.length === 0) return null;
+ if (list.length === 1) return list[0];
+ const last = this.turn.get(name);
+ let next = last === undefined ? Math.floor(Math.random() * list.length) : (last + 1 + Math.floor(Math.random() * (list.length - 1))) % list.length;
+ if (next === last) next = (next + 1) % list.length;
+ this.turn.set(name, next);
+ return list[next];
+ }
+
+ /** Play a loaded sound; null when it cannot be heard (not loaded, no WebAudio, silenced). */
+ play(name: SoundName, o: PlayOptions = {}): Voice | null {
+ const ctx = this.ctx;
+ const master = this.master;
+ if (!ctx || !master) return null;
+ const buffer = this.take(name);
+ if (!buffer) return null;
+ try {
+ const t = ctx.currentTime + (o.delay ?? 0);
+ const src = ctx.createBufferSource();
+ src.buffer = buffer;
+ src.loop = !!o.loop;
+ const pj = o.pitchJitter ?? 0.04;
+ const gj = o.gainJitter ?? 0.1;
+ const rate = (o.rate ?? 1) * (1 + (Math.random() * 2 - 1) * pj);
+ src.playbackRate.value = rate;
+ let level = (o.gain ?? 1) * (1 + (Math.random() * 2 - 1) * gj);
+ let pan = 0;
+ if (o.at && o.listener) {
+ const s = spatial(o.at, o.listener);
+ level *= s.level;
+ pan = s.pan;
+ }
+ const g = ctx.createGain();
+ if (o.fadeIn && o.fadeIn > 0) {
+ g.gain.setValueAtTime(0.0001, t);
+ g.gain.linearRampToValueAtTime(level, t + o.fadeIn);
+ } else {
+ g.gain.setValueAtTime(level, t);
+ }
+ src.connect(g);
+ const panner = pan !== 0 ? ctx.createStereoPanner?.() : undefined;
+ if (panner) {
+ panner.pan.value = pan;
+ g.connect(panner).connect(master);
+ } else {
+ g.connect(master);
+ }
+ src.start(t);
+ let stopped = false;
+ const stop = (fade = 0.08): void => {
+ if (stopped) return;
+ stopped = true;
+ try {
+ const now = ctx.currentTime;
+ g.gain.cancelScheduledValues(now);
+ g.gain.setValueAtTime(g.gain.value, now);
+ g.gain.linearRampToValueAtTime(0.0001, now + Math.max(0.005, fade));
+ src.stop(now + Math.max(0.005, fade) + 0.02);
+ } catch {
+ /* already stopped */
+ }
+ };
+ if (o.duration !== undefined) {
+ const end = t + Math.max(0.02, o.duration);
+ g.gain.setValueAtTime(level, Math.max(t, end - 0.06));
+ g.gain.linearRampToValueAtTime(0.0001, end);
+ src.stop(end + 0.02);
+ stopped = true;
+ }
+ src.onended = () => { try { g.disconnect(); panner?.disconnect(); } catch { /* gone */ } };
+ return {
+ stop,
+ setGain: (gain, ramp = 0.1) => {
+ if (stopped) return;
+ g.gain.setTargetAtTime(Math.max(0.0001, gain), ctx.currentTime, ramp / 3);
+ },
+ setRate: (r, ramp = 0.1) => {
+ if (stopped) return;
+ src.playbackRate.setTargetAtTime(r, ctx.currentTime, ramp / 3);
+ },
+ };
+ } catch (error) {
+ console.debug(`Verse sound ${name} did not play`, error);
+ return null;
+ }
+ }
+
+ /** Close the context (the page is going away). */
+ dispose(): void {
+ if (this.ctx) void this.ctx.close().catch(() => undefined);
+ this.ctx = null;
+ this.master = null;
+ this.buffers.clear();
+ this.loading.clear();
+ }
+}
+
+async function defaultFetch(url: string): Promise<ArrayBuffer> {
+ const res = await fetch(url);
+ if (!res.ok) throw new Error(`${res.status} ${url}`);
+ return res.arrayBuffer();
+}
+
+function decode(ctx: AudioContext, data: ArrayBuffer): Promise<AudioBuffer> {
+ // Older WebKit only has the callback form.
+ return new Promise((resolve, reject) => {
+ const p = ctx.decodeAudioData(data, resolve, reject) as Promise<AudioBuffer> | undefined;
+ if (p && typeof p.then === "function") p.then(resolve, reject);
+ });
+}
+
+let shared: VerseAudio | null = null;
+
+/** The one audio engine every part of the Verse plays through. */
+export function verseAudio(): VerseAudio {
+ shared ??= new VerseAudio();
+ return shared;
+}
diff --git a/dodaios/ui/web/frontend/src/components/society/verse/duel/duelController.ts b/dodaios/ui/web/frontend/src/components/society/verse/duel/duelController.ts
index 9cb3c6a7d6..8a729e09bf 100644
--- a/dodaios/ui/web/frontend/src/components/society/verse/duel/duelController.ts
+++ b/dodaios/ui/web/frontend/src/components/society/verse/duel/duelController.ts
@@ -137,6 +137,7 @@ export class DuelController {
pause(): void {
if (this.phase !== "running") return;
this.input.clear();
+ this.sound?.silence();
this.setPhase("paused");
}
@@ -161,6 +162,7 @@ export class DuelController {
this.duel?.dispose();
this.duel = null;
this.input.clear();
+ this.sound?.silence();
this.visualEvents.length = 0;
this.setPhase("off");
this.onExit?.(at);
@@ -256,7 +258,7 @@ export class DuelController {
if (count !== this.lastCount && count > 0) this.sound?.tick(count === 1);
this.lastCount = count;
const cam = this.camera.pose.position;
- this.sound?.play(events, view.slot, { x: cam.x, z: cam.z, yaw: this.camera.yaw });
+ this.sound?.play(events, view.slot, { x: cam.x, z: cam.z, yaw: this.camera.yaw }, view.players);
}
for (const e of events) this.visualEvents.push(e);
// A burst the renderer never drained (a hidden stage) is not kept forever.
diff --git a/dodaios/ui/web/frontend/src/components/society/verse/duel/duelSound.ts b/dodaios/ui/web/frontend/src/components/society/verse/duel/duelSound.ts
index 1580b6d3a4..d2f39d378f 100644
--- a/dodaios/ui/web/frontend/src/components/society/verse/duel/duelSound.ts
+++ b/dodaios/ui/web/frontend/src/components/society/verse/duel/duelSound.ts
@@ -1,338 +1,200 @@
/**
- * The duel's sound effects, synthesised with WebAudio (no recorded assets):
- * the blaster shot, impacts and body hits, the shield's block and parry,
- * overheat alarm, vent hiss and its perfect/missed chimes, roll whoosh,
- * countdown ticks, the round start and the match's end.
+ * The duel's sound effects: recorded takes (verse/audio, see its CREDITS.md)
+ * for the blaster shot, impacts and body hits, the shield's hum, block and
+ * parry, the overheat alarm and vent hiss, the roll, footsteps on the deck
+ * plating, the countdown beeps, the round start and the match's end.
*
* Sounds from the opponent's side are panned and attenuated by where they
- * happen relative to the camera. The AudioContext is made on the first
- * sound after a user gesture (starting the duel is one); without WebAudio
- * (tests, old browsers) everything is silent.
+ * happen relative to the camera. The takes load when a duel starts (a user
+ * gesture, so the AudioContext may start too); until they have arrived, or
+ * without WebAudio (tests, old browsers), everything is silent.
*/
import type { CombatEvent } from "../combat/types";
+import type { PlayerView } from "../combat/view";
+import { DUEL_SOUNDS, verseAudio, type Listener, type VerseAudio, type Voice } from "../audio/verseAudio";
-type Ctx = AudioContext;
+export type { Listener } from "../audio/verseAudio";
-/** Listener for positional sounds: the camera's position and heading (yaw 0 faces +Z). */
-export interface Listener { x: number; z: number; yaw: number }
+type At = { x: number; z: number } | undefined;
+
+/** Metres between footfalls walking and sprinting. */
+const STRIDE_WALK = 1.45;
+const STRIDE_RUN = 2.1;
export class DuelSound {
- private ctx: Ctx | null = null;
- private master: GainNode | null = null;
- private noise: AudioBuffer | null = null;
- private failed = false;
- volume = 0.55;
+ private readonly audio: VerseAudio;
+ private hum: Voice | null = null;
+ private vent: Voice | null = null;
+ /** Distance each player has covered since their last footfall, and where they were last frame. */
+ private readonly walked = new Map<number, { x: number; z: number; d: number }>();
- private audio(): Ctx | null {
- if (this.ctx || this.failed) return this.ctx;
- try {
- const AC = (window as unknown as { AudioContext?: typeof AudioContext; webkitAudioContext?: typeof AudioContext }).AudioContext
- ?? (window as unknown as { webkitAudioContext?: typeof AudioContext }).webkitAudioContext;
- if (!AC) { this.failed = true; return null; }
- const ctx = new AC();
- const master = ctx.createGain();
- master.gain.value = this.volume;
- // A gentle limiter keeps a burst of shots and impacts from clipping.
- const comp = ctx.createDynamicsCompressor();
- comp.threshold.value = -14;
- comp.ratio.value = 6;
- comp.attack.value = 0.003;
- comp.release.value = 0.12;
- master.connect(comp).connect(ctx.destination);
- const len = Math.floor(ctx.sampleRate * 1.2);
- const buf = ctx.createBuffer(1, len, ctx.sampleRate);
- const data = buf.getChannelData(0);
- let seed = 12345;
- for (let i = 0; i < len; i++) {
- seed = (seed * 1103515245 + 12345) & 0x7fffffff;
- data[i] = (seed / 0x7fffffff) * 2 - 1;
- }
- this.ctx = ctx;
- this.master = master;
- this.noise = buf;
- } catch {
- this.failed = true;
- }
- return this.ctx;
+ constructor(audio: VerseAudio = verseAudio()) {
+ this.audio = audio;
}
- /** Wake the audio (call from a user gesture). */
+ /** Wake the audio and fetch the duel's sounds (call from a user gesture: starting the duel is one). */
resume(): void {
- const ctx = this.audio();
- if (ctx && ctx.state === "suspended") void ctx.resume().catch(() => undefined);
- }
-
- dispose(): void {
- if (this.ctx) void this.ctx.close().catch(() => undefined);
- this.ctx = null;
- this.master = null;
- }
-
- /** An output for a sound at (x, z) heard from the listener; null for a sound at the listener. */
- private out(ctx: Ctx, gain: number, at?: { x: number; z: number } | null, l?: Listener | null): AudioNode {
- const g = ctx.createGain();
- let level = gain;
- if (at && l) {
- const dx = at.x - l.x;
- const dz = at.z - l.z;
- const d = Math.hypot(dx, dz);
- level *= 1 / (1 + Math.max(0, d - 2) / 9);
- if (d > 0.5) {
- const rel = Math.atan2(dx, dz) - l.yaw;
- // Right of the heading is negative rel (yaw grows to the left), so the pan is -sin(rel).
- const pan = ctx.createStereoPanner?.();
- if (pan) {
- pan.pan.value = Math.max(-0.85, Math.min(0.85, -Math.sin(rel)));
- g.connect(pan).connect(this.master as GainNode);
- g.gain.value = level;
- return g;
- }
- }
- }
- g.gain.value = level;
- g.connect(this.master as GainNode);
- return g;
+ this.audio.resume();
+ void this.audio.preload(DUEL_SOUNDS);
}
- private env(ctx: Ctx, node: AudioNode, t: number, attack: number, peak: number, decay: number): GainNode {
- const g = ctx.createGain();
- g.gain.setValueAtTime(0.0001, t);
- g.gain.exponentialRampToValueAtTime(Math.max(0.0002, peak), t + attack);
- g.gain.exponentialRampToValueAtTime(0.0001, t + attack + decay);
- node.connect(g);
- return g;
+ /** Stop what is still sounding (the shield's hum, a vent): the match paused or ended. */
+ silence(): void {
+ this.dispose();
}
- private tone(ctx: Ctx, out: AudioNode, type: OscillatorType, f0: number, f1: number, t: number, attack: number, peak: number, decay: number): void {
- const o = ctx.createOscillator();
- o.type = type;
- o.frequency.setValueAtTime(f0, t);
- if (f1 !== f0) o.frequency.exponentialRampToValueAtTime(Math.max(20, f1), t + attack + decay);
- this.env(ctx, o, t, attack, peak, decay).connect(out);
- o.start(t);
- o.stop(t + attack + decay + 0.05);
+ dispose(): void {
+ this.hum?.stop(0.05);
+ this.hum = null;
+ this.vent?.stop(0.05);
+ this.vent = null;
+ this.walked.clear();
}
- private hiss(ctx: Ctx, out: AudioNode, kind: BiquadFilterType, f0: number, f1: number, q: number, t: number, attack: number, peak: number, decay: number): void {
- const src = ctx.createBufferSource();
- src.buffer = this.noise;
- src.loop = true;
- const f = ctx.createBiquadFilter();
- f.type = kind;
- f.Q.value = q;
- f.frequency.setValueAtTime(f0, t);
- if (f1 !== f0) f.frequency.exponentialRampToValueAtTime(Math.max(20, f1), t + attack + decay);
- src.connect(f);
- this.env(ctx, f, t, attack, peak, decay).connect(out);
- src.start(t, Math.random() * 0.8);
- src.stop(t + attack + decay + 0.05);
+ private remote(local: boolean, at: At, l?: Listener | null) {
+ return local ? {} : { at: at ?? null, listener: l ?? null };
}
- /** The blaster: a bright descending zap over a short noise crack and a low thump. */
- shot(local: boolean, at?: { x: number; z: number }, l?: Listener | null): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, local ? 0.8 : 0.6, local ? null : at, l);
- const pitch = 0.94 + Math.random() * 0.12;
- this.tone(ctx, out, "sawtooth", 2400 * pitch, 260 * pitch, t, 0.002, 0.22, 0.14);
- this.tone(ctx, out, "square", 1300 * pitch, 180 * pitch, t, 0.002, 0.12, 0.11);
- this.hiss(ctx, out, "bandpass", 5200, 1800, 1.4, t, 0.001, 0.5, 0.06);
- this.tone(ctx, out, "sine", 150, 48, t, 0.003, local ? 0.6 : 0.35, 0.12);
+ shot(local: boolean, at?: At, l?: Listener | null): void {
+ this.audio.play("shot", { gain: local ? 0.9 : 0.75, pitchJitter: 0.05, ...this.remote(local, at, l) });
}
- /** A bolt meets a wall or the floor: crack and sizzle. */
impact(at: { x: number; z: number }, l?: Listener | null): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.55, at, l);
- this.hiss(ctx, out, "lowpass", 3200, 500, 0.8, t, 0.001, 0.7, 0.16);
- this.hiss(ctx, out, "highpass", 6000, 6000, 0.7, t + 0.01, 0.01, 0.12, 0.3);
- this.tone(ctx, out, "triangle", 420, 90, t, 0.001, 0.25, 0.08);
+ this.audio.play("impact", { gain: 0.6, pitchJitter: 0.08, at, listener: l ?? null });
}
- /** A bolt hits a body: a dull thud with a burn; the shooter hears a crisp marker tick. */
- bodyHit(local: boolean, headshot: boolean, at?: { x: number; z: number }, l?: Listener | null): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, local ? 0.75 : 0.5, local ? null : at, l);
- this.tone(ctx, out, "sine", 210, 60, t, 0.002, 0.7, 0.14);
- this.hiss(ctx, out, "bandpass", 1800, 700, 1.2, t, 0.002, 0.45, 0.18);
- if (headshot) this.tone(ctx, out, "triangle", 900, 500, t, 0.002, 0.3, 0.12);
+ bodyHit(local: boolean, at?: At, l?: Listener | null): void {
+ this.audio.play("body_hit", { gain: local ? 1 : 0.7, ...this.remote(local, at, l) });
}
- /** The shooter's hit confirmation. */
+ /** The shooter's hit confirmation: a short tick, higher for a headshot, doubled for the kill. */
marker(kind: "hit" | "head" | "kill"): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.35);
- if (kind === "kill") {
- this.tone(ctx, out, "triangle", 880, 880, t, 0.002, 0.5, 0.18);
- this.tone(ctx, out, "triangle", 1320, 1320, t + 0.07, 0.002, 0.45, 0.32);
- return;
- }
- this.tone(ctx, out, "sine", kind === "head" ? 2600 : 2100, kind === "head" ? 2600 : 2100, t, 0.001, 0.4, 0.05);
- if (kind === "head") this.tone(ctx, out, "sine", 3300, 3300, t + 0.045, 0.001, 0.35, 0.06);
+ this.audio.play("marker", { gain: 0.5, rate: kind === "head" ? 1.25 : 1, pitchJitter: 0.01 });
+ if (kind === "kill") this.audio.play("marker", { gain: 0.5, rate: 1.5, pitchJitter: 0.01, delay: 0.08 });
}
- /** The shield absorbs a bolt: an electric crackle with a hum. */
- block(at?: { x: number; z: number }, l?: Listener | null): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.6, at, l);
- this.tone(ctx, out, "square", 180, 140, t, 0.002, 0.25, 0.2);
- this.hiss(ctx, out, "bandpass", 2600, 1200, 3, t, 0.002, 0.6, 0.2);
- this.tone(ctx, out, "sawtooth", 620, 380, t, 0.002, 0.12, 0.16);
+ block(at?: At, l?: Listener | null): void {
+ this.audio.play("block", { gain: 0.75, at: at ?? null, listener: l ?? null });
}
- /** A deflection glances off with a whine. */
- deflect(at?: { x: number; z: number }, l?: Listener | null): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.55, at, l);
- this.tone(ctx, out, "triangle", 900, 2600, t, 0.002, 0.3, 0.22);
- this.hiss(ctx, out, "bandpass", 3500, 3500, 2, t, 0.002, 0.3, 0.12);
+ deflect(at?: At, l?: Listener | null): void {
+ this.audio.play("deflect", { gain: 0.7, pitchJitter: 0.08, at: at ?? null, listener: l ?? null });
}
- /** A perfect parry: a bright bell ring and a rising zing. */
- parry(at?: { x: number; z: number }, l?: Listener | null): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.75, at, l);
- this.tone(ctx, out, "sine", 1320, 1320, t, 0.002, 0.55, 0.7);
- this.tone(ctx, out, "sine", 1980, 1980, t, 0.002, 0.35, 0.55);
- this.tone(ctx, out, "triangle", 2640, 2700, t, 0.002, 0.2, 0.4);
- this.tone(ctx, out, "sawtooth", 600, 3200, t, 0.002, 0.12, 0.18);
- this.hiss(ctx, out, "highpass", 5000, 8000, 1, t, 0.001, 0.3, 0.1);
+ parry(at?: At, l?: Listener | null): void {
+ this.audio.play("parry", { gain: 0.9, pitchJitter: 0.02, at: at ?? null, listener: l ?? null });
+ this.audio.play("block", { gain: 0.45, rate: 1.3, at: at ?? null, listener: l ?? null });
}
+ /** The person's shield comes up: a power-on thump and a hum that lasts while it is raised. */
shieldUp(local: boolean): void {
- const ctx = this.audio();
- if (!ctx || !local) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.3);
- this.tone(ctx, out, "sawtooth", 110, 220, t, 0.03, 0.25, 0.18);
- this.tone(ctx, out, "sine", 440, 660, t, 0.02, 0.12, 0.15);
+ if (!local) return;
+ this.audio.play("shield_up", { gain: 0.55 });
+ this.hum?.stop(0.05);
+ this.hum = this.audio.play("shield_hum", { gain: 0.28, loop: true, fadeIn: 0.12, pitchJitter: 0 });
}
shieldDown(local: boolean): void {
- const ctx = this.audio();
- if (!ctx || !local) return;
- const t = ctx.currentTime;
- this.tone(ctx, this.out(ctx, 0.22), "sawtooth", 220, 90, t, 0.01, 0.2, 0.14);
+ if (!local) return;
+ if (this.hum) {
+ this.hum.setRate(0.8, 0.15);
+ this.hum.stop(0.18);
+ this.hum = null;
+ }
}
- shieldBreak(at?: { x: number; z: number }, l?: Listener | null): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.6, at, l);
- this.hiss(ctx, out, "bandpass", 4000, 400, 1.5, t, 0.002, 0.8, 0.45);
- this.tone(ctx, out, "square", 300, 60, t, 0.002, 0.3, 0.4);
+ shieldBreak(at?: At, l?: Listener | null): void {
+ this.hum?.stop(0.05);
+ this.hum = null;
+ this.audio.play("shield_break", { gain: 0.8, at: at ?? null, listener: l ?? null });
}
- /** Overheat: a falling two-tone alarm over a hiss. */
overheat(): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.4);
- for (let i = 0; i < 3; i++) {
- this.tone(ctx, out, "square", 980, 980, t + i * 0.16, 0.004, 0.28, 0.06);
- this.tone(ctx, out, "square", 735, 735, t + i * 0.16 + 0.075, 0.004, 0.28, 0.06);
- }
- this.hiss(ctx, out, "highpass", 3000, 1500, 0.7, t, 0.02, 0.35, 0.7);
+ this.audio.play("overheat", { gain: 0.5, pitchJitter: 0 });
}
- vent(seconds: number): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- this.hiss(ctx, this.out(ctx, 0.35), "bandpass", 5000, 1400, 0.9, t, 0.03, 0.5, Math.max(0.3, seconds));
+ ventStart(seconds: number): void {
+ this.vent?.stop(0.05);
+ this.vent = this.audio.play("vent", { gain: 0.55, duration: Math.max(0.35, seconds), pitchJitter: 0.03 });
}
ventPerfect(): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.35);
- this.tone(ctx, out, "triangle", 1046, 1046, t, 0.002, 0.4, 0.15);
- this.tone(ctx, out, "triangle", 1568, 1568, t + 0.06, 0.002, 0.4, 0.3);
+ this.vent?.stop(0.12);
+ this.vent = null;
+ this.audio.play("vent_perfect", { gain: 0.6, pitchJitter: 0 });
}
ventMiss(): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- this.tone(ctx, this.out(ctx, 0.3), "square", 140, 120, t, 0.004, 0.3, 0.18);
+ this.audio.play("vent_miss", { gain: 0.6, pitchJitter: 0.02 });
}
- dodge(local: boolean, at?: { x: number; z: number }, l?: Listener | null): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- this.hiss(ctx, this.out(ctx, local ? 0.45 : 0.3, local ? null : at, l), "bandpass", 600, 2400, 1.6, t, 0.06, 0.6, 0.22);
+ dodge(local: boolean, at?: At, l?: Listener | null): void {
+ this.audio.play("dodge", { gain: local ? 0.8 : 0.55, ...this.remote(local, at, l) });
}
- death(at?: { x: number; z: number }, l?: Listener | null): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.6, at, l);
- this.tone(ctx, out, "sine", 120, 35, t, 0.005, 0.8, 0.6);
- this.hiss(ctx, out, "lowpass", 900, 120, 0.7, t, 0.005, 0.5, 0.5);
+ death(at?: At, l?: Listener | null): void {
+ this.audio.play("death", { gain: 0.9, pitchJitter: 0.03, at: at ?? null, listener: l ?? null });
}
- /** One countdown second. */
+ /** One countdown second; the last one is higher. */
tick(last: boolean): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- this.tone(ctx, this.out(ctx, 0.3), "sine", last ? 880 : 660, last ? 880 : 660, t, 0.003, 0.4, 0.12);
+ this.audio.play("beep", { gain: 0.45, rate: last ? 1.5 : 1, pitchJitter: 0 });
}
- /** The round starts: a rising sweep into a bright chord. */
roundStart(): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.4);
- this.tone(ctx, out, "sawtooth", 220, 880, t, 0.02, 0.18, 0.25);
- for (const f of [523, 659, 784]) this.tone(ctx, out, "triangle", f, f, t + 0.2, 0.01, 0.22, 0.5);
+ this.audio.play("round_start", { gain: 0.6, pitchJitter: 0 });
}
roundEnd(won: boolean): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.35);
- const chord = won ? [523, 659, 784, 1046] : [440, 523, 622];
- chord.forEach((f, i) => this.tone(ctx, out, "triangle", f, f, t + i * 0.07, 0.01, 0.22, 0.6));
+ this.hum?.stop(0.1);
+ this.hum = null;
+ this.audio.play("round_end", { gain: 0.6, rate: won ? 1 : 0.84, pitchJitter: 0 });
}
surge(): void {
- const ctx = this.audio();
- if (!ctx) return;
- const t = ctx.currentTime;
- const out = this.out(ctx, 0.35);
- for (let i = 0; i < 2; i++) this.tone(ctx, out, "sawtooth", 160, 320, t + i * 0.45, 0.05, 0.25, 0.3);
+ this.audio.play("surge", { gain: 0.5, pitchJitter: 0 });
+ }
+
+ /** Footfalls on the plating for every player on their feet, from how far each moved since the last frame. */
+ steps(players: readonly PlayerView[], slot: number, l: Listener | null): void {
+ for (const p of players) {
+ const prev = this.walked.get(p.slot);
+ if (!prev || !p.alive || p.dodging) {
+ this.walked.set(p.slot, { x: p.x, z: p.z, d: prev && p.alive ? prev.d : 0 });
+ continue;
+ }
+ const moved = Math.hypot(p.x - prev.x, p.z - prev.z);
+ // A respawn or a round's reset teleports: no footfall for that.
+ const d = moved > 1.5 ? 0 : prev.d + moved;
+ const stride = p.sprinting ? STRIDE_RUN : STRIDE_WALK;
+ const local = p.slot === slot;
+ if (d >= stride && p.speed > 0.4) {
+ const run = p.sprinting;
+ this.audio.play("step", {
+ gain: (run ? 0.55 : 0.38) * (local ? 1 : 0.9),
+ rate: run ? 1.06 : 1,
+ pitchJitter: 0.06,
+ gainJitter: 0.2,
+ ...this.remote(local, p, l),
+ });
+ this.walked.set(p.slot, { x: p.x, z: p.z, d: 0 });
+ } else {
+ this.walked.set(p.slot, { x: p.x, z: p.z, d: p.speed > 0.4 ? d : Math.min(d, stride * 0.6) });
+ }
+ }
}
/** Play whatever a frame's events call for. `slot` is the person's. */
- play(events: readonly CombatEvent[], slot: number, l: Listener | null): void {
+ play(events: readonly CombatEvent[], slot: number, l: Listener | null, players?: readonly PlayerView[]): void {
+ if (players) this.steps(players, slot, l);
if (events.length === 0) return;
+ const where = (player: number): At => players?.find((p) => p.slot === player);
for (const e of events) {
switch (e.type) {
case "shot": this.shot(e.player === slot, e, l); break;
case "impact": this.impact(e, l); break;
case "hit":
- this.bodyHit(e.target === slot, e.headshot, e, l);
+ this.bodyHit(e.target === slot, e, l);
if (e.owner === slot && e.target !== slot) this.marker(e.health <= 0 ? "kill" : e.headshot ? "head" : "hit");
break;
case "block": this.block(e, l); break;
@@ -340,13 +202,13 @@ export class DuelSound {
case "parry": this.parry(e, l); break;
case "shield_up": this.shieldUp(e.player === slot); break;
case "shield_down": this.shieldDown(e.player === slot); break;
- case "shield_break": this.shieldBreak(undefined, l); break;
+ case "shield_break": this.shieldBreak(e.player === slot ? undefined : where(e.player), l); break;
case "overheat": if (e.player === slot) this.overheat(); break;
- case "vent_start": if (e.player === slot) this.vent((e.end - e.tick) / 60); break;
+ case "vent_start": if (e.player === slot) this.ventStart((e.end - e.tick) / 60); break;
case "vent_perfect": if (e.player === slot) this.ventPerfect(); break;
case "vent_miss": if (e.player === slot) this.ventMiss(); break;
- case "dodge": this.dodge(e.player === slot); break;
- case "death": this.death(undefined, l); break;
+ case "dodge": this.dodge(e.player === slot, where(e.player), l); break;
+ case "death": this.death(e.player === slot ? undefined : where(e.player), l); break;
case "round_start": this.roundStart(); break;
case "round_end": this.roundEnd(e.winner === slot); break;
case "surge": this.surge(); break;
diff --git a/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/eyeLevelGame.test.tsx b/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/eyeLevelGame.test.tsx
index a1b41f989b..1d65c9cb14 100644
--- a/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/eyeLevelGame.test.tsx
+++ b/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/eyeLevelGame.test.tsx
@@ -250,11 +250,11 @@ describe("view settings", () => {
it("reads anything stored as valid settings", () => {
expect(normalizeViewPrefs(null)).toEqual(VIEW_DEFAULTS);
- expect(normalizeViewPrefs({ sensitivity: 99, invertY: "yes", quality: "ultra", fovThird: 400, fovFirst: "wide", view: "top" })).toEqual({
- ...VIEW_DEFAULTS, sensitivity: LOOK_SENSITIVITY.max, fovThird: SHOULDER.maxHfovDeg,
+ expect(normalizeViewPrefs({ sensitivity: 99, invertY: "yes", quality: "ultra", fovThird: 400, fovFirst: "wide", volume: 7, view: "top" })).toEqual({
+ ...VIEW_DEFAULTS, sensitivity: LOOK_SENSITIVITY.max, fovThird: SHOULDER.maxHfovDeg, volume: 1,
});
- expect(normalizeViewPrefs({ sensitivity: 0.5, invertY: true, quality: "low", fovThird: 64, fovFirst: 95, view: "first" })).toEqual({
- sensitivity: 0.5, invertY: true, quality: "low", fovThird: 64, fovFirst: 95, view: "first",
+ expect(normalizeViewPrefs({ sensitivity: 0.5, invertY: true, quality: "low", fovThird: 64, fovFirst: 95, volume: 0.25, view: "first" })).toEqual({
+ sensitivity: 0.5, invertY: true, quality: "low", fovThird: 64, fovFirst: 95, volume: 0.25, view: "first",
});
});
diff --git a/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/viewSettings.ts b/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/viewSettings.ts
index 3fa15e293a..49006aba30 100644
--- a/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/viewSettings.ts
+++ b/dodaios/ui/web/frontend/src/components/society/verse/engine/realtime/viewSettings.ts
@@ -1,9 +1,9 @@
/**
* The person's own settings for the eye-level views: mouse sensitivity, an
* inverted vertical axis, the field of view in third and in first person,
- * the render quality, and the view they last chose (bird's-eye, third or
- * first person). Cosmetic and local to this browser (localStorage, every
- * access guarded); never synced. Without storage the defaults apply and
+ * the render quality, the view they last chose (bird's-eye, third or
+ * first person) and the Verse's sound volume. Cosmetic and local to this
+ * browser (localStorage, every access guarded); never synced. Without storage the defaults apply and
* changes last for the session.
*/
import { create } from "zustand";
@@ -23,6 +23,8 @@ export interface ViewPrefs {
/** Horizontal field of view in third and in first person, degrees (SHOULDER.minHfovDeg–maxHfovDeg). */
fovThird: number;
fovFirst: number;
+ /** The Verse's sound level, 0 (silent) to 1. */
+ volume: number;
/** The view the person last chose. */
view: VerseView;
}
@@ -34,7 +36,7 @@ export interface ViewSettings extends ViewPrefs {
export const VIEW_SETTINGS_KEY = "dodaios.verse.view.v1";
export const VIEW_DEFAULTS: Readonly<ViewPrefs> = {
- sensitivity: 1, invertY: false, quality: "auto", fovThird: SHOULDER.hfovDeg, fovFirst: SHOULDER.firstHfovDeg, view: "third",
+ sensitivity: 1, invertY: false, quality: "auto", fovThird: SHOULDER.hfovDeg, fovFirst: SHOULDER.firstHfovDeg, volume: 0.7, view: "third",
};
/** Whatever was stored (or nothing), as valid settings. Pure. */
@@ -49,6 +51,7 @@ export function normalizeViewPrefs(raw: unknown): ViewPrefs {
quality: o.quality === "high" || o.quality === "low" ? o.quality : "auto",
fovThird: typeof o.fovThird === "number" ? clampHfov(o.fovThird, VIEW_DEFAULTS.fovThird) : VIEW_DEFAULTS.fovThird,
fovFirst: typeof o.fovFirst === "number" ? clampHfov(o.fovFirst, VIEW_DEFAULTS.fovFirst) : VIEW_DEFAULTS.fovFirst,
+ volume: typeof o.volume === "number" && Number.isFinite(o.volume) ? Math.min(1, Math.max(0, o.volume)) : VIEW_DEFAULTS.volume,
view: normalizeView(o.view),
};
}
@@ -71,7 +74,7 @@ function write(prefs: ViewPrefs): void {
}
const prefsOf = (s: ViewPrefs): ViewPrefs => ({
- sensitivity: s.sensitivity, invertY: s.invertY, quality: s.quality, fovThird: s.fovThird, fovFirst: s.fovFirst, view: s.view,
+ sensitivity: s.sensitivity, invertY: s.invertY, quality: s.quality, fovThird: s.fovThird, fovFirst: s.fovFirst, volume: s.volume, view: s.view,
});
export const useViewSettings = create<ViewSettings>((set, get) => ({
diff --git a/dodaios/ui/web/frontend/src/components/society/verse/hud/ViewSettingsPanel.tsx b/dodaios/ui/web/frontend/src/components/society/verse/hud/ViewSettingsPanel.tsx
index 904d885292..abb80f7d1e 100644
--- a/dodaios/ui/web/frontend/src/components/society/verse/hud/ViewSettingsPanel.tsx
+++ b/dodaios/ui/web/frontend/src/components/society/verse/hud/ViewSettingsPanel.tsx
@@ -1,7 +1,7 @@
/**
* The eye-level views' settings: mouse sensitivity, an inverted vertical
- * axis, the field of view in third and in first person, and the render
- * quality. Changes apply at once and stay in this
+ * axis, the field of view in third and in first person, the sound volume
+ * and the render quality. Changes apply at once and stay in this
* browser (`viewSettings`).
*/
import { useId, useRef } from "react";
@@ -25,6 +25,7 @@ export function ViewSettingsPanel({ t, tier, onClose }: Props) {
const quality = useViewSettings((s) => s.quality);
const fovThird = useViewSettings((s) => s.fovThird);
const fovFirst = useViewSettings((s) => s.fovFirst);
+ const volume = useViewSettings((s) => s.volume);
const set = useViewSettings((s) => s.set);
const reset = useViewSettings((s) => s.reset);
const first = useRef<HTMLInputElement>(null);
@@ -80,6 +81,22 @@ export function ViewSettingsPanel({ t, tier, onClose }: Props) {
/>
</div>
))}
+ <div className="verse-field">
+ <label className="verse-setting-head" htmlFor={`${id}-volume`}>
+ <span className="verse-label">{t("verse.settings.volume")}</span>
+ <span className="verse-setting-value">{Math.round(volume * 100)}%</span>
+ </label>
+ <input
+ id={`${id}-volume`}
+ type="range"
+ className="verse-range"
+ min={0}
+ max={1}
+ step={0.05}
+ value={volume}
+ onChange={(e) => set({ volume: Number(e.target.value) })}
+ />
+ </div>
<div className="verse-field">
<span className="verse-label" id={`${id}-quality`}>{t("verse.settings.quality")}</span>
<div className="verse-seg" role="group" aria-labelledby={`${id}-quality`}>
diff --git a/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.de.json b/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.de.json
index 25023635e7..295e531e8f 100644
--- a/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.de.json
+++ b/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.de.json
@@ -119,7 +119,8 @@
"mouse_lock": "In Third Person und Ego-Perspektive fängt ein Klick in die Ansicht die Maus: Bewegen dreht die Kamera, die linke Maustaste benutzt, worauf das Fadenkreuz zeigt. Esc gibt sie frei; L fängt sie oder gibt sie ebenfalls frei.",
"reset": "Zurücksetzen",
"fov_third": "Sichtfeld, Third Person",
- "fov_first": "Sichtfeld, Ego-Perspektive"
+ "fov_first": "Sichtfeld, Ego-Perspektive",
+ "volume": "Lautstärke"
},
"lift": {
"title": "Turbolift",
diff --git a/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.en.json b/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.en.json
index 9b0df71329..047331b3e0 100644
--- a/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.en.json
+++ b/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.en.json
@@ -119,7 +119,8 @@
"mouse_lock": "In third and first person a click on the view takes the mouse: moving it turns the camera, the left button works what the crosshair is on. Esc gives it back; L takes or releases it too.",
"reset": "Reset",
"fov_third": "Field of view, third person",
- "fov_first": "Field of view, first person"
+ "fov_first": "Field of view, first person",
+ "volume": "Sound volume"
},
"lift": {
"title": "Turbolift",
diff --git a/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.es.json b/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.es.json
index f862047022..279d9ef8e8 100644
--- a/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.es.json
+++ b/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.es.json
@@ -119,7 +119,8 @@
"mouse_lock": "En tercera y primera persona un clic en la vista captura el ratón: moverlo gira la cámara y el botón izquierdo usa lo que señala la mira. Esc lo libera; L también lo captura o lo libera.",
"reset": "Restablecer",
"fov_third": "Campo de visión, tercera persona",
- "fov_first": "Campo de visión, primera persona"
+ "fov_first": "Campo de visión, primera persona",
+ "volume": "Volumen del sonido"
},
"lift": {
"title": "Turboascensor",
diff --git a/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.pt.json b/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.pt.json
index 4a003df99d..5ec8c41576 100644
--- a/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.pt.json
+++ b/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.pt.json
@@ -119,7 +119,8 @@
"mouse_lock": "Em terceira e primeira pessoa um clique na vista captura o mouse: movê-lo gira a câmera e o botão esquerdo usa o que a mira aponta. Esc o libera; L também o captura ou libera.",
"reset": "Redefinir",
"fov_third": "Campo de visão, terceira pessoa",
- "fov_first": "Campo de visão, primeira pessoa"
+ "fov_first": "Campo de visão, primeira pessoa",
+ "volume": "Volume do som"
},
"lift": {
"title": "Turboelevador",
diff --git a/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.zh.json b/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.zh.json
index bf66885159..bfbdcdffa9 100644
--- a/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.zh.json
+++ b/dodaios/ui/web/frontend/src/i18n/locales/ship/verse.zh.json
@@ -119,7 +119,8 @@
"mouse_lock": "在第三人称和第一人称下,点击画面即锁定鼠标:移动鼠标转动镜头,左键使用准星所指的对象。Esc 释放;L 也可锁定或释放。",
"reset": "重置",
"fov_third": "视野(第三人称)",
- "fov_first": "视野(第一人称)"
+ "fov_first": "视野(第一人称)",
+ "volume": "音量"
},
"lift": {
"title": "升降梯",