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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/scriptprocessor-offlineaudiocontext.html

Issue 2581463002: Refactor WebAudio test directory (Closed)
Patch Set: Use correct path for wav result files Created 4 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>ScriptProcessorNode on OfflineAudioContext</title>
5 <script src="../resources/testharness.js"></script>
6 <script src="../resources/testharnessreport.js"></script>
7 <script src="resources/audit-util.js"></script>
8 <script src="resources/audio-testing.js"></script>
9 </head>
10 <body>
11 <script>
12 var audit = Audit.createTaskRunner();
13
14
15 // Fill the output of script processor with a constant value.
16 audit.defineTask('simple-output', function (taskDone) {
17 var sampleRate = 44100;
18 var scriptBufferSize = 256;
19 var renderLength = 1;
20 var PI = Math.fround(Math.PI);
21
22 var context = new OfflineAudioContext(
23 1, renderLength * sampleRate, sampleRate);
24
25 var scriptNode = context.createScriptProcessor(scriptBufferSize, 1, 1);
26 scriptNode.onaudioprocess = function (event) {
27 var outputChannel = event.outputBuffer.getChannelData(0);
28 outputChannel.fill(PI);
29 };
30 scriptNode.connect(context.destination);
31
32 context.startRendering().then(function (buffer) {
33 var channel = buffer.getChannelData(0);
34 var initialDelay = channel.subarray(0, 2 * scriptBufferSize);
35 var actualContent = channel.subarray(2 * scriptBufferSize);
36
37 // There is the initial delay (2 x buffer size) which is silent.
38 Should('The initial delay contains zeros.', initialDelay)
39 .beConstantValueOf(0);
40
41 // After the initial delay, we must get |PI|.
42 Should('The actual content contains ' + PI, actualContent)
43 .beConstantValueOf(PI);
44
45 taskDone();
46 });
47 });
48
49
50 // Pass through an oscillator via a script processor. Sum with the
51 // phase-inverted oscillator with the delayed start time. Verify the
52 // rendered buffer is completely silent.
53 audit.defineTask('oscillator-output', function (taskDone) {
54 var sampleRate = 44100;
55 var scriptBufferSize = 256;
56 var renderLength = 1;
57
58 var context = new OfflineAudioContext(
59 1, renderLength * sampleRate, sampleRate);
60
61 var osc1 = context.createOscillator();
62 var osc2 = context.createOscillator();
63 var inverter = context.createGain();
64 var scriptNode = context.createScriptProcessor(scriptBufferSize, 1, 1);
65 scriptNode.onaudioprocess = function (event) {
66 var inputChannel = event.inputBuffer.getChannelData(0);
67 var outputChannel = event.outputBuffer.getChannelData(0);
68 outputChannel.set(inputChannel);
69 };
70
71 inverter.gain.value = -1;
72
73 osc1.connect(inverter).connect(context.destination);
74 osc2.connect(scriptNode).connect(context.destination);
75
76 // The delayed start for |osc1|.
77 osc1.start((2 * scriptBufferSize) / sampleRate);
78 osc2.start();
79
80 context.startRendering().then(function (buffer) {
81 var channel = buffer.getChannelData(0);
82
83 // The rendered buffer must be silent.
84 Should('The rendered buffer', channel)
85 .beConstantValueOf(0);
86
87 taskDone();
88 });
89 });
90
91
92 audit.runTasks();
93 </script>
94 </body>
95 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698