-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaudiotapprocessor.js
45 lines (35 loc) · 1.16 KB
/
audiotapprocessor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright © 2022 Michael Thornburgh
// SPDX-License-Identifier: MIT
registerProcessor('com_zenomt_AudioTapNodeProcessor', class extends AudioWorkletProcessor {
constructor(options, ...args) {
super(options, ...args);
this._offset = 0;
this._planes = [];
this._bufferTimestamp = 0;
const samplesPerBuffer = Number(options.processorOptions.samplesPerBuffer) || 1024;
this._samplesPerPost = 128 * Math.floor((samplesPerBuffer + 127) / 128);
}
process(inputs, outputs, parameters) {
const input = inputs[0];
const output = outputs[0];
if((!input.length) || (!output.length))
return;
if(0 == this._offset)
this._bufferTimestamp = currentTime;
for(var ch = 0; (ch < input.length) && (ch < output.length); ch++)
{
if(0 == this._offset)
this._planes.push(new Float32Array(this._samplesPerPost));
output[ch].set(input[ch]);
this._planes[ch].set(input[ch], this._offset);
}
this._offset += input[0].length;
if(this._offset >= this._samplesPerPost)
{
this.port.postMessage({command:"samples", currentTime:this._bufferTimestamp, sampleRate, planes:this._planes});
this._offset = 0;
this._planes = [];
}
return true;
}
});