JavaScript HTML 5 Audio lib - How to get the average value of the music table

I have found there a nice and working perfectly fine tutorial to play with music with a web library.

Everything is working fine but I would like to have the "average value" of the music I play. Let me explain that. Currently: music is loaded,

function loadSound(url) {
        var request = new XMLHttpRequest();
        request.open('GET', url, true);
        request.responseType = 'arraybuffer';

        // When loaded decode the data
        request.onload = function() {

            // decode the data
            context.decodeAudioData(request.response, function(buffer) {
                // when the audio is decoded play the sound
                playSound(buffer);
            }, onError);
        }
        request.send();
    }

and buffer played. I can easily find the average value of the buffer that way:

var getAverage = function(dataArray){
        var total = 0,                               // initialize to 0
            i = 0, length = dataArray.length;
        while(i < length) total += dataArray[i++];   // add all
        return length ? total / length : 0;          // divide (when length !== 0)
    }

used there

javascriptNode.onaudioprocess = function() {

        // get the average for the first channel
        var array =  new Uint8Array(analyser.frequencyBinCount);
        analyser.getByteFrequencyData(array);

        // clear the current state
        ctx.clearRect(0, 0, 1000, 325);

        // set the fill style
        ctx.fillStyle=gradient;
        drawSpectrum(array);
        var averageVal = getAverage(array);

But what about the "global" value and not only the one put in the buffer?

In a word: how to recover the global Uint8Array object from the loaded mp3, and not only the parsed buffer?

Many thanks for you help!

Answer:1

I have a JSON object: var info=JSON.parse(server_response); I run console.log(info); And got this output: [ [ [ "Dipu", "Mondal", "O Positive", "017xxxx", "...

I have a JSON object: var info=JSON.parse(server_response); I run console.log(info); And got this output: [ [ [ "Dipu", "Mondal", "O Positive", "017xxxx", "...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. cancun
  6. canada goose
  7. cane corso
  8. canes
  9. canadian prime minister
  10. cancun flights
  11. canker sore
  12. candy
  13. cancer
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis

I'm trying to make kind of typewriting effect in HTML5. For rendering and puting it all together , I'm using this pixi.js plugin. So far I have been able to make it work (partially), although it ...

I'm trying to make kind of typewriting effect in HTML5. For rendering and puting it all together , I'm using this pixi.js plugin. So far I have been able to make it work (partially), although it ...

The azure-functions-cli offers a way to kickoff debugging, but these instructions seem to be Visual Studio specific. I tried using a similar trick to serverless by setting up a run config in WebStorm ...

The azure-functions-cli offers a way to kickoff debugging, but these instructions seem to be Visual Studio specific. I tried using a similar trick to serverless by setting up a run config in WebStorm ...

  1. azure functions debug locally
  2. azure functions debug vscode
  3. azure functions debug visual studio
  4. azure functions debug port
  5. azure functions debug
  6. azure functions debug log
  7. azure functions debug console
  8. azure functions debug mode
  9. azure functions debug timertrigger
  10. azure functions debug https
  11. azure function debug remote
  12. azure function debug not working
  13. azure function debug blob trigger
  14. azure function debug locally timer trigger
  15. azure function debug change port
  16. azure function debug startup

I have recently applied on my website an invisible Google ReCaptcha, but it is showing Unexpected Error: Invalid token= when I use the following code: <script src="https://www.google.com/...

I have recently applied on my website an invisible Google ReCaptcha, but it is showing Unexpected Error: Invalid token= when I use the following code: <script src="https://www.google.com/...

  1. javascript error invalid or unexpected token
  2. javascript error invalid left-hand side in assignment
  3. javascript error invalid character
  4. javascript error invalid argument
  5. javascript error invalid shorthand property initializer
  6. javascript error invalid date
  7. javascript error invalid regular expression flags
  8. javascript error invalid xml
  9. javascript error invalid label
  10. javascript error invalid token
  11. javascript runtime error invalid character
  12. javascript runtime error invalid calling object
  13. javascript runtime error invalid character json.parse
  14. javascript runtime error invalid argument
  15. javascript runtime error invalid character occurred
  16. ie javascript error invalid character
  17. javascript syntax error invalid character
  18. javascript runtime error invalid template
  19. javascript runtime error invalid character jquery.parsejson
  20. javascript rangeerror invalid array length