跳转到内容

AudioAPI

此内容尚不支持你的语言。

Defined in: audio/Audio.ts:87

new AudioAPI(backend, mixer?): AudioAPI

Defined in: audio/Audio.ts:129

PlatformAudioBackend

AudioMixer | null

AudioAPI

baseUrl: string = ''

Defined in: audio/Audio.ts:127

get bufferBudget(): number

Defined in: audio/Audio.ts:142

The effective warm-cache byte budget: an explicit override, else the live RuntimeConfig.audioCacheBudget (so build-config changes apply without plumbing). 0 disables the warm cache — a buffer is freed the moment its refCount reaches 0.

number


get maxVoices(): number

Defined in: audio/Audio.ts:581

number

dispose(): void

Defined in: audio/Audio.ts:701

void


ensureBus(name, parent?): boolean

Defined in: audio/Audio.ts:643

Ensure a named bus exists (creating it under parent ?? master). False on backends without a mixer graph.

string

string

boolean


getBufferHandle(url): AudioBufferHandle | undefined

Defined in: audio/Audio.ts:690

string

AudioBufferHandle | undefined


getBufferStats(): AudioBufferStats

Defined in: audio/Audio.ts:216

Buffer residency counters — the observability side of the budget.

AudioBufferStats


getBusDucking(target): BusDuckRule | null

Defined in: audio/Audio.ts:681

string

BusDuckRule | null


getBusEffects(busName): BusEffectDef[]

Defined in: audio/Audio.ts:671

string

BusEffectDef[]


getBusVolume(busName): number

Defined in: audio/Audio.ts:515

Unity (1) for an unknown bus.

string

number


getMasterVolume(): number

Defined in: audio/Audio.ts:498

Mixerless backends (WeChat/Null) report unity volume and unmuted — the read-side mirror of the volume setters’ silent no-op there.

number


getMusicVolume(): number

Defined in: audio/Audio.ts:502

number


getSFXVolume(): number

Defined in: audio/Audio.ts:506

number


getSpectrum(out): boolean

Defined in: audio/Audio.ts:697

Fill out with the master output’s frequency spectrum (0-255 per bin, low→high) for visualizers. Returns false on backends without analysis (e.g. WeChat) — callers should treat that as silence.

Uint8Array

boolean


getUIVolume(): number

Defined in: audio/Audio.ts:510

number


hasMixerGraph(): boolean

Defined in: audio/Audio.ts:637

Whether this backend has a mixer graph at all.

The fact behind every false the bus calls below return, reported once so a reader does not have to infer a capability from a failed write. Without one, applyAudioProjectConfig applies maxVoices and stops before the bus list — so an authored mixer is not partly applied, it is not applied.

boolean


invalidateBuffer(url): boolean

Defined in: audio/Audio.ts:191

Drop a buffer whose source bytes changed (hot reload) so no future play or load serves stale audio. Safe while sounds are playing — live sources keep their own reference to the decoded data; only the cache entry goes, and the next play/load re-fetches fresh bytes. Returns true if the url was cached.

string

boolean


isBusMuted(busName): boolean

Defined in: audio/Audio.ts:520

string

boolean


muteBus(busName, muted): void

Defined in: audio/Audio.ts:618

string

boolean

void


playBGM(url, config?): void

Defined in: audio/Audio.ts:382

string

number

number

number

void


playBuffer(buffer, config?): AudioHandle

Defined in: audio/Audio.ts:571

Play an already-resolved buffer. The one door every voice comes through — a scripted playSFX, a playBGM, an AudioSource in the scene — so the bus gain a backend without a mixer graph cannot apply, and the voice cap priority is measured against, are decided once for all of them.

AudioBufferHandle

PlayConfig

AudioHandle


playSFX(url, config?): AudioHandle

Defined in: audio/Audio.ts:352

string

number

number

number

number

AudioHandle


playTrack(url, config?): Promise<AudioHandle | null>

Defined in: audio/Audio.ts:338

Play a fully-RESOLVED clip URL on an explicit bus (created on demand under master). Unlike playSFX/playBGM this applies no ref resolution — the caller already holds the final URL (the video system’s audio track derives it from the resolved video source). Null when the clip can’t load; loaded buffers share the residency cache.

string

PlayConfig = {}

Promise<AudioHandle | null>


preload(url): Promise<void>

Defined in: audio/Audio.ts:312

string

Promise<void>


preloadAll(urls): Promise<void>

Defined in: audio/Audio.ts:323

string[]

Promise<void>


preloadFromData(url, data): Promise<void>

Defined in: audio/Audio.ts:327

string

ArrayBuffer

Promise<void>


releaseBuffer(url): void

Defined in: audio/Audio.ts:171

Unpin a buffer. At refCount 0 it becomes an evictable warm-cache entry (bounded by bufferBudget) — still instantly playable and revivable by retainBuffer — or is freed outright when the budget is 0.

string

void


resume(): void

Defined in: audio/Audio.ts:460

Resume the audio device after suspend.

void


retainBuffer(url): boolean

Defined in: audio/Audio.ts:157

Pin a cached buffer: refCount + 1 (reviving an evictable entry back to held). Returns false on a miss — the caller must load and re-acquire. Every retain needs a matching releaseBuffer.

string

boolean


setAssetResolver(resolver): void

Defined in: audio/Audio.ts:268

(url) => ArrayBuffer | null

void


setBufferBudget(bytes): void

Defined in: audio/Audio.ts:147

Override the warm-cache byte budget; null returns to RuntimeConfig.

number | null

void


setBusDucking(target, rule): boolean

Defined in: audio/Audio.ts:677

Install (or clear with null) sidechain ducking on target — e.g. duck ‘music’ to 30% while ‘voice’ carries signal.

string

BusDuckRule | null

boolean


setBusEffects(busName, effects): boolean

Defined in: audio/Audio.ts:664

Replace a bus’s DSP insert chain. No-op (false) on backends without a WebAudio graph (WeChat/Null) — same degradation as the volume APIs.

string

BusEffectDef[]

boolean


setBusVolume(busName, volume): void

Defined in: audio/Audio.ts:651

string

number

void


setMasterVolume(volume): void

Defined in: audio/Audio.ts:464

number

void


setMaxVoices(max): void

Defined in: audio/Audio.ts:577

The voice ceiling; 0 or less means no cap.

number

void

playBuffer


setMusicVolume(volume): void

Defined in: audio/Audio.ts:472

number

void


setRefResolver(resolver): void

Defined in: audio/Audio.ts:279

Route play refs through the realm’s single asset resolver — the same channel every other asset type resolves through (uuid manifest, cooked logical→staged maps, project base). Takes precedence over the legacy baseUrl prefix, so playSFX('assets/…') works in cooked builds whose content-addressed staging renamed the physical files.

((ref) => string) | null

void


setSFXVolume(volume): void

Defined in: audio/Audio.ts:480

number

void


setUIVolume(volume): void

Defined in: audio/Audio.ts:488

number

void


stopAll(): void

Defined in: audio/Audio.ts:428

void


stopBGM(fadeOut?): void

Defined in: audio/Audio.ts:436

number

void


suspend(): void

Defined in: audio/Audio.ts:455

Suspend the whole audio device (every voice, every bus) without touching any volume the user set — the device-level pause a fullscreen takeover (a rewarded ad, an OS interruption) wants, where per-bus volumes would fight the mixer’s own state. Balanced by resume.

void


trimBufferCache(): number

Defined in: audio/Audio.ts:203

Free every evictable warm-cache buffer now (memory pressure). Held buffers and the budget are untouched; the cache refills as buffers are released afterwards. Returns the number of buffers freed.

number


updateDucking(): void

Defined in: audio/Audio.ts:686

Advance duck envelopes (driven per-frame by AudioUpdateSystem).

void


updateFades(dt): void

Defined in: audio/Audio.ts:722

Advance every fade by dt seconds — called once a frame by the audio system, which is what makes a fade the game’s clock rather than the browser’s: it pauses when the game does, and it exists on a device.

number

void