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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-loop-grain-no-duration.html

Issue 2783553002: Convert AudioBufferSource tests to new Audit (Closed)
Patch Set: Indent neatly. Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 3
4 <head> 4 <head>
5 <title>Test AudioBufferSourceNode looping without explicit duration</title> 5 <title>Test AudioBufferSourceNode looping without explicit duration</title>
6 <script src="../../resources/testharness.js"></script> 6 <script src="../../resources/testharness.js"></script>
7 <script src="../../resources/testharnessreport.js"></script> 7 <script src="../../resources/testharnessreport.js"></script>
8 <script src="../resources/audit-util.js"></script> 8 <script src="../resources/audit-util.js"></script>
9 <script src="../resources/audio-testing.js"></script> 9 <script src="../resources/audit.js"></script>
10 </head> 10 </head>
11 11
12 <body> 12 <body>
13 <script> 13 <script>
14 14
15 // Reasonably low sample rate for the optimum test speed. 15 // Reasonably low sample rate for the optimum test speed.
16 var sampleRate = 4096; 16 var sampleRate = 4096;
17 17
18 var audit = Audit.createTaskRunner(); 18 var audit = Audit.createTaskRunner();
19 19
20 // Task: create a short linear ramp and enable looping. The test will 20 // Task: create a short linear ramp and enable looping. The test will
21 // verify that the ramp was looped the appropriate number of times. 21 // verify that the ramp was looped the appropriate number of times.
22 audit.defineTask('loop-count', function (done) { 22 audit.define('loop-count', (task, should) => {
23 // How many loops of the source we want to render. Any whole number 23 // How many loops of the source we want to render. Any whole number
24 // greater than 1 will work. 24 // greater than 1 will work.
25 var loopCount = 4; 25 var loopCount = 4;
26 var sourceFrames = 8; 26 var sourceFrames = 8;
27 var renderFrames = sourceFrames * loopCount; 27 var renderFrames = sourceFrames * loopCount;
28 28
29 var context = new OfflineAudioContext(1, renderFrames, sampleRate); 29 var context = new OfflineAudioContext(1, renderFrames, sampleRate);
30 var source = context.createBufferSource(); 30 var source = context.createBufferSource();
31 var linearRampBuffer = createLinearRampBuffer(context, sourceFrames); 31 var linearRampBuffer = createLinearRampBuffer(context, sourceFrames);
32 32
(...skipping 12 matching lines...) Expand all
45 45
46 var actual = renderedBuffer.getChannelData(0); 46 var actual = renderedBuffer.getChannelData(0);
47 var linearRamp = linearRampBuffer.getChannelData(0); 47 var linearRamp = linearRampBuffer.getChannelData(0);
48 48
49 // Manually create a |loopCount| copies of linear ramps. 49 // Manually create a |loopCount| copies of linear ramps.
50 var expected = new Float32Array(linearRamp.length * loopCount); 50 var expected = new Float32Array(linearRamp.length * loopCount);
51 for (var i = 0; i < loopCount; i++) 51 for (var i = 0; i < loopCount; i++)
52 expected.set(linearRamp, linearRamp.length * i); 52 expected.set(linearRamp, linearRamp.length * i);
53 53
54 // The actual output should match the created loop. 54 // The actual output should match the created loop.
55 Should('The output of actual and expected loops', actual) 55 should(actual, 'The output of actual and expected loops')
56 .beEqualToArray(expected); 56 .beEqualToArray(expected);
57 }).then(done); 57 }).then(() => task.done());
58 }); 58 });
59 59
60 // Task: Test that looping an AudioBufferSource works correctly if the 60 // Task: Test that looping an AudioBufferSource works correctly if the
61 // source is started and the buffer is assigned later, but before the source 61 // source is started and the buffer is assigned later, but before the source
62 // would start. 62 // would start.
63 audit.defineTask('delayed-start', function (done) { 63 audit.define('delayed-start', (task, should) => {
64 var renderDuration = 2; 64 var renderDuration = 2;
65 var context = new OfflineAudioContext(2, sampleRate * renderDuration, samp leRate); 65 var context = new OfflineAudioContext(2, sampleRate * renderDuration, samp leRate);
66 var linearRampBuffer = createLinearRampBuffer(context, 128); 66 var linearRampBuffer = createLinearRampBuffer(context, 128);
67 67
68 var normal = context.createBufferSource(); 68 var normal = context.createBufferSource();
69 var delayed = context.createBufferSource(); 69 var delayed = context.createBufferSource();
70 var merger = context.createChannelMerger(2); 70 var merger = context.createChannelMerger(2);
71 71
72 // Connect the normally started source to the left channel, and the 72 // Connect the normally started source to the left channel, and the
73 // delayed to the right channel. 73 // delayed to the right channel.
74 normal.connect(merger, 0, 0); 74 normal.connect(merger, 0, 0);
75 delayed.connect(merger, 0, 1); 75 delayed.connect(merger, 0, 1);
76 merger.connect(context.destination); 76 merger.connect(context.destination);
77 77
78 normal.buffer = linearRampBuffer; 78 normal.buffer = linearRampBuffer;
79 normal.loop = true; 79 normal.loop = true;
80 delayed.loop = true; 80 delayed.loop = true;
81 81
82 normal.start(1, 0); 82 normal.start(1, 0);
83 delayed.start(1, 0); 83 delayed.start(1, 0);
84 84
85 // Assign the buffer to the delayed source node at 0.5 second. 85 // Assign the buffer to the delayed source node at 0.5 second.
86 context.suspend(0.5).then(function () { 86 context.suspend(0.5).then(function () {
87 delayed.buffer = linearRampBuffer; 87 delayed.buffer = linearRampBuffer;
88 context.resume(); 88 context.resume();
89 }); 89 });
90 90
91 context.startRendering().then(function (buffer) { 91 context.startRendering().then(function (buffer) {
92 // The left and right channel must match regardless of the timing 92 // The left and right channel must match regardless of the timing
93 // of buffer assignment. 93 // of buffer assignment.
94 Should('The content of the left and right channel', 94 should(buffer.getChannelData(0),
95 buffer.getChannelData(0)).beEqualToArray(buffer.getChannelData(1)); 95 'The content of the left and right channel')
96 }).then(done); 96 .beEqualToArray(buffer.getChannelData(1));
97 })
98 .then(() => task.done());
97 }); 99 });
98 100
99 audit.defineTask('finish', function (done) { 101 audit.run();
100 done();
101 });
102
103 audit.runTasks(
104 'loop-count',
105 'delayed-start',
106 'finish'
107 );
108
109 successfullyParsed = true;
110 </script> 102 </script>
111 </body> 103 </body>
112 104
113 </html> 105 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698