141
rated 0 times
[
142]
[
1]
/ answers: 1 / hits: 15931
/ 13 Years ago, thu, march 1, 2012, 12:00:00
How do I write a JavaScript program to display a waveform from an audio file? I want to use Web Audio and Canvas.
I tried this code:
(new window.AudioContext).decodeAudioData(audioFile, function (data) {
var channel = data.getChannelData(0);
for (var i = 0; i < channel; i++) {
canvas.getContext('2d').fillRect(i, 1, 40 - channel[i], 40);
}
});
But the result is far from what I want (namely, the image is not smooth since I'm drawing with rectangles). I want it to look smooth like this image:
Any hints on how to implement the waveform?
More From » html