Optimize transferer node
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -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
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user