2026-12-05 20:29:27 -05:00
|
|
|
|
# Adaptive Music architecture — 0.8.3
|
2026-12-04 08:58:47 -05:00
|
|
|
|
|
|
|
|
|
|
Adaptive Music is an independent project by CheddahBoxMB for Foundry v14.371 and
|
|
|
|
|
|
MA 2.10.6, with no system dependency or additional required process. The expanded
|
|
|
|
|
|
operator authorization selects direct trusted-GM browser access and GM-local
|
|
|
|
|
|
credential handling for the standalone module; it supersedes the older gateway-only
|
|
|
|
|
|
scaffolding rule. Optional historical gateway source is not required or deployed.
|
|
|
|
|
|
|
|
|
|
|
|
## Setup and receiver ownership
|
|
|
|
|
|
|
2026-12-04 11:08:09 -05:00
|
|
|
|
The Connection tab validates the server, token and optional Advanced network fields
|
|
|
|
|
|
before authentication. The Connect gesture starts the GM audio context before
|
|
|
|
|
|
authentication, receiver provisioning and catalog loading. Playback reads the
|
|
|
|
|
|
dedicated MA queue and submits controls on the same controller as scene transitions.
|
|
|
|
|
|
|
2026-12-04 08:58:47 -05:00
|
|
|
|
The GM supplies the private trusted HTTPS MA origin and access token. Authentication
|
|
|
|
|
|
reads account-authorized music providers. The official pinned Sendspin SDK generates
|
|
|
|
|
|
one X25519 identity for the campaign, GM user and MA origin. Its identity, pairing
|
|
|
|
|
|
storage, catalog key and name are encrypted in local IndexedDB with a non-extractable
|
|
|
|
|
|
AES-GCM key. The key is stored in the same browser; this does not protect against
|
2026-12-05 09:40:14 -05:00
|
|
|
|
trusted-origin scripts or theft of the complete browser profile. A GM can opt in
|
|
|
|
|
|
to a separate encrypted device record with the MA token, address, receiver name
|
|
|
|
|
|
and reconnect preference. Receiver records exclude credentials. Both records are
|
|
|
|
|
|
scoped to the Foundry origin, world and user. Without opt-in, failed attempts
|
|
|
|
|
|
retain private input in tab memory. A different MA origin uses separate credentials
|
|
|
|
|
|
and receiver identity.
|
2026-12-04 08:58:47 -05:00
|
|
|
|
|
2026-12-04 11:08:09 -05:00
|
|
|
|
The logged-in GM account can retain an AES-GCM envelope containing the last
|
|
|
|
|
|
successfully connected MA address and receiver name in a Foundry User Setting.
|
|
|
|
|
|
The MA token supplied for a connection unlocks the envelope. Its key is derived
|
|
|
|
|
|
with a separate purpose label and bound to the Foundry origin, world and user.
|
|
|
|
|
|
Foundry persists the encrypted record across devices and server restarts.
|
|
|
|
|
|
|
2026-12-04 08:58:47 -05:00
|
|
|
|
Connect audio first authenticates the `/ws` API session, then authenticates
|
|
|
|
|
|
`/sendspin` using that token and the SDK-generated client ID. MA 2.10.6 associates
|
|
|
|
|
|
this new web receiver with already-authenticated API sessions for the token. The
|
|
|
|
|
|
same API session must therefore survive pairing, catalog reads and playback.
|
2026-12-05 09:40:14 -05:00
|
|
|
|
MA 2.10.6 associates all API sessions carrying the same restricted token with the
|
|
|
|
|
|
last Sendspin browser receiver to connect using it. Concurrent receivers need
|
|
|
|
|
|
separate tokens. Loss of receiver access stops automation without retargeting.
|
2026-12-04 08:58:47 -05:00
|
|
|
|
`sendspin/pair_web_player` pairs only this identity to the calling account. Noise
|
|
|
|
|
|
activation and clock synchronization precede exact ID/name/provider/topology checks.
|
|
|
|
|
|
During startup, a successful null queue lookup is retried briefly on the same
|
|
|
|
|
|
authenticated API session because MA can expose the player before registering its
|
|
|
|
|
|
queue. Playback requires the receiver’s own active queue.
|
|
|
|
|
|
There is no household player list or arbitrary target selector.
|
|
|
|
|
|
|
|
|
|
|
|
The receiver uses SDK software volume. Fresh receivers do not report volume before
|
|
|
|
|
|
capabilities are advertised, so volume cannot be a preconnection requirement. Static
|
|
|
|
|
|
account-authorized playlist tracks become opaque HMAC references bound to the stored
|
2026-12-04 11:08:09 -05:00
|
|
|
|
catalog key and campaign. New references use a separate key derived from the MA
|
|
|
|
|
|
token, MA origin and campaign so the same authorized catalog resolves on another
|
|
|
|
|
|
browser. A browser with its original receiver vault still resolves legacy IDs.
|
2026-12-05 09:40:14 -05:00
|
|
|
|
Saving that scene again writes the new reference. Scene and world flags hold opaque references. The active GM browser and its audio
|
|
|
|
|
|
context host the live connection. Disconnect ends that session and pauses automatic
|
|
|
|
|
|
reconnection.
|
2026-12-04 08:58:47 -05:00
|
|
|
|
|
|
|
|
|
|
## Audio and listeners
|
|
|
|
|
|
|
|
|
|
|
|
The pinned official SDK negotiates PCM, performs Noise and time synchronization,
|
2026-12-05 09:40:14 -05:00
|
|
|
|
and decodes audio. A bounded Web Audio timeline anchors a packet run to the local
|
|
|
|
|
|
audio clock and advances it by each rendered chunk’s length. The browser converts
|
|
|
|
|
|
sample rates from each AudioBuffer’s input rate. A 120 ms startup cushion and
|
|
|
|
|
|
bounded 0.1% rate correction absorb jitter and drift. The queue allows eight
|
|
|
|
|
|
seconds of server lead, up to 768 active nodes and 8 MiB of decoded audio. It
|
|
|
|
|
|
counts source timestamp gaps and overlaps separately from late drops and local
|
|
|
|
|
|
underruns. Timestamped partial clears trim only invalid audio. Separate
|
|
|
|
|
|
transition and volume gains feed the GM output and one MediaStreamDestination
|
|
|
|
|
|
track for listener distribution.
|
2026-12-04 08:58:47 -05:00
|
|
|
|
|
|
|
|
|
|
User document public keys authenticate ephemeral ECDH/AES-GCM invitation delivery.
|
|
|
|
|
|
Private keys stay in memory. Invitations are bound to world, sender, recipient,
|
|
|
|
|
|
epochs and expiry. Each player receives only its own WebRTC capability. Bounded
|
|
|
|
|
|
AES-GCM envelopes carry SDP over Foundry’s module socket; audio uses DTLS-SRTP,
|
|
|
|
|
|
never PCM over that socket. Firefox’s session-level SDP direction default is
|
|
|
|
|
|
correctly overridden by the sole audio media direction. Offers remain recvonly;
|
|
|
|
|
|
answers remain sendonly. Video, data and injected sender media are rejected.
|
|
|
|
|
|
|
2026-12-05 09:40:14 -05:00
|
|
|
|
Up to eight listeners negotiate automatically. A signaling invitation expires
|
|
|
|
|
|
after 30 minutes. Established DTLS-SRTP media continues while its listener and GM
|
|
|
|
|
|
remain authorized. Failed negotiation times out after 20 seconds and a disconnected
|
|
|
|
|
|
peer is dropped after 10 seconds. The reconciliation loop can invite the listener
|
2026-12-05 20:29:27 -05:00
|
|
|
|
again. Foundry's connection and User document events reconcile listeners
|
|
|
|
|
|
without replacing the GM transport. One user gesture unlocks browser audio when
|
|
|
|
|
|
required. A stable HTMLAudioElement and optional activated Web Audio path play
|
|
|
|
|
|
the incoming track. Each listener's local output applies their saved mute and
|
|
|
|
|
|
volume settings downstream of WebRTC. Default ICE uses no public STUN/TURN service.
|
|
|
|
|
|
The GM's personal monitor gain sits on the local output branch after the split
|
|
|
|
|
|
to the listener stream. Campaign volume remains upstream of that split.
|
2026-12-04 08:58:47 -05:00
|
|
|
|
|
|
|
|
|
|
## Transitions and recovery
|
|
|
|
|
|
|
2026-12-05 13:37:05 -05:00
|
|
|
|
Manual override/silence > combatant boss override > designated encounter boss cue
|
|
|
|
|
|
> started combat in the active scene > ambient > world default > silence.
|
|
|
|
|
|
An explicit combat scene takes precedence. An unlinked encounter with
|
|
|
|
|
|
scene-bound combatants applies to their scenes. An unlinked encounter with no
|
|
|
|
|
|
scene-bound combatants is global. Begun, active encounters are resolved through
|
|
|
|
|
|
post-operation combat and combatant hooks. No system actor schemas are used. The existing
|
2026-12-04 08:58:47 -05:00
|
|
|
|
serialized controller checks campaign/session/generation and current authority.
|
2026-12-05 20:29:27 -05:00
|
|
|
|
Authority requires one active full Gamemaster. Foundry's Assistant GM role is
|
|
|
|
|
|
eligible for listener audio. A Web Lock excludes common duplicate tabs. Queue
|
|
|
|
|
|
commands retain their existing session and generation fences.
|
2026-12-04 08:58:47 -05:00
|
|
|
|
|
|
|
|
|
|
Every queue mutation verifies the exact dedicated target, standalone topology and
|
|
|
|
|
|
its own active queue. Signed snapshots retain ordered duplicates, index, repeat,
|
|
|
|
|
|
whole-second position and state, scoped to campaign/session/fence/generation for up
|
2026-12-05 13:37:05 -05:00
|
|
|
|
to 12 hours. An interrupted ambient snapshot can survive an excursion while its
|
|
|
|
|
|
scene's encounter remains live and the ambient reference still matches.
|
|
|
|
|
|
Ambiguous writes latch closed and stop automation; they are not retried.
|
2026-12-04 08:58:47 -05:00
|
|
|
|
MA Sendspin lacks native pause in 2.10.6, so pause retains a logical stopped-queue
|
|
|
|
|
|
snapshot and resume explicitly seeks its item. A paused restore rebuilds without
|
2026-12-05 09:40:14 -05:00
|
|
|
|
briefly playing. A finished static queue can be interrupted and rebuilt in an
|
|
|
|
|
|
idle state for replay. The Playback panel can set MA's dedicated queue repeat
|
|
|
|
|
|
mode. Logical pause state is memory-only.
|
|
|
|
|
|
|
2026-12-05 20:29:27 -05:00
|
|
|
|
The floating bar's campaign pause holds the serialized controller. The
|
|
|
|
|
|
dedicated MA queue pauses in place, and an active owned native fallback uses
|
|
|
|
|
|
its snapshot and stop operations. Play resumes the original position when the
|
|
|
|
|
|
cue still applies. A different current cue takes precedence, and the prior
|
|
|
|
|
|
cue's pre-pause snapshot remains available under normal restoration rules.
|
|
|
|
|
|
The hold belongs to the active GM runtime and ends if that session is disposed.
|
|
|
|
|
|
|
2026-12-05 09:40:14 -05:00
|
|
|
|
Reconnecting to a remembered receiver can preserve its existing queue. When the
|
|
|
|
|
|
trusted device auto-reconnects with a populated queue, the next music intent
|
|
|
|
|
|
or explicit return to scene music takes control. Crash or reload can lose the
|
|
|
|
|
|
ambient interruption stack and logical pause. Adaptive Music provides sequential
|
|
|
|
|
|
fade-out and fade-in using its one MA queue. True overlap between arbitrary
|
|
|
|
|
|
scene playlists would require two independently managed streams at once.
|
|
|
|
|
|
|
|
|
|
|
|
Scene Configuration and the Playlists sidebar use Foundry render hooks. The
|
|
|
|
|
|
director displays virtual catalog items for assignment and saves only opaque
|
2026-12-05 13:37:05 -05:00
|
|
|
|
references into scene flags. The GM's native Combat Tracker stores the encounter
|
|
|
|
|
|
designation on the Combat document and reflects the current playback mode.
|
|
|
|
|
|
No Foundry Playlist document is created for an MA
|
2026-12-05 09:40:14 -05:00
|
|
|
|
item. The module cedes a scene with a configured native soundtrack to Foundry.
|
|
|
|
|
|
Only explicitly owned native fallback playlists can be managed by Adaptive Music.
|
|
|
|
|
|
Positional audio and other native effects stay under Foundry’s control.
|
2026-12-04 08:58:47 -05:00
|
|
|
|
|
|
|
|
|
|
## Verification boundary
|
|
|
|
|
|
|
2026-12-04 11:08:09 -05:00
|
|
|
|
The installed v0.7.0 module was tested in a logged-in Foundry v14.371 development
|
2026-12-05 09:40:14 -05:00
|
|
|
|
world through the private Nginx route. The v0.8.0 browser preview used validated
|
|
|
|
|
|
ZIP assets with the real development world, MA and two listeners. It exercised
|
|
|
|
|
|
Foundry module-socket signaling, scene and combat hooks, ordered ambient
|
2026-12-05 13:37:05 -05:00
|
|
|
|
restoration, real playback controls and User document permissions. The operator
|
|
|
|
|
|
later verified installed v0.8.0 audio in Chrome on macOS and at a remote WAN
|
|
|
|
|
|
listener. macOS Firefox connectivity remains unresolved. See [TESTING.md](TESTING.md).
|