Normalize audio from getByteFrequencyData by volume

I created the getSpectrum method using the getByteFrequencyData method in the Node Web Audio API Analyzer. The array of returned audio data refers to the sound source (either to the element or to the Audio () element) volume , a value from 0 to 1.

Using the volume of the audio source, I am trying to normalize every value obtained from getByteFrequencyData so that the user of getSpectrum does not need to worry about the volume when they render the audio data.

This is the striped 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 specification refers to the equation used to calculate the return value given maxDecibels and minDecibels. With my rudimentary understanding, I tried to change the math to get a normalized value, but I can't get it to work correctly. I am having trouble achieving this using only a volume value from 0 to 1.

Any incitement would be greatly appreciated! Heres a working example of a problem. Changing the volume slider will show the problem.

Update 7/22/16: Thanks to @ raymond-toy's answer, I figured out how to convert the value 0 to 1 to decibels.

 volumeDB = Math.abs((Math.log(volume)/Math.LN10)*20); 

After getting the DB, I inverted the equation in the W3C specification,

 value = ((audioDataValue * volumeDB) / 255) - volumeDB 

Unfortunately, value still ends relative to volume . Does anyone see what I'm missing?

+6
source share
2 answers

Apparently, I was on a stupid errand. As @ raymond-toy noted, Spectrum values ​​implicitly refer to volume. Normalization would mean losing part of the data “from the bottom of the spectrum,” which was not my goal.

If anyone is interested, I just split audioDataValue by 255, getting a float from 0 to 1.

+1
source

getByteFrequencyData returns values ​​in dB. You do not want to divide these values ​​into an audio instance. You want to convert (somehow!) AudioE1.volume to a dB value and add (or subtract) that from the values ​​from getByteFrequencyData

It might be easier to understand if you first used getFloatFrequencyData to see what was happening.

+1
source

All Articles