1class VocoderEnvelopeProcessor extends AudioWorkletProcessor { 2 constructor() { 3 super(); 4 this.envelope = 0; 5 this.attack = 0.01; // ~0.5ms at 48kHz 6 this.release = 0.02; // ~1ms at 48kHz 7 } 8 9 process(inputs, outputs, parameters) { 10 const input = inputs[0]; 11 const output = outputs[0]; 12 13 if (!input || !input[0]) return true; 14 15 const inputChannel = input[0]; 16 const outputChannel = output[0]; 17 18 for (let i = 0; i < inputChannel.length; i++) { 19 const absValue = Math.abs(inputChannel[i]); 20 21 // Envelope follower with fast attack, slightly slower release 22 if (absValue > this.envelope) { 23 this.envelope += this.attack * (absValue - this.envelope); 24 } else { 25 this.envelope += this.release * (absValue - this.envelope); 26 } 27 28 // Output the envelope value (DC signal that represents amplitude) 29 // Boost it significantly so it drives gain parameters audibly 30 outputChannel[i] = this.envelope * 4.0; 31 } 32 33 return true; 34 } 35} 36 37registerProcessor('vocoder-envelope-processor', VocoderEnvelopeProcessor);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.