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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/resources/scriptprocessornode-testing-audit.js

Issue 2718563004: Convert more ScriptProcessorNode tests to testharness (Closed)
Patch Set: Address review comments. Created 3 years, 10 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
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/ScriptProcessor/scriptprocessornode-zero-input-channels-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/webaudio/resources/scriptprocessornode-testing-audit.js
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/scriptprocessornode-testing-audit.js b/third_party/WebKit/LayoutTests/webaudio/resources/scriptprocessornode-testing-audit.js
new file mode 100644
index 0000000000000000000000000000000000000000..271fd6d9109c08b50fdccb0e5c6a966e7802d018
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/scriptprocessornode-testing-audit.js
@@ -0,0 +1,85 @@
+// For the current implementation of JavaScriptAudioNode, when it works with
+// OfflineAudioContext (which runs much faster than real-time) the
+// event.inputBuffer might be overwrite again before onaudioprocess ever get
+// chance to be called. We carefully arrange the renderLengthInFrames and
+// bufferSize to have exactly the same value to avoid this issue.
+let renderLengthInFrames = 512;
+let bufferSize = 512;
+
+let context;
+
+function createBuffer(context, numberOfChannels, length) {
+ let audioBuffer = context.createBuffer(numberOfChannels, length, sampleRate);
+
+ fillData(audioBuffer, numberOfChannels, audioBuffer.length);
+ return audioBuffer;
+}
+
+function processAudioData(event, should) {
+ buffer = event.outputBuffer;
+
+ should(buffer.numberOfChannels, 'Number of channels in output buffer')
+ .beEqualTo(outputChannels);
+ should(buffer.length, 'Length of output buffer').beEqualTo(bufferSize);
+
+ buffer = event.inputBuffer;
+
+ let success = checkStereoOnlyData(buffer, inputChannels, buffer.length);
+
+ should(success, 'onaudioprocess was called with the correct input data')
+ .beTrue();
+}
+
+function fillData(buffer, numberOfChannels, length) {
+ for (let i = 0; i < numberOfChannels; ++i) {
+ let data = buffer.getChannelData(i);
+
+ for (let j = 0; j < length; ++j)
+ if (i < 2)
+ data[j] = i * 2 - 1;
+ else
+ data[j] = 0;
+ }
+}
+
+// Both 2 to 8 upmix and 8 to 2 downmix are just directly copy the first two
+// channels and left channels are zeroed.
+function checkStereoOnlyData(buffer, numberOfChannels, length) {
+ for (let i = 0; i < numberOfChannels; ++i) {
+ let data = buffer.getChannelData(i);
+
+ for (let j = 0; j < length; ++j) {
+ if (i < 2) {
+ if (data[j] != i * 2 - 1)
+ return false;
+ } else {
+ if (data[j] != 0)
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+function runJSNodeTest(should) {
+ // Create offline audio context.
+ context = new OfflineAudioContext(2, renderLengthInFrames, sampleRate);
+
+ let sourceBuffer =
+ createBuffer(context, sourceChannels, renderLengthInFrames);
+
+ let bufferSource = context.createBufferSource();
+ bufferSource.buffer = sourceBuffer;
+
+ let scriptNode =
+ context.createScriptProcessor(bufferSize, inputChannels, outputChannels);
+
+ bufferSource.connect(scriptNode);
+ scriptNode.connect(context.destination);
+ scriptNode.onaudioprocess = event => {
+ processAudioData(event, should);
+ };
+
+ bufferSource.start(0);
+ return context.startRendering();
+}
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/ScriptProcessor/scriptprocessornode-zero-input-channels-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698