Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Unified Diff: third_party/WebKit/LayoutTests/webaudio/audioworklet/processors.js

Issue 2793593002: AudioWorklet prototype
Patch Set: Merge changes, AudioParam bug fix Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/webaudio/audioworklet/processors.js
diff --git a/third_party/WebKit/LayoutTests/webaudio/audioworklet/processors.js b/third_party/WebKit/LayoutTests/webaudio/audioworklet/processors.js
new file mode 100644
index 0000000000000000000000000000000000000000..79128d3857b896b8ea9ed83613327b0ab924a957
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/audioworklet/processors.js
@@ -0,0 +1,58 @@
+'use strict'
+
+registerProcessor('bypass', class Bypass extends AudioWorkletProcessor {
+ constructor () {
+ super();
+ }
+
+ process (input, output) {
+ let inputChannelData = input.getChannelData(0);
+ let outputChannelData = output.getChannelData(0);
+ outputChannelData.set(inputChannelData);
+ }
+});
+
+registerProcessor('noise', class Noise extends AudioWorkletProcessor {
+ static get parameterDescriptors () {
+ return [{
+ name: 'gain',
+ defaultValue: 0.25,
+ minValue: 0,
+ maxValue: 1
+ }];
+ }
+
+ constructor () {
+ super();
+ }
+
+ process (input, output, parameters) {
+ let outputChannelData = output.getChannelData(0);
+ let gain = parameters.gain;
+ for (let i = 0; i < 128; ++i) {
+ outputChannelData[i] = Math.random() * gain[i];
+ }
+ }
+});
+
+registerProcessor('onepole', class OnePole extends AudioWorkletProcessor {
+ constructor () {
+ super();
+ this.updateCoefficients_(5000);
+ }
+
+ updateCoefficients_ (cutoffFrequency) {
+ this.b1 = Math.exp(-2 * Math.PI * cutoffFrequency / 48000);
+ this.a0 = 1.0 - this.b1;
+ this.z1 = 0;
+ }
+
+ process (input, output) {
+ let inputChannelData = input.getChannelData(0);
+ let outputChannelData = output.getChannelData(0);
+ for (let i = 0; i < 128; ++i) {
+ this.z1 = inputChannelData[i] * this.a0 + this.z1 * this.b1;
+ outputChannelData[i] = this.z1;
+ }
+ }
+});

Powered by Google App Engine
This is Rietveld 408576698