How can I pass a custom int parameter into the script that is available globally from the configuration of the instance?
I'm trying to display the currently received volume for a stream - the below implementation logs it to the console. Ideally this would be implemented as a callback that could update labels or canvases for multiple players on a single page with the currently received audio volume.
I'm attempting to add the following code which allows for adding a web audio analyzer connects to the chain that calculates the volume currently received
const scriptNode = e.createScriptProcessor(16384, 2, 2);
const myAudio = document.querySelector("audio");
const source = e.createMediaElementSource(myAudio);
const analyser = e.createAnalyser();
source.connect(analyser);
analyser.connect(e.destination);
scriptNode.connect(e.destination),
(e.onstatechange = () => {
"running" !== e.state && e.resume().catch(t);
});
analyser.fftSize = 2048;
const sampleBuffer = new Float32Array(analyser.fftSize);
setInterval(function() {
analyser.getFloatTimeDomainData(sampleBuffer);
// Compute average power over the interval.
let sumOfSquares = 0;
for (let i = 0; i < sampleBuffer.length; i++) {
sumOfSquares += sampleBuffer[i] ** 2;
}
const avgPowerDecibels = 10 * Math.log10(sumOfSquares / sampleBuffer.length);
// Compute peak instantaneous power over the interval.
let peakInstantaneousPower = 0;
for (let i = 0; i < sampleBuffer.length; i++) {
const power = sampleBuffer[i] ** 2;
peakInstantaneousPower = Math.max(power, peakInstantaneousPower);
}
const peakInstantaneousPowerDecibels = 10 * Math.log10(peakInstantaneousPower);
console.log(avgPowerDecibels.toFixed(2));
}, 1000);
})
How can I pass a custom int parameter into the script that is available globally from the configuration of the instance?
I'm trying to display the currently received volume for a stream - the below implementation logs it to the console. Ideally this would be implemented as a callback that could update labels or canvases for multiple players on a single page with the currently received audio volume.
I'm attempting to add the following code which allows for adding a web audio analyzer connects to the chain that calculates the volume currently received