Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getFloat32ArrayForFrameCount(frameCount, channel) {
var key = frameCount + " " + channel;
if (audioDataCache[key]) {
var ret = audioDataCache[key];
for (var i = 0; i < ret.length; ++i) {
ret[i] = 0;
}
return ret;
}
var ret = new Float32Array(frameCount);
audioDataCache[key] = ret;
return ret;
}
const EBUR128_LEFT_SURROUND = 4;
const EBUR128_RIGHT_SURROUND = 5;
const EBUR128_DUAL_MONO = 6;
const EBUR128_MODE_M = (1 << 0);
const EBUR128_MODE_S = (1 << 1) | EBUR128_MODE_M;
const EBUR128_MODE_I = (1 << 2) | EBUR128_MODE_M;
const EBUR128_MODE_LRA = (1 << 3) | EBUR128_MODE_S;
const EBUR128_MODE_SAMPLE_PEAK = (1 << 4) | EBUR128_MODE_M;
const EBUR128_MODE_TRUE_PEAK = (1 << 5) | EBUR128_MODE_M | EBUR128_MODE_SAMPLE_PEAK;
const EBUR128_MODE_HISTOGRAM = (1 << 6);
const relative_gate = -10.0;
const relative_gate_factor = Math.pow(10.0, relative_gate / 10.0);
//const minus_twenty_decibels = Math.pow(10.0, -20.0 / 10.0);
const histogram_energies = new Float32Array(1000);
const histogram_energy_boundaries = new Float32Array(1001);
histogram_energy_boundaries[0] = Math.pow(10.0, (-70.0 + 0.691) / 10.0);
for (var i = 1; i < 1001; ++i) {
histogram_energy_boundaries[i] = Math.pow(10.0, (i / 10.0 - 70.0 + 0.691) / 10.0);
}
for (var i = 0; i < 1000; ++i) {
histogram_energies[i] = Math.pow(10.0, (i / 10.0 - 69.95 + 0.691) / 10.0);
}
function ebur128_energy_to_loudness(energy) {
return 10 * (Math.log(energy) * Math.LOG10E) - 0.691;
}
function find_histogram_index(energy) {
var index_min = 0;
var index_max = 1000;
async initialize() {
const width = (this.canvas.clientWidth * this.page.devicePixelRatio() | 0) || 120;
const height = (this.canvas.clientHeight * this.page.devicePixelRatio() | 0) || 50;
this.width = width;
this.height = height;
this.currentCapPositions = new Float32Array(this.getNumBins());
this.emptyBins = new Float32Array(this.getNumBins());
this.transitionInfoArray = new Array(this.getNumBins());
this.canvas.width = width;
this.canvas.height = height;
for (let i = 0; i < this.transitionInfoArray.length; ++i) {
this.transitionInfoArray[i] = new TransitionInfo(this);
}
if (this.enabledMediaMatcher) {
addLegacyListener(this.enabledMediaMatcher, `change`, this.enabledMediaMatchChanged);
this.enabledMediaMatchChanged();
}
this.globalEvents.on(`resize`, this.binSizeMediaMatchChanged);
this.player.on(PLAYBACK_STOP_EVENT, this.playerStopped);
export default function Ebur128(channels, samplerate, mode) {
this.mode = mode;
this.samplerate = samplerate;
this.channels = Math.max(1, Math.min(channels, 5));
this.channel_map = [];
this.initChannels();
this.sample_peak = new Float32Array(channels);
this.true_peak = new Float32Array(channels);
this.use_histogram = (mode & EBUR128_MODE_HISTOGRAM) > 0;
this.samples_in_100ms = ((samplerate + 5) / 10) >>> 0;
this.needed_frames = this.samples_in_100ms * 4;
this.audio_data_index = 0;
this.audio_data_frames = 0;
if ((mode & EBUR128_MODE_S) === EBUR128_MODE_S) {
this.audio_data_frames = this.samples_in_100ms * 30;
} else if ((mode & EBUR128_MODE_M) === EBUR128_MODE_M) {
this.audio_data_frames = this.samples_in_100ms * 4;
} else {
throw new Error("invalid mode");
}
this.audio_data = new Array(channels);
for (var i = 0; i < channels; ++i) {
import {throttle} from "util";
import {Float32Array, performance} from "platform/platform";
import EventEmitter from "events";
import {cancelAndHold} from "audio/frontend/AudioPlayer";
import SourceDescriptor, {decibelToGain} from "audio/frontend/SourceDescriptor";
import {BUFFER_FILL_TYPE_SEEK,
BUFFER_FILL_TYPE_REPLACEMENT} from "audio/backend/AudioSource";
const NO_THROTTLE = {};
const EXPENSIVE_CALL_THROTTLE_TIME = 100;
export const FADE_MINIMUM_VOLUME = 0.2;
export const CURVE_LENGTH = 8;
export const CURVE_HOLDER = new Float32Array(CURVE_LENGTH + 1);
const getCurve = function(v0, v1) {
const t0 = 0;
const t1 = CURVE_LENGTH;
const ret = CURVE_HOLDER;
for (let t = t0; t <= t1; ++t) {
const value = v0 * Math.pow(v1 / v0, (t - t0) / (t1 - t0));
ret[t] = value;
}
return ret;
};
const getFadeOutCurve = function(startValue) {
return getCurve(startValue, FADE_MINIMUM_VOLUME);
};
import AbstractBackend from "AbstractBackend";
import {Float32Array, Float64Array} from "platform/platform";
import realFft from "audio/realfft";
export const AUDIO_VISUALIZER_READY_EVENT_NAME = `audioVisualizerReady`;
const weights = new Float32Array([
0, 0,
10, 0.0003019951720402013,
12.5, 0.0006760829753919819,
16, 0.0014621771744567184,
20, 0.0029853826189179603,
25, 0.10351421666793437,
31.5, 0.19054607179632474,
40, 0.481131121482591,
50, 0.5095408738576246,
63, 0.515408738576246,
80, 0.525408738576246,
100, 0.5395408738576246,
125, 0.5595408738576246,
160, 0.4195408738576246,
200, 0.4395408738576246,
250, 0.4495408738576246,
Ebur128.prototype.initFilter = function() {
var samplerate = this.samplerate;
var f0 = 1681.974450955533;
var G = 3.999843853973347;
var Q = 0.7071752369554196;
var K = Math.tan(Math.PI * f0 / samplerate);
var Vh = Math.pow(10.0, G / 20.0);
var Vb = Math.pow(Vh, 0.4996667741545416);
var pb = new Float32Array([0.0, 0.0, 0.0]);
var pa = new Float32Array([1.0, 0.0, 0.0]);
var rb = new Float32Array([1.0, -2.0, 1.0]);
var ra = new Float32Array([1.0, 0.0, 0.0]);
var a0 = 1.0 + K / Q + K * K;
pb[0] = (Vh + Vb * K / Q + K * K) / a0;
pb[1] = 2.0 * (K * K - Vh) / a0;
pb[2] = (Vh - Vb * K / Q + K * K) / a0;
pa[1] = 2.0 * (K * K - 1.0) / a0;
pa[2] = (1.0 - K / Q + K * K) / a0;
f0 = 38.13547087602444;
Q = 0.5003270373238773;
K = Math.tan(Math.PI * f0 / samplerate);
ra[1] = 2.0 * (K * K - 1.0) / (1.0 + K / Q + K * K);
_getDestinationBuffers() {
const {channelCount, targetBufferLengthAudioFrames} = this;
const ret = new Array(channelCount);
for (let ch = 0; ch < channelCount; ++ch) {
ret[ch] = new Float32Array(targetBufferLengthAudioFrames);
}
return ret;
}
const channelDataF32 = channelData.map(v => new Float32Array(v));
const binsF64 = new Float64Array(bins);