I've created a getSpectrum method using the getByteFrequencyData method on the Web Audio API's Analyser Node. The array of audio data returned is relative to the audio source's (either an el, or Audio() instance) volume, a value from 0 to 1.
Using the audio source's volume I'm trying to normalize each value received from getByteFrequencyData so that the user of getSpectrum doesn't have to worry about volume when they're visualizing the audio data.
This is the striped down version of getSpectrum
var audioData = new Uint8Array(analyser.binCount);
var spectrum = [];
analyser.getByteFrequencyData(audioData);
for (var i = 0; i < audioData.length; i++) {
var value = audioData[i];
//Where I'm trying to calculate the value independent of volume
value = ((value / audioEl.volume) / 255);
spectrum.push(value);
}
return spectrum;
The W3C spec references the equation used to calculate the returned value given a maxDecibels and minDecibels. With my rudimentary understanding, I've tried to inverse the math so I get a normalized value, but I can't getting it working exactly right. I'm having trouble accomplishing this with just a volume value from 0 to 1.
Any incite would be greatly appreciated! Heres a working example of the issue. Changing the volume slider will illustrate the problem.
Update 7/22/16: Thanks to @raymond-toy's answer I figured out how to convert the 0 to 1 volume value to decibels.
volumeDB = Math.abs((Math.log(volume)/Math.LN10)*20);
After getting the DB, I inversed the equation in the W3C spec,
value = ((audioDataValue * volumeDB) / 255) - volumeDB
Unfortunately, value somehow still ends up relative to volume. Does anyone see what I'm missing?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)