Variable PCM_CAPTURE_PROCESSOR_SOURCEConst
PCM_CAPTURE_PROCESSOR_SOURCE: "\nclass HiyvePcmCaptureProcessor extends AudioWorkletProcessor {\n constructor(options) {\n super();\n const opts = (options && options.processorOptions) || {};\n const requested = (opts.chunkFrames | 0) || 4096;\n this.chunkFrames = Math.max(128, Math.ceil(requested / 128) * 128);\n this.buffers = null;\n this.filled = 0;\n this.chunkStartFrame = 0;\n this.stopped = false;\n this.port.onmessage = (event) => {\n if (event.data && event.data.type === 'stop') {\n this.flush();\n this.stopped = true;\n this.port.postMessage({ type: 'flushed' });\n }\n };\n }\n\n ensureBuffers(channelCount) {\n if (!this.buffers || this.buffers.length !== channelCount) {\n this.buffers = [];\n for (let c = 0; c < channelCount; c += 1) {\n this.buffers.push(new Float32Array(this.chunkFrames));\n }\n this.filled = 0;\n }\n }\n\n flush() {\n if (!this.buffers || this.filled === 0) return;\n const channels = this.buffers.map((buffer) => buffer.slice(0, this.filled));\n this.port.postMessage(\n { type: 'chunk', frame: this.chunkStartFrame, channels },\n channels.map((channel) => channel.buffer),\n );\n this.filled = 0;\n }\n\n process(inputs) {\n if (this.stopped) return false;\n const input = inputs[0];\n if (!input || input.length === 0 || !input[0] || input[0].length === 0) return true;\n this.ensureBuffers(input.length);\n const frames = input[0].length;\n if (this.filled + frames > this.chunkFrames) this.flush();\n if (this.filled === 0) this.chunkStartFrame = currentFrame;\n for (let c = 0; c < input.length; c += 1) {\n this.buffers[c].set(input[c], this.filled);\n }\n this.filled += frames;\n if (this.filled >= this.chunkFrames) this.flush();\n return true;\n }\n}\n\nregisterProcessor('hiyve-pcm-capture', HiyvePcmCaptureProcessor);\n" = ...
Source of the AudioWorklet processor, as a string.
It is a string rather than a module so a library build can register it without knowing where its own files are served from: the main thread wraps it in a Blob URL and passes that to
audioWorklet.addModule(). The processor only copies input samples into a buffer and posts whole chunks — no analysis happens on the audio thread.