samedi 1 avril 2017

Audio web : offline peak detector?

Working with audio web API, I am looking for a way to program a simple offline chain applying 3 effects on top of a wav file. My problem is that I am looking for precisely control the peak level between each effect. Means I need to build a node to get the peak level of the entire track, followed by a gainNode to correct it the the desired value. I also need this peak level value at the end if I want to accurately control the limiter overflow.

The only way I found so far was what I found in this post : Is there a way get something like decibel levels from an audio file and transform that information into a json array?

my code is:

var total=0;
analyser=offContext.creatScriptProcessor(512);
analyser.onaudioprocess = (function(){
    return function(evt){
        var input=evt.inputBuffer.getChannelData(0);
        var ln=input.length;
        for(var i=0;i<ln;i++){
            total+=input[i]*input[i];
        }
        var rms=Math.sqrt(total/ln*.5);
        var peak=20*Math.log10(rms);
    }:
}());

One of the problems that I have is very different values depending on the buffer size I set (512 here). Also if I reinject the opposite of this peak variable in a following gainNode, I should have 0 at the output - which is not the case. Either these formulas are bad, or the process is not sequential as expected: is this value only known once we fire the start() function? Is it really available (fully resolved) for the next node in Offline mode? If not it means I have to run several complete phases with one dedicated to the volume control between them so I can use this value for the next effect.

I though some peak detector would have been developed already, for auto-limiter for instance.

I would really appreciate any tip to move forward, I am stuck with this since a few days now :(

Many thanks.




Aucun commentaire:

Enregistrer un commentaire