in Education by
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)

1 Answer

0 votes
by
getByteFrequencyData returns values in dB. You don't want to divide these values by the audioE1.volume. You want to convert (somehow!) audioE1.volume to a dB value and add (or subtract) that from values from getByteFrequencyData It might be easier to understand things if you used getFloatFrequencyData first to see what's happening.

Related questions

0 votes
    Problem I have several tests that do the same thing in mocha. This for me, it's duplication, and is the ... ) you have dataProviders. In phpUnit a dataProvider works this way:...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    hello I have the following code that maps through my text and prints typography, {['Example1:', 'Example2 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    hello I have the following code that maps through my text and prints typography, {['Example1:', 'Example2 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    is there a way to validate the pattern of an input by it's event object (without using a form)? ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 5, 2022 in Education by JackTerrance
0 votes
    is there a way to validate the pattern of an input by it's event object (without using a form)? ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    How can I check a regular expression to be fulfilled only if there is a number or group of numbers ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    How can I check a regular expression to be fulfilled only if there is a number or group of numbers ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I am looking for a way to close a component when there it a click outisde of the element. I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 2022 in Education by JackTerrance
0 votes
    I am trying to sort an array of objects by the name field but the ordering is wrong. The order I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    I have a custom input validation component that I use in a form. Something like 15 instances of this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have the following code: let pa = 0; let pw = 0; let pc = 0; let pi = 0; let ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    I'm importing Popup from react-leaflet import { Marker, Map, Popup, TileLayer, ZoomControl, GeoJSON, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I have the following code: let pa = 0; let pw = 0; let pc = 0; let pi = 0; let ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I am using this codepen https://codepen.io/anon/pen/jJXmpZ but I am struggling to implement a new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I am using this codepen https://codepen.io/anon/pen/jJXmpZ but I am struggling to implement a new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
...