Optimize transferer node

This commit is contained in:
msqr1
2024-09-29 15:35:19 -07:00
parent 62b742cdf7
commit b440373845
3 changed files with 13 additions and 12 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+11 -10
View File
@@ -48,17 +48,18 @@ let processorURL = URL.createObjectURL(new Blob(['(', (() => {
registerProcessor('VoskletTransferer', class extends AudioWorkletProcessor { registerProcessor('VoskletTransferer', class extends AudioWorkletProcessor {
constructor(opts) { constructor(opts) {
super(); super();
this.count = 0; this.filledSize = 0;
this.maxCount = opts.processorOptions.maxCount; this.bufferSize = opts.processorOptions;
this.buffer = new Float32Array(this.maxCount * 128); this.buffer = new Float32Array(this.bufferSize);
} }
process(inputs) { process(inputs) {
if(!inputs[0][0]) return true; if(inputs[0][0]) {
this.buffer.set(inputs[0][0], this.count++ * 128); this.buffer.set(inputs[0][0], this.filledSize += 128);
if(this.count >= this.maxCount) { if(this.filledSize >= this.bufferSize) {
this.count = 0; this.filledSize = 0;
this.port.postMessage(this.buffer, [this.buffer.buffer]); this.port.postMessage(this.buffer, [this.buffer.buffer]);
this.buffer = new Float32Array(this.maxCount * 128); this.buffer = new Float32Array(this.bufferSize);
}
} }
return true; return true;
} }
@@ -161,7 +162,7 @@ Module = {
numberOfInputs: 1, numberOfInputs: 1,
numberOfOutputs: 0, numberOfOutputs: 0,
channelCount: 1, channelCount: 1,
processorOptions: { maxCount: bufferSize / 128 } processorOptions: bufferSize
}); });
}, },