5d5cbe5f356c72d832ab4b28eb76095e95d3d91287786d78dbfa416e62f63767.json 17 KB

1
  1. {"ast":null,"code":"import { EngineStore } from \"../Engines/engineStore.js\";\nimport { AbstractEngine } from \"../Engines/abstractEngine.js\";\n/**\n * It could be useful to isolate your music & sounds on several tracks to better manage volume on a grouped instance of sounds.\n * It will be also used in a future release to apply effects on a specific track.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#using-sound-tracks\n */\nexport class SoundTrack {\n /**\n * Creates a new sound track.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#using-sound-tracks\n * @param scene Define the scene the sound track belongs to\n * @param options\n */\n constructor(scene, options = {}) {\n /**\n * The unique identifier of the sound track in the scene.\n */\n this.id = -1;\n this._isInitialized = false;\n scene = scene || EngineStore.LastCreatedScene;\n if (!scene) {\n return;\n }\n this._scene = scene;\n this.soundCollection = [];\n this._options = options;\n if (!this._options.mainTrack && this._scene.soundTracks) {\n this._scene.soundTracks.push(this);\n this.id = this._scene.soundTracks.length - 1;\n }\n }\n _initializeSoundTrackAudioGraph() {\n var _AbstractEngine$audio;\n if ((_AbstractEngine$audio = AbstractEngine.audioEngine) !== null && _AbstractEngine$audio !== void 0 && _AbstractEngine$audio.canUseWebAudio && AbstractEngine.audioEngine.audioContext) {\n this._outputAudioNode = AbstractEngine.audioEngine.audioContext.createGain();\n this._outputAudioNode.connect(AbstractEngine.audioEngine.masterGain);\n if (this._options) {\n if (this._options.volume) {\n this._outputAudioNode.gain.value = this._options.volume;\n }\n }\n this._isInitialized = true;\n }\n }\n /**\n * Release the sound track and its associated resources\n */\n dispose() {\n if (AbstractEngine.audioEngine && AbstractEngine.audioEngine.canUseWebAudio) {\n if (this._connectedAnalyser) {\n this._connectedAnalyser.stopDebugCanvas();\n }\n while (this.soundCollection.length) {\n this.soundCollection[0].dispose();\n }\n if (this._outputAudioNode) {\n this._outputAudioNode.disconnect();\n }\n this._outputAudioNode = null;\n }\n }\n /**\n * Adds a sound to this sound track\n * @param sound define the sound to add\n * @ignoreNaming\n */\n addSound(sound) {\n var _AbstractEngine$audio2;\n if (!this._isInitialized) {\n this._initializeSoundTrackAudioGraph();\n }\n if ((_AbstractEngine$audio2 = AbstractEngine.audioEngine) !== null && _AbstractEngine$audio2 !== void 0 && _AbstractEngine$audio2.canUseWebAudio && this._outputAudioNode) {\n sound.connectToSoundTrackAudioNode(this._outputAudioNode);\n }\n if (sound.soundTrackId !== undefined) {\n if (sound.soundTrackId === -1) {\n this._scene.mainSoundTrack.removeSound(sound);\n } else if (this._scene.soundTracks) {\n this._scene.soundTracks[sound.soundTrackId].removeSound(sound);\n }\n }\n this.soundCollection.push(sound);\n sound.soundTrackId = this.id;\n }\n /**\n * Removes a sound to this sound track\n * @param sound define the sound to remove\n * @ignoreNaming\n */\n removeSound(sound) {\n const index = this.soundCollection.indexOf(sound);\n if (index !== -1) {\n this.soundCollection.splice(index, 1);\n }\n }\n /**\n * Set a global volume for the full sound track.\n * @param newVolume Define the new volume of the sound track\n */\n setVolume(newVolume) {\n var _AbstractEngine$audio3;\n if ((_AbstractEngine$audio3 = AbstractEngine.audioEngine) !== null && _AbstractEngine$audio3 !== void 0 && _AbstractEngine$audio3.canUseWebAudio && this._outputAudioNode) {\n this._outputAudioNode.gain.value = newVolume;\n }\n }\n /**\n * Switch the panning model to HRTF:\n * Renders a stereo output of higher quality than equalpower — it uses a convolution with measured impulse responses from human subjects.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound\n */\n switchPanningModelToHRTF() {\n var _AbstractEngine$audio4;\n if ((_AbstractEngine$audio4 = AbstractEngine.audioEngine) !== null && _AbstractEngine$audio4 !== void 0 && _AbstractEngine$audio4.canUseWebAudio) {\n for (let i = 0; i < this.soundCollection.length; i++) {\n this.soundCollection[i].switchPanningModelToHRTF();\n }\n }\n }\n /**\n * Switch the panning model to Equal Power:\n * Represents the equal-power panning algorithm, generally regarded as simple and efficient. equalpower is the default value.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound\n */\n switchPanningModelToEqualPower() {\n var _AbstractEngine$audio5;\n if ((_AbstractEngine$audio5 = AbstractEngine.audioEngine) !== null && _AbstractEngine$audio5 !== void 0 && _AbstractEngine$audio5.canUseWebAudio) {\n for (let i = 0; i < this.soundCollection.length; i++) {\n this.soundCollection[i].switchPanningModelToEqualPower();\n }\n }\n }\n /**\n * Connect the sound track to an audio analyser allowing some amazing\n * synchronization between the sounds/music and your visualization (VuMeter for instance).\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#using-the-analyser\n * @param analyser The analyser to connect to the engine\n */\n connectToAnalyser(analyser) {\n var _AbstractEngine$audio6;\n if (this._connectedAnalyser) {\n this._connectedAnalyser.stopDebugCanvas();\n }\n this._connectedAnalyser = analyser;\n if ((_AbstractEngine$audio6 = AbstractEngine.audioEngine) !== null && _AbstractEngine$audio6 !== void 0 && _AbstractEngine$audio6.canUseWebAudio && this._outputAudioNode) {\n this._outputAudioNode.disconnect();\n this._connectedAnalyser.connectAudioNodes(this._outputAudioNode, AbstractEngine.audioEngine.masterGain);\n }\n }\n}","map":{"version":3,"names":["EngineStore","AbstractEngine","SoundTrack","constructor","scene","options","id","_isInitialized","LastCreatedScene","_scene","soundCollection","_options","mainTrack","soundTracks","push","length","_initializeSoundTrackAudioGraph","_AbstractEngine$audio","audioEngine","canUseWebAudio","audioContext","_outputAudioNode","createGain","connect","masterGain","volume","gain","value","dispose","_connectedAnalyser","stopDebugCanvas","disconnect","addSound","sound","_AbstractEngine$audio2","connectToSoundTrackAudioNode","soundTrackId","undefined","mainSoundTrack","removeSound","index","indexOf","splice","setVolume","newVolume","_AbstractEngine$audio3","switchPanningModelToHRTF","_AbstractEngine$audio4","i","switchPanningModelToEqualPower","_AbstractEngine$audio5","connectToAnalyser","analyser","_AbstractEngine$audio6","connectAudioNodes"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Audio/soundTrack.js"],"sourcesContent":["import { EngineStore } from \"../Engines/engineStore.js\";\nimport { AbstractEngine } from \"../Engines/abstractEngine.js\";\n/**\n * It could be useful to isolate your music & sounds on several tracks to better manage volume on a grouped instance of sounds.\n * It will be also used in a future release to apply effects on a specific track.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#using-sound-tracks\n */\nexport class SoundTrack {\n /**\n * Creates a new sound track.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#using-sound-tracks\n * @param scene Define the scene the sound track belongs to\n * @param options\n */\n constructor(scene, options = {}) {\n /**\n * The unique identifier of the sound track in the scene.\n */\n this.id = -1;\n this._isInitialized = false;\n scene = scene || EngineStore.LastCreatedScene;\n if (!scene) {\n return;\n }\n this._scene = scene;\n this.soundCollection = [];\n this._options = options;\n if (!this._options.mainTrack && this._scene.soundTracks) {\n this._scene.soundTracks.push(this);\n this.id = this._scene.soundTracks.length - 1;\n }\n }\n _initializeSoundTrackAudioGraph() {\n if (AbstractEngine.audioEngine?.canUseWebAudio && AbstractEngine.audioEngine.audioContext) {\n this._outputAudioNode = AbstractEngine.audioEngine.audioContext.createGain();\n this._outputAudioNode.connect(AbstractEngine.audioEngine.masterGain);\n if (this._options) {\n if (this._options.volume) {\n this._outputAudioNode.gain.value = this._options.volume;\n }\n }\n this._isInitialized = true;\n }\n }\n /**\n * Release the sound track and its associated resources\n */\n dispose() {\n if (AbstractEngine.audioEngine && AbstractEngine.audioEngine.canUseWebAudio) {\n if (this._connectedAnalyser) {\n this._connectedAnalyser.stopDebugCanvas();\n }\n while (this.soundCollection.length) {\n this.soundCollection[0].dispose();\n }\n if (this._outputAudioNode) {\n this._outputAudioNode.disconnect();\n }\n this._outputAudioNode = null;\n }\n }\n /**\n * Adds a sound to this sound track\n * @param sound define the sound to add\n * @ignoreNaming\n */\n addSound(sound) {\n if (!this._isInitialized) {\n this._initializeSoundTrackAudioGraph();\n }\n if (AbstractEngine.audioEngine?.canUseWebAudio && this._outputAudioNode) {\n sound.connectToSoundTrackAudioNode(this._outputAudioNode);\n }\n if (sound.soundTrackId !== undefined) {\n if (sound.soundTrackId === -1) {\n this._scene.mainSoundTrack.removeSound(sound);\n }\n else if (this._scene.soundTracks) {\n this._scene.soundTracks[sound.soundTrackId].removeSound(sound);\n }\n }\n this.soundCollection.push(sound);\n sound.soundTrackId = this.id;\n }\n /**\n * Removes a sound to this sound track\n * @param sound define the sound to remove\n * @ignoreNaming\n */\n removeSound(sound) {\n const index = this.soundCollection.indexOf(sound);\n if (index !== -1) {\n this.soundCollection.splice(index, 1);\n }\n }\n /**\n * Set a global volume for the full sound track.\n * @param newVolume Define the new volume of the sound track\n */\n setVolume(newVolume) {\n if (AbstractEngine.audioEngine?.canUseWebAudio && this._outputAudioNode) {\n this._outputAudioNode.gain.value = newVolume;\n }\n }\n /**\n * Switch the panning model to HRTF:\n * Renders a stereo output of higher quality than equalpower — it uses a convolution with measured impulse responses from human subjects.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound\n */\n switchPanningModelToHRTF() {\n if (AbstractEngine.audioEngine?.canUseWebAudio) {\n for (let i = 0; i < this.soundCollection.length; i++) {\n this.soundCollection[i].switchPanningModelToHRTF();\n }\n }\n }\n /**\n * Switch the panning model to Equal Power:\n * Represents the equal-power panning algorithm, generally regarded as simple and efficient. equalpower is the default value.\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound\n */\n switchPanningModelToEqualPower() {\n if (AbstractEngine.audioEngine?.canUseWebAudio) {\n for (let i = 0; i < this.soundCollection.length; i++) {\n this.soundCollection[i].switchPanningModelToEqualPower();\n }\n }\n }\n /**\n * Connect the sound track to an audio analyser allowing some amazing\n * synchronization between the sounds/music and your visualization (VuMeter for instance).\n * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#using-the-analyser\n * @param analyser The analyser to connect to the engine\n */\n connectToAnalyser(analyser) {\n if (this._connectedAnalyser) {\n this._connectedAnalyser.stopDebugCanvas();\n }\n this._connectedAnalyser = analyser;\n if (AbstractEngine.audioEngine?.canUseWebAudio && this._outputAudioNode) {\n this._outputAudioNode.disconnect();\n this._connectedAnalyser.connectAudioNodes(this._outputAudioNode, AbstractEngine.audioEngine.masterGain);\n }\n }\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,2BAA2B;AACvD,SAASC,cAAc,QAAQ,8BAA8B;AAC7D;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,CAAC;EACpB;AACJ;AACA;AACA;AACA;AACA;EACIC,WAAWA,CAACC,KAAK,EAAEC,OAAO,GAAG,CAAC,CAAC,EAAE;IAC7B;AACR;AACA;IACQ,IAAI,CAACC,EAAE,GAAG,CAAC,CAAC;IACZ,IAAI,CAACC,cAAc,GAAG,KAAK;IAC3BH,KAAK,GAAGA,KAAK,IAAIJ,WAAW,CAACQ,gBAAgB;IAC7C,IAAI,CAACJ,KAAK,EAAE;MACR;IACJ;IACA,IAAI,CAACK,MAAM,GAAGL,KAAK;IACnB,IAAI,CAACM,eAAe,GAAG,EAAE;IACzB,IAAI,CAACC,QAAQ,GAAGN,OAAO;IACvB,IAAI,CAAC,IAAI,CAACM,QAAQ,CAACC,SAAS,IAAI,IAAI,CAACH,MAAM,CAACI,WAAW,EAAE;MACrD,IAAI,CAACJ,MAAM,CAACI,WAAW,CAACC,IAAI,CAAC,IAAI,CAAC;MAClC,IAAI,CAACR,EAAE,GAAG,IAAI,CAACG,MAAM,CAACI,WAAW,CAACE,MAAM,GAAG,CAAC;IAChD;EACJ;EACAC,+BAA+BA,CAAA,EAAG;IAAA,IAAAC,qBAAA;IAC9B,IAAI,CAAAA,qBAAA,GAAAhB,cAAc,CAACiB,WAAW,cAAAD,qBAAA,eAA1BA,qBAAA,CAA4BE,cAAc,IAAIlB,cAAc,CAACiB,WAA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