Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
Club audio improvements, audio licenses, and test updates
nirholas717078998bd6
diff --git a/public/club/audio/LICENSES.md b/public/club/audio/LICENSES.mdindex 3b2be8d69..5f7f3cfa1 100644--- a/public/club/audio/LICENSES.md+++ b/public/club/audio/LICENSES.md@@ -13,8 +13,9 @@ under **Creative Commons CC0 1.0 Universal**(https://creativecommons.org/publicdomain/zero/1.0/). You can use themfor any purpose, with or without attribution.-The one exception is `entrance.mp3` (the walk-in anthem) — a supplied-third-party track that is **not** CC0. See its row in the table below.+The exceptions are the supplied third-party tracks that are **not** CC0:+the walk-in anthem `entrance.mp3` and the two full-length music-bed tracks+`club.mp3` + `im-in-love-wit-a-stripper-fast.mp3`. See their rows below.| File | Source | License | Length | Notes || -------------------- | ------------------------------------------------------------- | ------- | --------------------- | --------------------------------------------------------------------- |@@ -26,6 +27,8 @@ third-party track that is **not** CC0. See its row in the table below.| `silly.{ogg,mp3}` | Authored — 130 BPM major-key bounce + woodblock + cartoon arp | CC0 1.0 | ~7.4 s loop (4 bars) | Playful bed for the Silly clip. || `pole.{ogg,mp3}` | Authored — 105 BPM neutral groove + sine pad | CC0 1.0 | ~9.1 s loop (4 bars) | Generic backing track for pole choreography clips (spin/climb/combo). || `entrance.mp3` | Supplied third-party track | © original artist — **not** CC0 | full track, one-shot | Walk-in anthem played once on `club:admitted` via `ClubAudio.playEntrance()`. Not synthesised — confirm the artist's license before any redistribution beyond three.ws. |+| `club.mp3` | Supplied third-party track | © original artist — **not** CC0 | full track, looped | First track of the music bed (`ClubAudio.startMusic()`). Streamed via `createMediaElementSource`, never decoded to a buffer. Confirm the artist's license before any redistribution beyond three.ws. |+| `im-in-love-wit-a-stripper-fast.mp3` | Supplied third-party track | © original artist — **not** CC0 | full track, looped | Second track of the music bed, played after `club.mp3` then loops back. Streamed, not decoded. Confirm the artist's license before any redistribution beyond three.ws. |## Mastering notesdiff --git a/src/club-audio.js b/src/club-audio.jsindex 6884c5dde..4b4f12fb0 100644--- a/src/club-audio.js+++ b/src/club-audio.js@@ -240,7 +240,7 @@ export class ClubAudio {gain.gain.value = this.style || this.entrance ? MUSIC_DUCK_GAIN : MUSIC_GAIN;source.connect(gain).connect(this.effectsBus);- this.music = { el, source, gain, index: 0, source_errStreak: 0 };+ this.music = { el, source, gain, index: 0, errStreak: 0 };const srcFor = (i) => `${AUDIO_BASE}/${MUSIC_SEQUENCE[i]}.mp3`;const advance = (delta) => {@@ -255,12 +255,12 @@ export class ClubAudio {// next track. If every track in the sequence fails in a row we stop// advancing so one outage can't spin a hot reload loop.el.addEventListener('playing', () => {- this.music.source_errStreak = 0;+ this.music.errStreak = 0;});el.addEventListener('ended', () => advance(1));el.addEventListener('error', () => {- this.music.source_errStreak += 1;- if (this.music.source_errStreak > MUSIC_SEQUENCE.length) return;+ this.music.errStreak += 1;+ if (this.music.errStreak > MUSIC_SEQUENCE.length) return;advance(1);});diff --git a/src/club.js b/src/club.jsindex 5d173f803..05bde2e6c 100644--- a/src/club.js+++ b/src/club.js@@ -1292,11 +1292,10 @@ window.addEventListener('club:performance-end', () => {{const doorPay = document.getElementById('club-door-pay');doorPay?.addEventListener('click', () => {- // Prime the context and start ambience immediately so the user hears the- // club music muffled through the door (outdoor effect is the default state).- audio.ensureContext()- .then(() => audio.startAmbience())- .catch(() => {});+ // The cover click is a user gesture — start the music bed now so the+ // soundtrack is already playing (muffled through the door, since outdoor+ // is the default effects state) before the rope drops.+ audio.startMusic().catch(() => {});}, { once: true });const armOnGesture = () => {@@ -1313,6 +1312,19 @@ window.addEventListener('club:performance-end', () => {}, { once: true });}+// ── Club music bed ──────────────────────────────────────────────────────────+// The two-track soundtrack — club anthem → the stripper cut → loop — is the+// room's music, and it should start the moment the visitor lands. Browser+// autoplay policy blocks sound until a gesture, so we latch onto the first+// interaction anywhere on the page: walking up the alley, the cover-charge+// click, or a tip. startMusic() is idempotent (and the door + tip flows call+// it too), so whichever gesture lands first starts the bed and the rest no-op.+{+ const start = () => audio.startMusic().catch((err) => log.warn('[club] music', err));+ window.addEventListener('pointerdown', start, { once: true });+ window.addEventListener('keydown', start, { once: true });+}+// ── Tip flow (x402 drop-in) ──────────────────────────────────────────────async function tipDancer({ dancer, dance, button }) {if (!window.X402?.pay) {@@ -1346,7 +1358,7 @@ async function tipDancer({ dancer, dance, button }) {// non-fatal — the rest of the tip flow still works without audio.try {await audio.ensureContext();- audio.startAmbience().catch((err) => log.warn('[club] startAmbience', err));+ audio.startMusic().catch((err) => log.warn('[club] startMusic', err));} catch (err) {log.warn('[club] audio unavailable', err);}diff --git a/tests/club-audio.test.js b/tests/club-audio.test.jsindex d828a0712..e2ab0340c 100644--- a/tests/club-audio.test.js+++ b/tests/club-audio.test.js@@ -37,6 +37,11 @@ class FakeAudioParam {this.events.push({ type: 'linearRamp', value, time });return this;}+ setTargetAtTime(value, time) {+ this.value = value;+ this.events.push({ type: 'target', value, time });+ return this;+ }cancelScheduledValues(time) {this.events.push({ type: 'cancel', time });return this;@@ -104,14 +109,96 @@ class FakeBufferSource {}}+class FakeBiquadFilterNode {+ constructor() {+ this.type = '';+ this.frequency = new FakeAudioParam(0);+ this.Q = new FakeAudioParam(0);+ this.gain = new FakeAudioParam(0);+ this._connections = [];+ }+ connect(dest) {+ this._connections.push(dest);+ return dest;+ }+ disconnect() {+ this._connections = [];+ }+}++class FakeConvolverNode {+ constructor() {+ this.buffer = null;+ this._connections = [];+ }+ connect(dest) {+ this._connections.push(dest);+ return dest;+ }+ disconnect() {+ this._connections = [];+ }+}++class FakeMediaElementSource {+ constructor(el) {+ this.mediaElement = el;+ this._connections = [];+ }+ connect(dest) {+ this._connections.push(dest);+ return dest;+ }+ disconnect() {+ this._connections = [];+ }+}++// First play() can be told to reject (browser autoplay policy) so we can+// exercise the gesture-retry path. `audioPlayBehavior` is reset per test.+let audioPlayBehavior = 'resolve';++class FakeAudioElement {+ constructor() {+ this.src = '';+ this.preload = '';+ this.loop = false;+ this.paused = true;+ this.playCount = 0;+ this._listeners = new Map();+ }+ addEventListener(type, cb) {+ if (!this._listeners.has(type)) this._listeners.set(type, []);+ this._listeners.get(type).push(cb);+ }+ async play() {+ this.playCount += 1;+ if (audioPlayBehavior === 'reject-first' && this.playCount === 1) {+ throw new Error('NotAllowedError: autoplay blocked');+ }+ this.paused = false;+ this._emit('playing');+ }+ pause() {+ this.paused = true;+ }+ _emit(type) {+ for (const cb of this._listeners.get(type) || []) cb();+ }+}+class FakeAudioContext {constructor() {this.currentTime = 0;+ this.sampleRate = 44100;this.destination = { _label: 'destination' };this.state = 'running';this.createdGains = [];this.createdSources = [];this.createdAnalysers = [];+ this.createdMediaSources = [];+ this.createdFilters = [];+ this.createdConvolvers = [];this.decodedBuffers = [];}createGain() {@@ -119,6 +206,30 @@ class FakeAudioContext {this.createdGains.push(g);return g;}+ createMediaElementSource(el) {+ const s = new FakeMediaElementSource(el);+ this.createdMediaSources.push(s);+ return s;+ }+ createBiquadFilter() {+ const f = new FakeBiquadFilterNode();+ this.createdFilters.push(f);+ return f;+ }+ createConvolver() {+ const c = new FakeConvolverNode();+ this.createdConvolvers.push(c);+ return c;+ }+ createBuffer(channels, length, rate) {+ const data = Array.from({ length: channels }, () => new Float32Array(length));+ return {+ numberOfChannels: channels,+ length,+ sampleRate: rate,+ getChannelData: (c) => data[c],+ };+ }createAnalyser() {const a = new FakeAnalyserNode();this.createdAnalysers.push(a);@@ -150,7 +261,9 @@ beforeEach(() => {originalFetch = globalThis.fetch;originalLocalStorage = globalThis.localStorage;- const fakeWindow = { AudioContext: FakeAudioContext };+ audioPlayBehavior = 'resolve';++ const fakeWindow = { AudioContext: FakeAudioContext, Audio: FakeAudioElement };globalThis.window = fakeWindow;// In-memory localStorage so setMuted persistence doesn't touch disk.@@ -228,6 +341,86 @@ describe('ClubAudio.startAmbience', () => {});});+describe('ClubAudio.startMusic', () => {+ it('streams the first track (club) through a media-element source at the music gain', async () => {+ const audio = new ClubAudio();+ const music = await audio.startMusic();++ expect(music).toBeTruthy();+ expect(audio.music).toBe(music);+ // One <audio> element wired through exactly one MediaElementSource.+ expect(audio.ctx.createdMediaSources).toHaveLength(1);+ expect(audio.ctx.createdMediaSources[0].mediaElement).toBe(music.el);+ // First track is club.mp3, playing, at the full bed gain.+ expect(music.el.src.endsWith('/club/audio/club.mp3')).toBe(true);+ expect(music.el.paused).toBe(false);+ expect(music.gain.gain.value).toBeCloseTo(0.85, 3);+ // Full tracks stream — they must never be decoded into a buffer.+ expect(audio.ctx.decodedBuffers).toHaveLength(0);+ });++ it('loops the sequence club → stripper → club on each `ended`', async () => {+ const audio = new ClubAudio();+ await audio.startMusic();+ const el = audio.music.el;++ expect(el.src.endsWith('/club/audio/club.mp3')).toBe(true);++ el._emit('ended');+ expect(el.src.endsWith('/club/audio/im-in-love-wit-a-stripper-fast.mp3')).toBe(true);+ expect(audio.music.index).toBe(1);++ el._emit('ended');+ expect(el.src.endsWith('/club/audio/club.mp3')).toBe(true);+ expect(audio.music.index).toBe(0);+ });++ it('retries on the same element after an autoplay rejection (no second graph)', async () => {+ audioPlayBehavior = 'reject-first';+ const audio = new ClubAudio();++ await expect(audio.startMusic()).rejects.toThrow();+ // The graph is wired even though the first play() was blocked.+ expect(audio.music).toBeTruthy();+ const firstEl = audio.music.el;++ // Second call (a user gesture) resumes the same element, not a new graph.+ await audio.startMusic();+ expect(audio.music.el).toBe(firstEl);+ expect(audio.music.el.paused).toBe(false);+ expect(audio.ctx.createdMediaSources).toHaveLength(1);+ });++ it('a tipped style loop ducks the music bed and fadeOutStyle restores it', async () => {+ const audio = new ClubAudio();+ await audio.startMusic();++ audio.ctx.currentTime = 4;+ await audio.fadeToStyle('rumba', 800);+ const duckRamp = audio.music.gain.gain._lastRamp();+ expect(duckRamp.value).toBeCloseTo(0.18, 3);+ expect(duckRamp.time).toBeCloseTo(4.8, 3);++ audio.ctx.currentTime = 10;+ await audio.fadeOutStyle(800);+ const restoreRamp = audio.music.gain.gain._lastRamp();+ expect(restoreRamp.value).toBeCloseTo(0.85, 3);+ expect(restoreRamp.time).toBeCloseTo(10.8, 3);+ });++ it('mute pauses the streaming element and unmute resumes it', async () => {+ const audio = new ClubAudio();+ await audio.startMusic();+ expect(audio.music.el.paused).toBe(false);++ audio.setMuted(true);+ expect(audio.music.el.paused).toBe(true);++ audio.setMuted(false);+ expect(audio.music.el.paused).toBe(false);+ });+});+describe('ClubAudio.fadeToStyle', () => {it('crossfades ambience down to 0.1 and style up to 0.75', async () => {const audio = new ClubAudio();