UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

71 lines 2.24 kB
import { AbstractNamedAudioNode } from "./abstractAudioNode.js"; import { _GetVolumeAudioProperty, _GetVolumeAudioSubNode } from "./subNodes/volumeAudioSubNode.js"; import { _AudioAnalyzer } from "./subProperties/audioAnalyzer.js"; /** * Abstract class representing a sound in the audio engine. */ export class AbstractSoundSource extends AbstractNamedAudioNode { constructor(name, engine, nodeType = 2 /* AudioNodeType.HAS_OUTPUTS */) { super(name, engine, nodeType); this._analyzer = null; this._outBus = null; this._onOutBusDisposed = () => { this._outBus = null; }; } /** * The analyzer features of the sound. */ get analyzer() { return this._analyzer ?? (this._analyzer = new _AudioAnalyzer(this._subGraph)); } /** * The output bus for the sound. * @see {@link AudioEngineV2.defaultMainBus} */ 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"); } } } /** * The output volume of the sound. */ get volume() { return _GetVolumeAudioProperty(this._subGraph, "volume"); } set volume(value) { // The volume subnode is created on initialization and should always exist. const node = _GetVolumeAudioSubNode(this._subGraph); if (!node) { throw new Error("No volume subnode"); } node.volume = value; } /** * Releases associated resources. */ dispose() { super.dispose(); this._analyzer?.dispose(); this._analyzer = null; this._outBus = null; } } //# sourceMappingURL=abstractSoundSource.js.map