chore: archive recoverable gateway source baseline
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import {Resampler} from './audio-core.js';
|
||||
import {PlaybackBuffer} from './playback-core.js';
|
||||
class Playback extends AudioWorkletProcessor {
|
||||
constructor(){
|
||||
super();this.first=false;this.voiced=false;this.blocks=0;this.resampler=new Resampler(48000,sampleRate);
|
||||
this.queue=new PlaybackBuffer(sampleRate,event=>this.port.postMessage({...event,contextTime:currentTime}));
|
||||
this.port.onmessage=({data})=>{
|
||||
if(data.type==='clear'){if(data.mode)this.queue.configure(data.mode);this.queue.clear(data.turn);this.first=false;this.voiced=false;this.blocks=0;this.resampler=new Resampler(48000,sampleRate);this.port.postMessage({type:'cleared',turn:data.turn,contextTime:currentTime});}
|
||||
if(data.type==='end')this.queue.end(data.turn);
|
||||
if(data.type==='pcm'&&data.turn===this.queue.turn)this.queue.push(data.turn,this.resampler.push(data.pcm),currentTime*1000);
|
||||
};
|
||||
}
|
||||
process(inputs,outputs){
|
||||
const out=outputs[0][0],used=this.queue.render(out,currentTime*1000)||0;
|
||||
if(used&&!this.first){this.first=true;this.port.postMessage({type:'rendered',turn:this.queue.turn,contextTime:currentTime});}
|
||||
if(!this.voiced){for(let i=0;i<used;i++)if(Math.abs(out[i])>.01){this.voiced=true;this.port.postMessage({type:'voiced',turn:this.queue.turn,contextTime:currentTime+i/sampleRate});break;}}
|
||||
if(++this.blocks%32===0&&!this.queue.done)this.port.postMessage({type:'playback.metrics',turn:this.queue.turn,values:this.queue.snapshot()});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
registerProcessor('playback',Playback);
|
||||
Reference in New Issue
Block a user