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

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

Issue 2718563004: Convert more ScriptProcessorNode tests to testharness (Closed)
Patch Set: Move checkResult body to test 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
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..cf8579641441c573986c8b8fcf0d2efe961829bb
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/scriptprocessornode-testing-audit.js
@@ -0,0 +1,84 @@
+// For the current implementation of JavaScriptAudioNode, when it works with OfflineAudioContext (which runs much faster
hongchan 2017/02/27 18:16:12 This file is newly created. Perhaps apply clang-fo
Raymond Toy 2017/02/27 19:07:34 Done, and also changed var to let.
+// 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.
+var renderLengthInFrames = 512;
+var bufferSize = 512;
+
+var context;
+
+function createBuffer(context, numberOfChannels, length) {
+ var 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;
+
+ var success = checkStereoOnlyData(buffer, inputChannels, buffer.length);
+
+ should(success, "onaudioprocess was called with the correct input data")
+ .beTrue();
+}
+
+function fillData(buffer, numberOfChannels, length) {
+ for (var i = 0; i < numberOfChannels; ++i) {
+ var data = buffer.getChannelData(i);
+
+ for (var 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 (var i = 0; i < numberOfChannels; ++i) {
+ var data = buffer.getChannelData(i);
+
+ for (var 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);
+
+ var sourceBuffer = createBuffer(context, sourceChannels, renderLengthInFrames);
+
+ var bufferSource = context.createBufferSource();
+ bufferSource.buffer = sourceBuffer;
+
+ var 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();
+}

Powered by Google App Engine
This is Rietveld 408576698