A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(examples): exercise sound event sources in audio demo
yhh6e59d603e9b7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a6054436b..38f3d60ef 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,10 @@ published separately; it ships inside the editor.## [Unreleased]+### Added++- **Audio demo exercises authored sound events.** Three weighted no-repeat footsteps, two sequential button variants and rate-limited collision bursts reuse the existing percussion clips. Source buttons expose seeded selection parameters and shared playback/rejection counts; normal exports retain all definitions and candidate dependencies, with an eight-voice project budget.+## [0.90.0] - 2026-10-15### Addeddiff --git a/examples/audio-demo/README.md b/examples/audio-demo/README.mdindex 72e8cff47..54bf315fd 100644--- a/examples/audio-demo/README.md+++ b/examples/audio-demo/README.md@@ -12,6 +12,10 @@ source orbiting the listener.| `1` `2` `3` `4` / click a pad | Kick / Snare / Hi-Hat / Clap || **Beat** button | Toggle the looping beat (music bus) || **Master / Music / SFX** | Click to cycle that bus's volume |+| `5` / **Footsteps** | Three weighted variants, no immediate repeat |+| `6` / **Button variants** | Alternate two variants in sequence |+| Hold `7` / **Collision burst** | Eight attempts per frame / sixteen per click |+| `0` | Stop the three event sources; restart their seeds on the next trigger || *(nothing)* | The orbiting dot pans and swells on its own |## What it shows@@ -32,6 +36,27 @@ source orbiting the listener.## How it works+The three `SoundEventSource` buttons reference ordinary `.esaudioevent` files.+They reuse the existing percussion WAVs as stand-ins for footsteps, button and+collision sounds; no additional recordings are needed. Open those definitions+in the editor's Sound Event panel to change weights, order and variation ranges.+Playback rate changes pitch **and duration**.++Footsteps use three weighted clips without immediate repeats; the button cycles+two clips; collisions have a two-instance cap and an 80 ms cooldown. Each source+has a fixed seed. `0` stops these sources, and the next trigger restarts their+selection streams. The project also limits the shared audio pool to eight voices,+including the original drums, beat and spatial hum. Event admission happens+before clip loading, followed by the existing global priority/voice budget.++The live readout uses `SoundEvents.getStats()` for actual played, rejected,+active and pending counts. Attempts are not assumed to be audible plays.+Holding `7` requests eight collision sounds per simulation frame (about 480/s+at 60 fps); the cooldown rejects most before clip I/O. This deliberately varies+with frame rate. The example keeps only counters and the latest result, not an+ever-growing history. Export through the normal project build command: all three+definitions and all their candidate clips follow the scene's UUID references.+The visualizer is fed by a new SDK method, `audio.getSpectrum(out)`, which fillsa `Uint8Array` with the master output's frequency magnitudes (0-255 per bin).Under the hood the WebAudio backend taps the master bus with an `AnalyserNode`@@ -53,6 +78,7 @@ assets/scenes/main.esscene # camera (+ AudioListener), pads, buttons, bars,# and the spatial hum sourceaudio/*.wav # kick / snare / hi-hat / clap, plus the looping hum+ audio/*.esaudioevent # footsteps / button / collision rules (existing clips)src/main.ts # registers the systemsconfig.ts # pad samples, volume steps, spectrum bins@@ -60,6 +86,7 @@ src/systems/preload.ts # warm the buffer cache at startupsfx.ts # pads → playSFX with pitch/pan variation+ events.ts # source triggers, collision stress and live admission countsbeat.ts # toggle the looping music-bus beatvolume.ts # cycle per-bus volume, update labelsvisualizer.ts # real spectrum → bar heights (audio.getSpectrum)diff --git a/examples/audio-demo/assets/audio/button.esaudioevent b/examples/audio-demo/assets/audio/button.esaudioeventnew file mode 100644index 000000000..669731638--- /dev/null+++ b/examples/audio-demo/assets/audio/button.esaudioevent@@ -0,0 +1,26 @@+{+ "version": 1,+ "clips": [+ {+ "clip": "@uuid:d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f80",+ "weight": 1+ },+ {+ "clip": "@uuid:c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f",+ "weight": 1+ }+ ],+ "mode": "sequence",+ "volume": [+ 0.25,+ 0.45+ ],+ "playbackRate": [+ 0.95,+ 1.05+ ],+ "bus": "ui",+ "priority": 10,+ "maxInstances": 2,+ "cooldown": 0.02+}diff --git a/examples/audio-demo/assets/audio/button.esaudioevent.meta b/examples/audio-demo/assets/audio/button.esaudioevent.metanew file mode 100644index 000000000..36aa6547c--- /dev/null+++ b/examples/audio-demo/assets/audio/button.esaudioevent.meta@@ -0,0 +1,6 @@+{+ "uuid": "49c8a413-9dbd-4905-aab0-33c50551e8fd",+ "version": "2.0",+ "type": "sound-event",+ "importer": {}+}diff --git a/examples/audio-demo/assets/audio/collision.esaudioevent b/examples/audio-demo/assets/audio/collision.esaudioeventnew file mode 100644index 000000000..3f2d2084f--- /dev/null+++ b/examples/audio-demo/assets/audio/collision.esaudioevent@@ -0,0 +1,30 @@+{+ "version": 1,+ "clips": [+ {+ "clip": "@uuid:a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",+ "weight": 1+ },+ {+ "clip": "@uuid:b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",+ "weight": 2+ },+ {+ "clip": "@uuid:d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f80",+ "weight": 1+ }+ ],+ "mode": "random",+ "volume": [+ 0.3,+ 0.65+ ],+ "playbackRate": [+ 0.8,+ 1.2+ ],+ "bus": "sfx",+ "priority": 1,+ "maxInstances": 2,+ "cooldown": 0.08+}diff --git a/examples/audio-demo/assets/audio/collision.esaudioevent.meta b/examples/audio-demo/assets/audio/collision.esaudioevent.metanew file mode 100644index 000000000..f94170aa5--- /dev/null+++ b/examples/audio-demo/assets/audio/collision.esaudioevent.meta@@ -0,0 +1,6 @@+{+ "uuid": "70a0391d-5ba5-4d30-a89d-b6a08b5d680e",+ "version": "2.0",+ "type": "sound-event",+ "importer": {}+}diff --git a/examples/audio-demo/assets/audio/footsteps.esaudioevent b/examples/audio-demo/assets/audio/footsteps.esaudioeventnew file mode 100644index 000000000..3ba39f866--- /dev/null+++ b/examples/audio-demo/assets/audio/footsteps.esaudioevent@@ -0,0 +1,30 @@+{+ "version": 1,+ "clips": [+ {+ "clip": "@uuid:a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",+ "weight": 3+ },+ {+ "clip": "@uuid:d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f80",+ "weight": 2+ },+ {+ "clip": "@uuid:c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f",+ "weight": 1+ }+ ],+ "mode": "no-repeat",+ "volume": [+ 0.45,+ 0.75+ ],+ "playbackRate": [+ 0.85,+ 1.15+ ],+ "bus": "sfx",+ "priority": 2,+ "maxInstances": 4,+ "cooldown": 0.06+}diff --git a/examples/audio-demo/assets/audio/footsteps.esaudioevent.meta b/examples/audio-demo/assets/audio/footsteps.esaudioevent.metanew file mode 100644index 000000000..4097fa822--- /dev/null+++ b/examples/audio-demo/assets/audio/footsteps.esaudioevent.meta@@ -0,0 +1,6 @@+{+ "uuid": "6c0866c1-5625-4d75-8b78-b4dc185a98d0",+ "version": "2.0",+ "type": "sound-event",+ "importer": {}+}diff --git a/examples/audio-demo/assets/scenes/main.esscene b/examples/audio-demo/assets/scenes/main.essceneindex ac7b69727..e4500debc 100644--- a/examples/audio-demo/assets/scenes/main.esscene+++ b/examples/audio-demo/assets/scenes/main.esscene@@ -12,7 +12,7 @@},{"id": 1, "name": "Canvas", "parent": null,- "children": [2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35],+ "children": [2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 39, 41, 43],"visible": true,"components": [{ "type": "Transform", "data": {} },@@ -330,8 +330,8 @@"id": 35, "name": "Hint", "parent": 1, "children": [], "visible": true,"components": [{ "type": "Transform", "data": {} },- { "type": "UINode", "data": { "position": 1, "width": { "value": 640, "unit": 0 }, "height": { "value": 22, "unit": 0 }, "insetLeft": { "value": 50, "unit": 1 }, "marginLeft": { "value": -320, "unit": 0 }, "insetTop": { "value": 100, "unit": 1 }, "marginTop": { "value": -34, "unit": 0 } } },- { "type": "Text", "data": { "content": "keys 1-4 or click the pads · Beat toggles the loop · click a bus to change its volume · the orbiting dot is a spatial source", "fontSize": 14, "color": { "r": 0.72, "g": 0.76, "b": 0.86, "a": 0.9 }, "align": 1, "verticalAlign": 1 } }+ { "type": "UINode", "data": { "position": 1, "width": { "value": 640, "unit": 0 }, "height": { "value": 34, "unit": 0 }, "insetLeft": { "value": 50, "unit": 1 }, "marginLeft": { "value": -320, "unit": 0 }, "insetTop": { "value": 100, "unit": 1 }, "marginTop": { "value": -42, "unit": 0 } } },+ { "type": "Text", "data": { "content": "1-4 drums | Beat: loop | buses: volume\n5 footsteps | 6 button | hold 7: collision stress | 0: stop event voices", "fontSize": 12, "color": { "r": 0.72, "g": 0.76, "b": 0.86, "a": 0.9 }, "align": 1, "verticalAlign": 1 } }]},{@@ -342,6 +342,72 @@{ "type": "AudioSource", "data": { "clip": "@uuid:b7c1d2e3-4f5a-4b6c-8d7e-9f0a1b2c3d4e", "bus": "sfx", "volume": 0.7, "loop": true, "playing": true, "playOnAwake": false, "spatial": true, "minDistance": 90, "maxDistance": 700 } },{ "type": "Orbiting", "data": { "radius": 320, "speed": 0.6 } }]+ },+ {+ "id": 37, "name": "footstepsEvent", "parent": 1, "children": [38], "visible": true,+ "components": [+ {"type":"Transform","data":{}},+ {"type":"UINode","data":{"position":1,"width":{"value":150,"unit":0},"height":{"value":46,"unit":0},"insetLeft":{"value":50,"unit":1},"marginLeft":{"value":-240,"unit":0},"insetTop":{"value":50,"unit":1},"marginTop":{"value":130,"unit":0}}},+ {"type":"UIVisual","data":{"visualType":1,"color":{"r":0.16,"g":0.31,"b":0.48,"a":1}}},+ {"type":"Interactable","data":{}},+ {"type":"EventPad","data":{"index":0}},+ {"type":"SoundEventSource","data":{"event":"@uuid:6c0866c1-5625-4d75-8b78-b4dc185a98d0","seed":19,"enabled":true,"playOnAwake":false}}+ ]+ },+ {+ "id": 38, "name": "footstepsLabel", "parent": 37, "children": [], "visible": true,+ "components": [+ {"type":"Transform","data":{}},+ {"type":"UINode","data":{"position":1,"insetLeft":{"value":0,"unit":1},"insetRight":{"value":0,"unit":1},"insetTop":{"value":0,"unit":1},"insetBottom":{"value":0,"unit":1}}},+ {"type":"Text","data":{"content":"Footsteps\n5","fontSize":16,"color":{"r":1,"g":1,"b":1,"a":1},"align":1,"verticalAlign":1}}+ ]+ },+ {+ "id": 39, "name": "buttonEvent", "parent": 1, "children": [40], "visible": true,+ "components": [+ {"type":"Transform","data":{}},+ {"type":"UINode","data":{"position":1,"width":{"value":150,"unit":0},"height":{"value":46,"unit":0},"insetLeft":{"value":50,"unit":1},"marginLeft":{"value":-75,"unit":0},"insetTop":{"value":50,"unit":1},"marginTop":{"value":130,"unit":0}}},+ {"type":"UIVisual","data":{"visualType":1,"color":{"r":0.21000000000000002,"g":0.31,"b":0.48,"a":1}}},+ {"type":"Interactable","data":{}},+ {"type":"EventPad","data":{"index":1}},+ {"type":"SoundEventSource","data":{"event":"@uuid:49c8a413-9dbd-4905-aab0-33c50551e8fd","seed":23,"enabled":true,"playOnAwake":false}}+ ]+ },+ {+ "id": 40, "name": "buttonLabel", "parent": 39, "children": [], "visible": true,+ "components": [+ {"type":"Transform","data":{}},+ {"type":"UINode","data":{"position":1,"insetLeft":{"value":0,"unit":1},"insetRight":{"value":0,"unit":1},"insetTop":{"value":0,"unit":1},"insetBottom":{"value":0,"unit":1}}},+ {"type":"Text","data":{"content":"Button variants\n6","fontSize":16,"color":{"r":1,"g":1,"b":1,"a":1},"align":1,"verticalAlign":1}}+ ]+ },+ {+ "id": 41, "name": "collisionEvent", "parent": 1, "children": [42], "visible": true,+ "components": [+ {"type":"Transform","data":{}},+ {"type":"UINode","data":{"position":1,"width":{"value":150,"unit":0},"height":{"value":46,"unit":0},"insetLeft":{"value":50,"unit":1},"marginLeft":{"value":90,"unit":0},"insetTop":{"value":50,"unit":1},"marginTop":{"value":130,"unit":0}}},+ {"type":"UIVisual","data":{"visualType":1,"color":{"r":0.26,"g":0.31,"b":0.48,"a":1}}},+ {"type":"Interactable","data":{}},+ {"type":"EventPad","data":{"index":2}},+ {"type":"SoundEventSource","data":{"event":"@uuid:70a0391d-5ba5-4d30-a89d-b6a08b5d680e","seed":31,"enabled":true,"playOnAwake":false}}+ ]+ },+ {+ "id": 42, "name": "collisionLabel", "parent": 41, "children": [], "visible": true,+ "components": [+ {"type":"Transform","data":{}},+ {"type":"UINode","data":{"position":1,"insetLeft":{"value":0,"unit":1},"insetRight":{"value":0,"unit":1},"insetTop":{"value":0,"unit":1},"insetBottom":{"value":0,"unit":1}}},+ {"type":"Text","data":{"content":"Collision burst\nhold 7 / click","fontSize":16,"color":{"r":1,"g":1,"b":1,"a":1},"align":1,"verticalAlign":1}}+ ]+ },+ {+ "id": 43, "name": "EventStatus", "parent": 1, "children": [], "visible": true,+ "components": [+ {"type":"Transform","data":{}},+ {"type":"UINode","data":{"position":1,"width":{"value":760,"unit":0},"height":{"value":54,"unit":0},"insetLeft":{"value":50,"unit":1},"marginLeft":{"value":-380,"unit":0},"insetTop":{"value":50,"unit":1},"marginTop":{"value":182,"unit":0}}},+ {"type":"Text","data":{"content":"Event sources ready","fontSize":13,"color":{"r":0.72,"g":0.76,"b":0.86,"a":0.9},"align":1,"verticalAlign":1}},+ {"type":"EventStatusLabel","data":{}}+ ]}]}diff --git a/examples/audio-demo/project.esproject b/examples/audio-demo/project.esprojectindex 5f01b557e..0d9a8617f 100644--- a/examples/audio-demo/project.esproject+++ b/examples/audio-demo/project.esproject@@ -9,5 +9,10 @@"width": 800,"height": 600},- "spineVersion": "none"+ "spineVersion": "none",+ "features": {+ "audio": {+ "maxVoices": 8+ }+ }}diff --git a/examples/audio-demo/src/components.ts b/examples/audio-demo/src/components.tsindex 1005a2ea3..5cea6d26d 100644--- a/examples/audio-demo/src/components.ts+++ b/examples/audio-demo/src/components.ts@@ -3,6 +3,9 @@ import { defineComponent, defineTag } from 'esengine';// A drum pad. `index` selects its sample; `cooldown` debounces retriggers.export const Pad = defineComponent('Pad', { index: 0, cooldown: 0 });+export const EventPad = defineComponent('EventPad', { index: 0 });+export const EventStatusLabel = defineTag('EventStatusLabel');+// The looping-beat toggle button, and its live On/Off label.export const BeatToggle = defineTag('BeatToggle');export const BeatLabel = defineTag('BeatLabel');diff --git a/examples/audio-demo/src/main.ts b/examples/audio-demo/src/main.tsindex eb8dd182a..77520c518 100644--- a/examples/audio-demo/src/main.ts+++ b/examples/audio-demo/src/main.ts@@ -10,10 +10,12 @@ import { beatSystem } from './systems/beat';import { orbitSystem } from './systems/orbit';import { volumeSystem, restoreVolumeSystem } from './systems/volume';import { visualizerSystem } from './systems/visualizer';+import { eventSystem } from './systems/events';addStartupSystem(preloadSystem);addStartupSystem(restoreVolumeSystem);addSystemToSchedule(Schedule.Update, sfxSystem);+addSystemToSchedule(Schedule.Update, eventSystem);addSystemToSchedule(Schedule.Update, beatSystem);addSystemToSchedule(Schedule.Update, orbitSystem);addSystemToSchedule(Schedule.Update, volumeSystem);diff --git a/examples/audio-demo/src/systems/events.ts b/examples/audio-demo/src/systems/events.tsnew file mode 100644index 000000000..b2a926809--- /dev/null+++ b/examples/audio-demo/src/systems/events.ts@@ -0,0 +1,70 @@+import {+ defineResource, defineSystem, Query, Mut, Res, ResMut, GetWorld,+ Input, UIEvents, Text, SoundEvents, SoundEventSource,+ triggerSoundEventSource, stopSoundEventSource,+} from 'esengine';+import { EventPad, EventStatusLabel } from '../components';++// Per-App counters, with no retained trigger history or second voice pool.+const EventReadout = defineResource({+ revision: 0, epoch: 0, selectionRevision: 0, attempts: 0, cancelled: 0,+ selection: 'No event selected', last: 'Ready',+}, 'AudioEventDemo');+const NAMES = ['Footsteps', 'Button', 'Collision'];++export const eventSystem = defineSystem(+ [Query(EventPad, SoundEventSource), Query(Mut(Text), EventStatusLabel),+ Res(Input), Res(UIEvents), Res(SoundEvents), ResMut(EventReadout), GetWorld()],+ (pads, labels, input, ui, playback, readout, world) => {+ const clicks = ui.query('click');+ const stopping = input.isKeyPressed('Digit0');+ for (const [entity, pad] of pads) {+ if (stopping) {+ stopSoundEventSource(world, entity);+ continue;+ }+ const clicked = clicks.some((event) => event.target === entity);+ const count = pad.index === 2+ ? (input.isKeyDown('Digit7') ? 8 : clicked ? 16 : 0)+ : (input.isKeyPressed(`Digit${pad.index + 5}`) || clicked ? 1 : 0);+ for (let i = 0; i < count; i++) {+ readout.modify((state) => { state.attempts++; state.revision++; });+ const serial = readout.get().revision;+ const epoch = readout.get().epoch;+ void triggerSoundEventSource(world, entity).then(async (handle) => {+ if (!handle) {+ readout.modify((state) => { state.cancelled++; });+ return;+ }+ await handle.ready;+ if (readout.get().epoch !== epoch) return;+ const selection = handle.selection;+ readout.modify((state) => {+ // Keep the latest selected parameters visible even if+ // the following attempts are rejected before selection.+ if (selection && serial > state.selectionRevision) {+ state.selectionRevision = serial;+ state.selection = `${NAMES[pad.index]} slot ${selection.slot + 1} | volume ${selection.volume.toFixed(2)} | rate ${selection.playbackRate.toFixed(2)}`;+ }+ if (state.revision === serial) state.last = handle.reason ?? handle.status;+ });+ }).catch((error: unknown) => {+ if (readout.get().revision === serial) {+ readout.modify((state) => { state.last = String(error); });+ }+ });+ }+ }+ if (stopping) {+ // Invalidate any pending readout as well as the owned event voices.+ readout.modify((state) => { state.epoch++; state.revision++; state.last = 'Stopped'; });+ }+ const stats = playback.getStats();+ const state = readout.get();+ const content = `${state.selection} | ${state.last}\nAttempts ${state.attempts} | played ${stats.played} | rejected ${stats.rejected} | active ${stats.active} | pending ${stats.pendingClips} | cancelled ${state.cancelled}`;+ for (const [, text] of labels) {+ if (text.content !== content) text.content = content;+ }+ },+ { name: 'AudioEventSystem', touches: { reads: [EventPad._name, SoundEventSource._name] } },+);diff --git a/tools/check-corpus-authoring.mjs b/tools/check-corpus-authoring.mjsindex ea57ce3ea..0a2bff059 100644--- a/tools/check-corpus-authoring.mjs+++ b/tools/check-corpus-authoring.mjs@@ -64,6 +64,7 @@ const NOT_INSTANCE_FORMATS = {'.esanimator': 'an animator graph: states and transitions over clips','.estimeline': 'a timeline: tracks over time, addressed to entities the scene owns','.esanim': 'a clip: curves over time',+ '.esaudioevent': 'an audio event definition; source instances belong to scenes','.esavatar': 'how one rig spells the joints another rig\'s clips name','.esmaterial': 'a material: shader + uniform values','.esshader': 'shader source',@@ -122,7 +123,6 @@ const DISPOSITION = {// — owed: a creator-facing component nothing in the shipped corpus authors.// Each reason names where the coverage belongs. —- SoundEventSource: ['owed', 'RM-066: author footsteps, button variants and rate-limited collisions in an audio-demo scene, then verify the exported build; component/graph and cook fixtures do not replace the complete example'],};const snapshot = JSON.parse(readFileSync(SNAPSHOT, 'utf8'));diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 11fd3119d..d745adfb0 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,12 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(editor): integrate Play realm network permissions for issue #97':+ { note: 'Editor Play can connect to game servers.' },+ 'fix(editor): allow game networking in the Play realm':+ { note: 'Editor Play can connect to game servers.' },+ 'feat(examples): exercise sound event sources in audio demo':+ { note: 'Audio demo exercises authored sound events.' },'perf(editor): reuse bounded audio waveform peaks':{ note: 'Sound events have a dedicated authoring panel.' },'feat(editor): author and preview sound event variants':