Check audio context support
This commit is contained in:
parent
1de3cc148e
commit
f1bde3a7a0
1 changed files with 6 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue