Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / resources / scriptprocessornode-testing.js
bloba94c6e959815169a88cf5b0588f877a7583d9be6
1 // For the current implementation of JavaScriptAudioNode, when it works with OfflineAudioContext (which runs much faster
2 // than real-time) the event.inputBuffer might be overwrite again before onaudioprocess ever get chance to be called.
3 // We carefully arrange the renderLengthInFrames and bufferSize to have exactly the same value to avoid this issue.
4 var renderLengthInFrames = 512;
5 var bufferSize = 512;
7 var context;
9 function createBuffer(context, numberOfChannels, length) {
10 var audioBuffer = context.createBuffer(numberOfChannels, length, sampleRate);
12 fillData(audioBuffer, numberOfChannels, audioBuffer.length);
13 return audioBuffer;
16 function processAudioData(event) {
17 buffer = event.outputBuffer;
18 if (buffer.numberOfChannels != outputChannels)
19 testFailed("numberOfOutputChannels doesn't match!");
21 if (buffer.length != bufferSize)
22 testFailed("length of buffer doesn't match!");
24 buffer = event.inputBuffer;
26 var success = checkStereoOnlyData(buffer, inputChannels, buffer.length);
28 if (success) {
29 testPassed("onaudioprocess was called with correct input data.");
30 } else {
31 testFailed("onaudioprocess was called with wrong input data.");
35 function fillData(buffer, numberOfChannels, length) {
36 for (var i = 0; i < numberOfChannels; ++i) {
37 var data = buffer.getChannelData(i);
39 for (var j = 0; j < length; ++j)
40 if (i < 2)
41 data[j] = i * 2 - 1;
42 else
43 data[j] = 0;
47 // Both 2 to 8 upmix and 8 to 2 downmix are just directly copy the first two channels and left channels are zeroed.
48 function checkStereoOnlyData(buffer, numberOfChannels, length) {
49 for (var i = 0; i < numberOfChannels; ++i) {
50 var data = buffer.getChannelData(i);
52 for (var j = 0; j < length; ++j) {
53 if (i < 2) {
54 if (data[j] != i * 2 - 1)
55 return false;
56 } else {
57 if (data[j] != 0)
58 return false;
62 return true;
65 function runJSNodeTest()
67 // Create offline audio context.
68 context = new OfflineAudioContext(2, renderLengthInFrames, sampleRate);
70 var sourceBuffer = createBuffer(context, sourceChannels, renderLengthInFrames);
72 var bufferSource = context.createBufferSource();
73 bufferSource.buffer = sourceBuffer;
75 var scriptNode = context.createScriptProcessor(bufferSize, inputChannels, outputChannels);
77 bufferSource.connect(scriptNode);
78 scriptNode.connect(context.destination);
79 scriptNode.onaudioprocess = processAudioData;
81 bufferSource.start(0);
82 context.oncomplete = finishJSTest;
83 context.startRendering();