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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/audiobuffersource-playbackrate-zero.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
4 <head>
5 <script src="../resources/js-test.js"></script>
6 <script src="resources/compatibility.js"></script>
7 <script src="resources/audit-util.js"></script>
8 <script src="resources/audio-testing.js"></script>
9 </head>
10
11 <body>
12 <script>
13 description('AudioBufferSourceNode: test the "zero" playbackRate.');
14 window.jsTestIsAsync = true;
15
16 // Sample rate should be power of 128 to observe the change of AudioParam at
17 // the beginning of rendering quantum. (playbackRate is k-rate) This is the
18 // minimum sample rate in the valid sample rate range.
19 var sampleRate = 4096;
20
21 // The render duration in seconds, and the length in samples.
22 var renderDuration = 1.0;
23 var renderLength = renderDuration * sampleRate;
24
25 var context = new OfflineAudioContext(1, renderLength, sampleRate);
26 var audit = Audit.createTaskRunner();
27
28
29 // Task: Render the actual buffer and compare with the reference.
30 audit.defineTask('synthesize-verify', function (done) {
31 var ramp = context.createBufferSource();
32 var rampBuffer = createLinearRampBuffer(context, renderLength);
33 ramp.buffer = rampBuffer;
34
35 ramp.connect(context.destination);
36 ramp.start();
37
38 // Leave the playbackRate as 1 for the first half, then change it
39 // to zero at the exact half. The zero playback rate should hold the
40 // sample value of the buffer index at the moment. (sample-and-hold)
41 ramp.playbackRate.setValueAtTime(1.0, 0.0);
42 ramp.playbackRate.setValueAtTime(0.0, renderDuration / 2);
43
44 context.startRendering().then(function (renderedBuffer) {
45 var data = renderedBuffer.getChannelData(0);
46 var rampData = rampBuffer.getChannelData(0);
47 var half = rampData.length / 2;
48 var passed = true;
49
50 for (var i = 1; i < rampData.length; i++) {
51 if (i < half) {
52 // Before the half position, the actual should match with the
53 // original ramp data.
54 if (data[i] !== rampData[i]) {
55 passed = false;
56 break;
57 }
58 } else {
59 // From the half position, the actual value should not change.
60 if (data[i] !== rampData[half]) {
61 passed = false;
62 break;
63 }
64 }
65 }
66
67 if (passed) {
68 testPassed('The zero playbackRate held the sample value correctly.');
69 } else {
70 testFailed('The zero playbackRate should hold the sample value. ' +
71 'Expected ' + rampData[half] + ' but got ' + data[i] + ' at the inde x ' +
72 i + '.');
73 }
74 }).then(done);
75 });
76
77 audit.defineTask('finish', function (done) {
78 finishJSTest();
79 done();
80 });
81
82 audit.runTasks(
83 'synthesize-verify',
84 'finish'
85 );
86
87 successfullyParsed = true;
88 </script>
89 </body>
90
91 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698