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.

104 lines 3.4 kB
import { Logger } from "../../../Misc/logger.js"; import { _AudioAnalyzerDefaults, AbstractAudioAnalyzer } from "../../abstractAudio/subProperties/abstractAudioAnalyzer.js"; import { _GetAudioAnalyzerSubNode, _SetAudioAnalyzerProperty } from "../subNodes/audioAnalyzerSubNode.js"; let _emptyByteFrequencyData = null; let _emptyFloatFrequencyData = null; /** @internal */ export function _GetEmptyByteFrequencyData() { if (!_emptyByteFrequencyData) { _emptyByteFrequencyData = new Uint8Array(); } return _emptyByteFrequencyData; } /** @internal */ export function _GetEmptyFloatFrequencyData() { if (!_emptyFloatFrequencyData) { _emptyFloatFrequencyData = new Float32Array(); } return _emptyFloatFrequencyData; } /** @internal */ export class _AudioAnalyzer extends AbstractAudioAnalyzer { /** @internal */ constructor(subGraph) { super(); this._fftSize = _AudioAnalyzerDefaults.fftSize; this._maxDecibels = _AudioAnalyzerDefaults.maxDecibels; this._minDecibels = _AudioAnalyzerDefaults.minDecibels; this._smoothing = _AudioAnalyzerDefaults.smoothing; this._subGraph = subGraph; } /** @internal */ get fftSize() { return this._fftSize; } set fftSize(value) { this._fftSize = value; _SetAudioAnalyzerProperty(this._subGraph, "fftSize", value); } /** @internal */ get isEnabled() { return _GetAudioAnalyzerSubNode(this._subGraph) !== null; } /** @internal */ get minDecibels() { return this._minDecibels; } set minDecibels(value) { this._minDecibels = value; _SetAudioAnalyzerProperty(this._subGraph, "minDecibels", value); } /** @internal */ get maxDecibels() { return this._maxDecibels; } set maxDecibels(value) { this._maxDecibels = value; _SetAudioAnalyzerProperty(this._subGraph, "maxDecibels", value); } /** @internal */ get smoothing() { return this._smoothing; } set smoothing(value) { this._smoothing = value; _SetAudioAnalyzerProperty(this._subGraph, "smoothing", value); } /** @internal */ dispose() { const subNode = _GetAudioAnalyzerSubNode(this._subGraph); if (subNode) { this._subGraph.removeSubNode(subNode); subNode.dispose(); } } /** @internal */ async enableAsync() { const subNode = _GetAudioAnalyzerSubNode(this._subGraph); if (!subNode) { await this._subGraph.createAndAddSubNode("Analyzer" /* AudioSubNode.ANALYZER */); } return Promise.resolve(); } /** @internal */ getByteFrequencyData() { const subNode = _GetAudioAnalyzerSubNode(this._subGraph); if (!subNode) { Logger.Warn("AudioAnalyzer not enabled"); this.enableAsync(); return _GetEmptyByteFrequencyData(); } return subNode.getByteFrequencyData(); } /** @internal */ getFloatFrequencyData() { const subNode = _GetAudioAnalyzerSubNode(this._subGraph); if (!subNode) { Logger.Warn("AudioAnalyzer not enabled"); this.enableAsync(); return _GetEmptyFloatFrequencyData(); } return subNode.getFloatFrequencyData(); } } //# sourceMappingURL=audioAnalyzer.js.map