I don't understand how this https://github.com/bbc/peaks.js/blob/master/demo/TOL_6min_720p_download.json can be turned into a waveform visualization with peaks.
I see the data in that file is a flat array of numbers. I am trying to understand how to convert those numbers into something meaningful for visual drawing.
Check out this fiddle to see a deeper look into the code https://codesandbox.io/s/cool-dijkstra-fyw25?file=/src/App.js
The goal is to create peaks with a high and low that looks like the image. I assume every 2 indexes represent a peak, but I don't want to assume anything.
I am pulling the JSON and passing it into the draw function like this
const peaksReq = await fetch(
"https://raw.githubusercontent.com/bbc/peaks.js/master/demo/TOL_6min_720p_download.json"
);
const peaksData = await peaksReq.json();
const peaks = peaksData.data;
// peaks is now a flat array of numbers
The goal is to turn the flat peaks array into a bar like the image above. The first set of data is a bunch of 0's eventually a sequence with meaning looks something like this [-7,5,-27,25,-30,26,-29,30,-24,26]
My understanding -- a guess is to turn it into a 2d array like this [[-7,5],[-27,25],[-30,26],[-29,30],[-24,26]] then convert those numbers to px that will fit within a boundary. -7, 5 would go up and down relative to a center axiom.
The problem I don't quite understand how to solve is if it is within a 40px element how do we keep those numbers relative. i.e the center of 40px is 20px. The maximum a bar can go upwards in a 40px space from its center without going out of bounds is 20px, you could add a buffer of 5px and say 15px.
