OLD | NEW |
(Empty) | |
| 1 'use strict' |
| 2 |
| 3 registerProcessor('bypass', class Bypass extends AudioWorkletProcessor { |
| 4 constructor () { |
| 5 super(); |
| 6 } |
| 7 |
| 8 process (input, output) { |
| 9 let inputChannelData = input.getChannelData(0); |
| 10 let outputChannelData = output.getChannelData(0); |
| 11 outputChannelData.set(inputChannelData); |
| 12 } |
| 13 }); |
| 14 |
| 15 registerProcessor('noise', class Noise extends AudioWorkletProcessor { |
| 16 static get parameterDescriptors () { |
| 17 return [{ |
| 18 name: 'gain', |
| 19 defaultValue: 0.25, |
| 20 minValue: 0, |
| 21 maxValue: 1 |
| 22 }]; |
| 23 } |
| 24 |
| 25 constructor () { |
| 26 super(); |
| 27 } |
| 28 |
| 29 process (input, output, parameters) { |
| 30 let outputChannelData = output.getChannelData(0); |
| 31 let gain = parameters.gain; |
| 32 for (let i = 0; i < 128; ++i) { |
| 33 outputChannelData[i] = Math.random() * gain[i]; |
| 34 } |
| 35 } |
| 36 }); |
| 37 |
| 38 registerProcessor('onepole', class OnePole extends AudioWorkletProcessor { |
| 39 constructor () { |
| 40 super(); |
| 41 this.updateCoefficients_(5000); |
| 42 } |
| 43 |
| 44 updateCoefficients_ (cutoffFrequency) { |
| 45 this.b1 = Math.exp(-2 * Math.PI * cutoffFrequency / 48000); |
| 46 this.a0 = 1.0 - this.b1; |
| 47 this.z1 = 0; |
| 48 } |
| 49 |
| 50 process (input, output) { |
| 51 let inputChannelData = input.getChannelData(0); |
| 52 let outputChannelData = output.getChannelData(0); |
| 53 for (let i = 0; i < 128; ++i) { |
| 54 this.z1 = inputChannelData[i] * this.a0 + this.z1 * this.b1; |
| 55 outputChannelData[i] = this.z1; |
| 56 } |
| 57 } |
| 58 }); |
OLD | NEW |