跳转到内容

AudioAPI

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

Defined in: audio/Audio.ts:124

new AudioAPI(backend, mixer?): AudioAPI

Defined in: audio/Audio.ts:175

PlatformAudioBackend

AudioMixer | null = null

AudioAPI

baseUrl: string = ''

Defined in: audio/Audio.ts:173

get bufferBudget(): number

Defined in: audio/Audio.ts:196

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 delivery(): AudioDelivery

Defined in: audio/Audio.ts:184

What this platform’s backend needs in order to play a clip — asked by the asset loader, so a url backend is not made to wait on a fetch whose bytes it then drops. See AudioDelivery.

AudioDelivery


get maxVoices(): number

Defined in: audio/Audio.ts:770

number

dispose(): void

Defined in: audio/Audio.ts:923

void


ensureBus(name, parent?): boolean

Defined in: audio/Audio.ts:865

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:912

string

AudioBufferHandle | undefined


getBufferStats(): AudioBufferStats

Defined in: audio/Audio.ts:289

Buffer residency counters — the observability side of the budget.

AudioBufferStats


getBusDucking(target): BusDuckRule | null

Defined in: audio/Audio.ts:903

string

BusDuckRule | null


getBusEffects(busName): BusEffectDef[]

Defined in: audio/Audio.ts:893

string

BusEffectDef[]


getBusVolume(busName): number

Defined in: audio/Audio.ts:704

Unity (1) for an unknown bus.

string

number


getMasterVolume(): number

Defined in: audio/Audio.ts:687

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:691

number


getSFXVolume(): number

Defined in: audio/Audio.ts:695

number


getSpectrum(out): boolean

Defined in: audio/Audio.ts:919

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:699

number


hasMixerGraph(): boolean

Defined in: audio/Audio.ts:859

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:240

End cached and pending loads for changed source bytes. Playing sources keep their decoded data; later loads fetch fresh. Returns whether a load ended.

string

boolean


isBusMuted(busName): boolean

Defined in: audio/Audio.ts:709

string

boolean


muteBus(busName, muted): void

Defined in: audio/Audio.ts:840

string

boolean

void


playBGM(url, config?): void

Defined in: audio/Audio.ts:523

string

number

number

number

void


playBuffer(buffer, config?): AudioHandle

Defined in: audio/Audio.ts:760

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:492

string

number

number

number

number

AudioHandle


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

Defined in: audio/Audio.ts:477

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:442

string

Promise<void>


preloadAll(urls): Promise<void>

Defined in: audio/Audio.ts:454

string[]

Promise<void>


preloadFromData(url, data): Promise<void>

Defined in: audio/Audio.ts:464

Cache url’s clip from bytes the caller already holds. url is the AUTHORED path this API is addressed by (the key retainBuffer and getBufferHandle take); the backend is handed the RESOLVED source, which for a url-delivery backend is the only thing it plays.

string

ArrayBuffer

Promise<void>


releaseBuffer(url): void

Defined in: audio/Audio.ts:225

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:639

Resume the audio device after suspend.

void


retainBuffer(url): boolean

Defined in: audio/Audio.ts:211

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:370

(url) => ArrayBuffer | null

void


setBufferBudget(bytes): void

Defined in: audio/Audio.ts:201

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

number | null

void


setBusDucking(target, rule): boolean

Defined in: audio/Audio.ts:899

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:886

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:873

string

number

void


setLoadTypes(types): void

Defined in: audio/Audio.ts:279

How each clip the importer was told about is held. Keyed by the clip’s project-relative path, the way the asset loader and play address it; anything absent is auto. A clip already loaded keeps how it was loaded until it is reloaded.

Readonly<Record<string, AudioLoadType>> | null

void


setMasterVolume(volume): void

Defined in: audio/Audio.ts:653

number

void


setMaxVoices(max): void

Defined in: audio/Audio.ts:766

The voice ceiling; 0 or less means no cap.

number

void

playBuffer


setMusicVolume(volume): void

Defined in: audio/Audio.ts:661

number

void


setRefResolver(resolver): void

Defined in: audio/Audio.ts:381

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:669

number

void


setUIVolume(volume): void

Defined in: audio/Audio.ts:677

number

void


stopAll(): void

Defined in: audio/Audio.ts:571

void


stopBGM(fadeOut?): void

Defined in: audio/Audio.ts:609

number

void


suspend(): void

Defined in: audio/Audio.ts:632

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:265

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 unique decoded buffers freed.

number


updateDucking(): void

Defined in: audio/Audio.ts:908

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

void


updateFades(dt): void

Defined in: audio/Audio.ts:940

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