Epsilon Engine Source code

Audio and exports

Use EpsilonAudio to turn scene-relative cues into a production score. The mixer works in Node or the browser. Preview playback and WebM encoding use browser audio and canvas APIs.

Mix a score#

A cue has an id, oscillator wave, start t and length in authored seconds, frequency in Hz and a linear gain. The waves are sine, triangle, square and sawtooth. The mixer scales cue times with scene speed, trims them at the scene boundary and preserves pitch.

import './src/audio-core.js';

const audio = globalThis.EpsilonAudio;
const sequence = { scenes: [{
  duration: 4, speed: 2, audio: [{
    id: 'dock-chime', wave: 'sine', t: 1, length: 0.5, frequency: 440, gain: 0.3
  }]
}] };
const plan = audio.plan(sequence);
const score = audio.mix(sequence);
const file = audio.wav(score);
console.log(plan.events[0].first, plan.events[0].last, score.rate, file.byteLength);
12000 18000 24000 96044
Call Result or effect
EpsilonAudio.cue(raw), clean(cues) Normalize one cue or an array. Each scene accepts up to 32 unique cue IDs. Length is 0.02–10 s, frequency 40–2000 Hz, gain 0–1.
EpsilonAudio.plan(project) Returns {frames, events} with inclusive first and exclusive last sample indices. Silent or out-of-scene cues are omitted. The production limit is 180 s.
EpsilonAudio.mix(project), wav(result) Return {pcm, rate, peak, scale} with mono Float32Array samples at 24 kHz, then a Uint8Array containing 16-bit PCM WAV. Peaks over one are scaled down.
new EpsilonScoreClock(context, result) Uses the caller's Web Audio context for play(), pause(), position() and finished. Resume the context in a user gesture before playing. dispose() disconnects the source.

Capture a film#

EpsilonFilmCapture.mime(MediaRecorder) selects a supported WebM type or returns null. validate(result) checks PCM range, sample rate and duration. capture({canvas, context, result, draw, signal, progress, authorize, check}) returns a promise for a WebM Blob. Supply a dedicated AudioContext. Capture closes it during cleanup, including after cancellation or failure.

The encoder calls await authorize() before recording. draw(seconds) paints the current production frame, driven by the audio clock. Optional progress(fraction) reports completion and check() can reject a changed run. An AbortSignal cancels the recording. The target is 30 fps with one canvas video track and one mixed audio track, bounded to 96 MiB and 180 s. Recording takes playback time.

For projects with actors, use authorizeProject(project, read, verify) to resolve every referenced image and check its local project grant and verified bytes. The Studio export UI checks again before it delivers the file. A private or missing image blocks that export.

Portable projects#

Use EpsilonPackages from src/package-core.js when a project must travel with its authorized actor images. Its epsilon-prime.studio/package@1 envelope contains canonical project JSON and digest-indexed image bytes. The file cap is 48 MiB, with up to 32 MiB of decoded assets and 8 MiB per image.

Call Contract
references(doc) Returns unique sorted actor image digests across scenes.
await create(doc, codec, {read, verify}) Returns {blob, project}. The latter is the exact serialized project string. read(sha) reads the current asset row. verify(blob, descriptor) checks the bytes. Studio uses MeldCasting.get and MeldCasting.verify.
await reauthorize(project, codec, deps) Re-reads permissions and asset integrity just before delivery. Pass the string returned by create.
await parse(blob, codec, verify) Checks canonical JSON, required references, descriptors and bytes. Returns {doc, project, rows} without writing browser storage.
await prepareImport(blob, codec, {read, verify, consent}) Requires explicit consent: true and checks for incompatible locally stored bytes or permissions. Returns a prepared import for the storage API.
storage(MeldCasting.DB, indexedDB?) await commit(prepared) writes new assets and the recovery record in one transaction and returns its key. list() lists recovery entries. read(key, codec) opens the recovered document.

MeldCasting.verify(blob, descriptor?) checks PNG, JPEG or WebP bytes, dimensions and digest. get(sha) reads a row, list() enumerates stored assets and forget(sha) removes bytes while preserving local restriction evidence. connect(origin, options?) opens the MELD portrait picker and returns {promise, cancel}. The browser checks the popup, origin, transfer state and image before acknowledging a committed transfer. The public Arcade build disables the live picker. Project packages use authorized local images.

Standalone HTML#

EpsilonSpatialExport.payload(scene) validates a playable spatial scene and projects its primitive geometry, collider roles, controller settings and palette into a versioned payload. build(scene, engineText) returns an HTML string. Pass the text of the built editor's #engine-script element so runtimeFrom(engineText) can extract the delimited spatial runtime. The payload remaps object IDs and emits static geometry. Private models and casting records stay in local rehearsal.

For a standalone 2D campaign, build the public player with python3 release/build_public_arcade.py arcade.html, then run python3 release/build_rift_playtest.py rift-station.html --source arcade.html. The second file opens without a web server. Build paths and ownership.