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.

3 lines (2 loc) 8.44 kB
import{g as e,d as t}from"./spatialWebAudioUpdaterComponent-LOlF6N8J.esm.min.js";import{y as s}from"./index-BPURObVq.esm.min.js";class n extends e{constructor(e,t){super(e,t,3)}connect(e){if(!this._connect(e))throw new Error("Connect failed")}disconnect(e){if(!this._disconnect(e))throw new Error("Disconnect failed")}disconnectAll(){if(!this._downstreamNodes)throw new Error("Disconnect failed");const e=this._downstreamNodes.values();for(let t=e.next();!t.done;t=e.next())if(!this._disconnect(t.value))throw new Error("Disconnect failed")}}const i={volume:1};class a extends n{constructor(e){super("Volume",e)}setOptions(e){this.setVolume(e.volume??i.volume,{shape:"none"})}}function o(e){return e.getSubNode("Volume")}const r=2048,u=-100,l=-30,h=.8;let d,c;class _{get frequencyBinCount(){return this.fftSize/2}getByteTimeDomainData(){return d??=new Uint8Array}getFloatTimeDomainData(){return c??=new Float32Array}}class m extends n{constructor(e){super("Analyzer",e)}setOptions(e){this.fftSize=e.analyzerFFTSize??r,this.minDecibels=e.analyzerMinDecibels??u,this.maxDecibels=e.analyzerMaxDecibels??l,this.smoothing=e.analyzerSmoothing??h}}function y(e){return e.getSubNode("Analyzer")}function b(e,t,s){e.callOnSubNode("Analyzer",e=>{e[t]=s})}let D=null,N=null;class f extends _{constructor(e){super(),this._fftSize=r,this._maxDecibels=l,this._minDecibels=u,this._smoothing=h,this._subGraph=e}get fftSize(){return this._fftSize}set fftSize(e){this._fftSize=e,b(this._subGraph,"fftSize",e)}get isEnabled(){return null!==y(this._subGraph)}get minDecibels(){return this._minDecibels}set minDecibels(e){this._minDecibels=e,b(this._subGraph,"minDecibels",e)}get maxDecibels(){return this._maxDecibels}set maxDecibels(e){this._maxDecibels=e,b(this._subGraph,"maxDecibels",e)}get smoothing(){return this._smoothing}set smoothing(e){this._smoothing=e,b(this._subGraph,"smoothing",e)}dispose(){const e=y(this._subGraph);e&&(this._subGraph.removeSubNodeAsync(e),e.dispose())}async enableAsync(){y(this._subGraph)||await this._subGraph.createAndAddSubNodeAsync("Analyzer")}getByteFrequencyData(){const e=y(this._subGraph);return e?e.getByteFrequencyData():(s.Warn("AudioAnalyzer not enabled"),this.enableAsync(),D||(D=new Uint8Array),D)}getByteTimeDomainData(){const e=y(this._subGraph);return e?e.getByteTimeDomainData():(s.Warn("AudioAnalyzer not enabled"),this.enableAsync(),super.getByteTimeDomainData())}getFloatFrequencyData(){const e=y(this._subGraph);return e?e.getFloatFrequencyData():(s.Warn("AudioAnalyzer not enabled"),this.enableAsync(),N||(N=new Float32Array),N)}getFloatTimeDomainData(){const e=y(this._subGraph);return e?e.getFloatTimeDomainData():(s.Warn("AudioAnalyzer not enabled"),this.enableAsync(),super.getFloatTimeDomainData())}}class g extends e{constructor(e,t,s){super(e,t,s),this._analyzer=null}get analyzer(){return this._analyzer??(this._analyzer=new f(this._subGraph))}get volume(){return e=this._subGraph,t="volume",o(e)?.[t]??i[t];var e,t}set volume(e){const t=o(this._subGraph);if(!t)throw new Error("No volume subnode");t.volume=e}dispose(){super.dispose(),this._analyzer?.dispose(),this._analyzer=null,this._subGraph.dispose()}setVolume(e,t=null){const s=o(this._subGraph);if(!s)throw new Error("No volume subnode");s.setVolume(e,t)}}class p{constructor(){this._createSubNodePromises={},this._isDisposed=!1,this._subNodes={},this._onSubNodeDisposed=e=>{const t=e;delete this._subNodes[t.name],this._onSubNodesChanged()}}callOnSubNode(e,t){const s=this.getSubNode(e);s?t(s):this._createSubNodePromisesResolvedAsync().then(()=>{const s=this.getSubNode(e);s?t(s):this.createAndAddSubNodeAsync(e).then(e=>{t(e)})})}createAndAddSubNodeAsync(e){return this._createSubNodePromises[e]||=this._createSubNode(e).then(e=>(this._addSubNode(e),e)),this._createSubNodePromises[e]}dispose(){this._isDisposed=!0;const e=Object.values(this._subNodes);for(const t of e)t.dispose();this._subNodes={},this._createSubNodePromises={}}getSubNode(e){return this._subNodes[e]??null}async removeSubNodeAsync(e){if(!e)return;await this._createSubNodePromisesResolvedAsync();const t=e.name;this._subNodes[t]&&delete this._subNodes[t],delete this._createSubNodePromises[t],this._onSubNodesChanged()}async _createSubNodePromisesResolvedAsync(){return await Promise.all(Object.values(this._createSubNodePromises))}_addSubNode(e){this._isDisposed?e.dispose():(this._subNodes[e.name]=e,e.onDisposeObservable.addOnce(this._onSubNodeDisposed),this._onSubNodesChanged())}}class z extends a{constructor(e){super(e);const s=this.node=new GainNode(e._audioContext);this._volume=new t(e,s.gain)}dispose(){super.dispose(),this._volume.dispose()}get volume(){return this._volume.value}set volume(e){this.setVolume(e)}get _inNode(){return this.node}get _outNode(){return this.node}setVolume(e,t=null){this._volume.setTargetValue(e,t)}_connect(e){return!!super._connect(e)&&(e._inNode&&this.node.connect(e._inNode),!0)}_disconnect(e){return!!super._disconnect(e)&&(e._inNode&&this.node.disconnect(e._inNode),!0)}getClassName(){return"_VolumeWebAudioSubNode"}}class A extends m{constructor(e){super(e),this._byteFrequencyData=null,this._byteTimeDomainData=null,this._floatFrequencyData=null,this._floatTimeDomainData=null,this._analyzerNode=new AnalyserNode(e._audioContext)}get fftSize(){return this._analyzerNode.fftSize}set fftSize(e){e!==this._analyzerNode.fftSize&&(this._analyzerNode.fftSize=e,this._clearArrays())}get _inNode(){return this._analyzerNode}get minDecibels(){return this._analyzerNode.minDecibels}set minDecibels(e){this._analyzerNode.minDecibels=e}get maxDecibels(){return this._analyzerNode.maxDecibels}set maxDecibels(e){this._analyzerNode.maxDecibels=e}get smoothing(){return this._analyzerNode.smoothingTimeConstant}set smoothing(e){this._analyzerNode.smoothingTimeConstant=e}dispose(){super.dispose(),this._clearArrays(),this._analyzerNode.disconnect()}getClassName(){return"_WebAudioAnalyzerSubNode"}getByteFrequencyData(){return this._byteFrequencyData&&0!==this._byteFrequencyData.length||(this._byteFrequencyData=new Uint8Array(this._analyzerNode.frequencyBinCount)),this._analyzerNode.getByteFrequencyData(this._byteFrequencyData),this._byteFrequencyData}getByteTimeDomainData(){return this._byteTimeDomainData&&0!==this._byteTimeDomainData.length||(this._byteTimeDomainData=new Uint8Array(this._analyzerNode.fftSize)),this._analyzerNode.getByteTimeDomainData(this._byteTimeDomainData),this._byteTimeDomainData}getFloatFrequencyData(){return this._floatFrequencyData&&0!==this._floatFrequencyData.length||(this._floatFrequencyData=new Float32Array(this._analyzerNode.frequencyBinCount)),this._analyzerNode.getFloatFrequencyData(this._floatFrequencyData),this._floatFrequencyData}getFloatTimeDomainData(){return this._floatTimeDomainData&&0!==this._floatTimeDomainData.length||(this._floatTimeDomainData=new Float32Array(this._analyzerNode.fftSize)),this._analyzerNode.getFloatTimeDomainData(this._floatTimeDomainData),this._floatTimeDomainData}_clearArrays(){this._byteFrequencyData=null,this._byteTimeDomainData=null,this._floatFrequencyData=null,this._floatTimeDomainData=null}}class S extends p{constructor(e){super(),this._outputNode=null,this._owner=e}async initAsync(e){const t=function(e){return e.analyzerEnabled||void 0!==e.analyzerFFTSize||void 0!==e.analyzerMinDecibels||void 0!==e.analyzerMaxDecibels||void 0!==e.analyzerSmoothing}(e);if(t&&await this.createAndAddSubNodeAsync("Analyzer"),await this.createAndAddSubNodeAsync("Volume"),await this._createSubNodePromisesResolvedAsync(),t){const t=y(this);if(!t)throw new Error("No analyzer subnode.");t.setOptions(e)}const s=o(this);if(!s)throw new Error("No volume subnode.");if(s.setOptions(e),"_VolumeWebAudioSubNode"!==s.getClassName())throw new Error("Not a WebAudio subnode.");if(this._outputNode=s.node,this._outputNode&&this._downstreamNodes){const e=this._downstreamNodes.values();for(let t=e.next();!t.done;t=e.next()){const e=t.value._inNode;e&&this._outputNode.connect(e)}}}get _inNode(){return this._outputNode}get _outNode(){return this._outputNode}_createSubNode(e){switch(e){case"Analyzer":return async function(e){return new A(e)}(this._owner.engine);case"Volume":return async function(e){return new z(e)}(this._owner.engine);default:throw new Error(`Unknown subnode name: ${e}`)}}_onSubNodesChanged(){const e=y(this),t=o(this);e&&t&&t.connect(e)}}export{g as A,S as _,n as a,o as b}; //# sourceMappingURL=webAudioBaseSubGraph-Ww7puCo8.esm.min.js.map