UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

155 lines (151 loc) 4.58 kB
import { A as AbstractAudioBus } from './abstractAudioBus-CkEq97Sy.esm.js'; import { _ as _HasSpatialAudioOptions, a as _StereoAudio, b as _SpatialWebAudio, c as _WebAudioBusAndSoundSubGraph } from './spatialWebAudio-BoQhANFp.esm.js'; import './webAudioBaseSubGraph-Cl2P5hh_.esm.js'; import './audioEngine-DOe3dmI5.esm.js'; import './index-D8dpgsp6.esm.js'; /** * Abstract class for an audio bus that has spatial audio and stereo output capabilities. * * Instances of this class can be connected to other audio buses. * * Audio buses are created by the {@link CreateAudioBusAsync} function. */ class AudioBus extends AbstractAudioBus { constructor(name, engine) { super(name, engine); this._outBus = null; this._onOutBusDisposed = () => { this.outBus = this.engine.defaultMainBus; }; } /** * The output bus of the audio bus. Defaults to the audio engine's default main bus. */ get outBus() { return this._outBus; } set outBus(outBus) { if (this._outBus === outBus) { return; } if (this._outBus) { this._outBus.onDisposeObservable.removeCallback(this._onOutBusDisposed); if (!this._disconnect(this._outBus)) { throw new Error("Disconnect failed"); } } this._outBus = outBus; if (this._outBus) { this._outBus.onDisposeObservable.add(this._onOutBusDisposed); if (!this._connect(this._outBus)) { throw new Error("Connect failed"); } } } /** * Releases associated resources. */ dispose() { super.dispose(); this._outBus = null; } } /** @internal */ class _WebAudioBus extends AudioBus { /** @internal */ constructor(name, engine, options) { super(name, engine); this._spatial = null; this._spatialAutoUpdate = true; this._spatialMinUpdateTime = 0; this._stereo = null; if (typeof options.spatialAutoUpdate === "boolean") { this._spatialAutoUpdate = options.spatialAutoUpdate; } if (typeof options.spatialMinUpdateTime === "number") { this._spatialMinUpdateTime = options.spatialMinUpdateTime; } this._subGraph = new _WebAudioBus._SubGraph(this); } /** @internal */ async _initAsync(options) { if (options.outBus) { this.outBus = options.outBus; } else { await this.engine.isReadyPromise; this.outBus = this.engine.defaultMainBus; } await this._subGraph.initAsync(options); if (_HasSpatialAudioOptions(options)) { this._initSpatialProperty(); } this.engine._addNode(this); } /** @internal */ dispose() { super.dispose(); this._spatial = null; this._stereo = null; this.engine._removeNode(this); } /** @internal */ get _inNode() { return this._subGraph._inNode; } /** @internal */ get _outNode() { return this._subGraph._outNode; } /** @internal */ get spatial() { if (this._spatial) { return this._spatial; } return this._initSpatialProperty(); } /** @internal */ get stereo() { return this._stereo ?? (this._stereo = new _StereoAudio(this._subGraph)); } /** @internal */ getClassName() { return "_WebAudioBus"; } _connect(node) { const connected = super._connect(node); if (!connected) { return false; } if (node._inNode) { this._outNode?.connect(node._inNode); } return true; } _disconnect(node) { const disconnected = super._disconnect(node); if (!disconnected) { return false; } if (node._inNode) { this._outNode?.disconnect(node._inNode); } return true; } _initSpatialProperty() { if (!this._spatial) { this._spatial = new _SpatialWebAudio(this._subGraph, this._spatialAutoUpdate, this._spatialMinUpdateTime); } return this._spatial; } } _WebAudioBus._SubGraph = class extends _WebAudioBusAndSoundSubGraph { get _downstreamNodes() { return this._owner._downstreamNodes ?? null; } get _upstreamNodes() { return this._owner._upstreamNodes ?? null; } }; export { _WebAudioBus }; //# sourceMappingURL=webAudioBus-iTqxpzV7.esm.js.map