Check audio context support

This commit is contained in:
N-Pex 2024-10-25 12:50:14 +02:00
parent 1de3cc148e
commit f1bde3a7a0

View file

@ -502,13 +502,16 @@ class Util {
}
generateWaveform(data, messageContent) {
if (!(window.AudioContext || window.webkitAudioContext)) {
return; // No support
}
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
if (audioCtx) {
return audioCtx.decodeAudioData(data)
.then((audioBuffer) => {
const rawData = audioBuffer.getChannelData(0); // We only need to work with one channel of data
const samples = 1000; // Number of samples we want to have in our final data set
const blockSize = Math.floor(rawData.length / samples); // the number of samples in each subdivision
const rawData = audioBuffer.getChannelData(0); // TODO - currently using only 1 channel
const samples = 1000; // Number of samples
const blockSize = Math.floor(rawData.length / samples);
let filteredData = [];
for (let i = 0; i < samples; i++) {
let blockStart = blockSize * i; // the location of the first sample in the block