62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
// Test instrumentation only. Report counts; never record or retain audio.
|
|
class AdaptiveContinuityMeter extends AudioWorkletProcessor {
|
|
frames=0;
|
|
channelSamples=0;
|
|
zeroRun=0;
|
|
maxZeroRun=0;
|
|
shortDropouts=0;
|
|
nearFullScale=0;
|
|
jumps=0;
|
|
maxStep=0;
|
|
last=0;
|
|
nextReport=0;
|
|
audible=false;
|
|
|
|
constructor(){
|
|
super();
|
|
this.port.onmessage=event=>{
|
|
if(event.data!=='start-phase')return;
|
|
this.zeroRun=this.maxZeroRun=0;
|
|
this.port.postMessage({...this.metrics(),phaseStarted:true});
|
|
};
|
|
}
|
|
|
|
metrics(){
|
|
return {sampleRate,frames:this.frames,channelSamples:this.channelSamples,shortDropouts:this.shortDropouts,
|
|
maxZeroRun:this.maxZeroRun,trailingZeroRun:this.zeroRun,nearFullScale:this.nearFullScale,jumps:this.jumps,maxStep:this.maxStep};
|
|
}
|
|
|
|
process([input],[output]) {
|
|
const length=output[0].length;
|
|
for(let i=0;i<length;i++){
|
|
let peak=0;
|
|
for(const channel of input){
|
|
peak=Math.max(peak,Math.abs(channel[i]));
|
|
if(Math.abs(channel[i])>=0.999)this.nearFullScale++;
|
|
this.channelSamples++;
|
|
}
|
|
if(peak<=0.000001)this.zeroRun++;
|
|
if(peak>0.000001){
|
|
if(this.audible){
|
|
this.maxZeroRun=Math.max(this.maxZeroRun,this.zeroRun);
|
|
if(this.zeroRun>=sampleRate*0.00075&&this.zeroRun<=sampleRate*0.08)this.shortDropouts++;
|
|
}
|
|
this.zeroRun=0;
|
|
this.audible=true;
|
|
}
|
|
const sample=input[0]?.[i]??0;
|
|
const step=Math.abs(this.last-sample);
|
|
this.maxStep=Math.max(this.maxStep,step);
|
|
if(step>0.35)this.jumps++;
|
|
this.last=sample;
|
|
}
|
|
this.frames+=length;
|
|
if(currentFrame>=this.nextReport){
|
|
this.nextReport=currentFrame+sampleRate;
|
|
this.port.postMessage(this.metrics());
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
registerProcessor('adaptive-continuity-meter',AdaptiveContinuityMeter);
|