OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 | 3 |
4 <head> | 4 <head> |
5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
7 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
8 <script src="../resources/audit.js"></script> | 8 <script src="../resources/audit.js"></script> |
9 </head> | 9 </head> |
10 | 10 |
11 <body> | 11 <body> |
12 <script> | 12 <script> |
13 | 13 |
14 // Sample rate should be power of 128 to observe the change of AudioParam at | 14 // Sample rate should be power of 128 to observe the change of AudioParam at |
15 // the beginning of rendering quantum. (playbackRate is k-rate) This is the | 15 // the beginning of rendering quantum. (playbackRate is k-rate) This is the |
16 // minimum sample rate in the valid sample rate range. | 16 // minimum sample rate in the valid sample rate range. |
17 var sampleRate = 4096; | 17 let sampleRate = 4096; |
18 | 18 |
19 // The render duration in seconds, and the length in samples. | 19 // The render duration in seconds, and the length in samples. |
20 var renderDuration = 1.0; | 20 let renderDuration = 1.0; |
21 var renderLength = renderDuration * sampleRate; | 21 let renderLength = renderDuration * sampleRate; |
22 | 22 |
23 var context = new OfflineAudioContext(1, renderLength, sampleRate); | 23 let context = new OfflineAudioContext(1, renderLength, sampleRate); |
24 var audit = Audit.createTaskRunner(); | 24 let audit = Audit.createTaskRunner(); |
25 | 25 |
26 | 26 |
27 // Task: Render the actual buffer and compare with the reference. | 27 // Task: Render the actual buffer and compare with the reference. |
28 audit.define('synthesize-verify', (task, should) => { | 28 audit.define('synthesize-verify', (task, should) => { |
29 var ramp = context.createBufferSource(); | 29 let ramp = context.createBufferSource(); |
30 var rampBuffer = createLinearRampBuffer(context, renderLength); | 30 let rampBuffer = createLinearRampBuffer(context, renderLength); |
31 ramp.buffer = rampBuffer; | 31 ramp.buffer = rampBuffer; |
32 | 32 |
33 ramp.connect(context.destination); | 33 ramp.connect(context.destination); |
34 ramp.start(); | 34 ramp.start(); |
35 | 35 |
36 // Leave the playbackRate as 1 for the first half, then change it | 36 // Leave the playbackRate as 1 for the first half, then change it |
37 // to zero at the exact half. The zero playback rate should hold the | 37 // to zero at the exact half. The zero playback rate should hold the |
38 // sample value of the buffer index at the moment. (sample-and-hold) | 38 // sample value of the buffer index at the moment. (sample-and-hold) |
39 ramp.playbackRate.setValueAtTime(1.0, 0.0); | 39 ramp.playbackRate.setValueAtTime(1.0, 0.0); |
40 ramp.playbackRate.setValueAtTime(0.0, renderDuration / 2); | 40 ramp.playbackRate.setValueAtTime(0.0, renderDuration / 2); |
41 | 41 |
42 context.startRendering().then(function (renderedBuffer) { | 42 context.startRendering().then(function (renderedBuffer) { |
43 var data = renderedBuffer.getChannelData(0); | 43 let data = renderedBuffer.getChannelData(0); |
44 var rampData = rampBuffer.getChannelData(0); | 44 let rampData = rampBuffer.getChannelData(0); |
45 var half = rampData.length / 2; | 45 let half = rampData.length / 2; |
46 var passed = true; | 46 let passed = true; |
| 47 let i; |
47 | 48 |
48 for (var i = 1; i < rampData.length; i++) { | 49 for (i = 1; i < rampData.length; i++) { |
49 if (i < half) { | 50 if (i < half) { |
50 // Before the half position, the actual should match with the | 51 // Before the half position, the actual should match with the |
51 // original ramp data. | 52 // original ramp data. |
52 if (data[i] !== rampData[i]) { | 53 if (data[i] !== rampData[i]) { |
53 passed = false; | 54 passed = false; |
54 break; | 55 break; |
55 } | 56 } |
56 } else { | 57 } else { |
57 // From the half position, the actual value should not change. | 58 // From the half position, the actual value should not change. |
58 if (data[i] !== rampData[half]) { | 59 if (data[i] !== rampData[half]) { |
59 passed = false; | 60 passed = false; |
60 break; | 61 break; |
61 } | 62 } |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 should(passed, 'The zero playbackRate') | 66 should(passed, 'The zero playbackRate') |
66 .message( | 67 .message( |
67 'held the sample value correctly', | 68 'held the sample value correctly', |
68 'should hold the sample value. ' + 'Expected ' + rampData[half] + | 69 'should hold the sample value. ' + 'Expected ' + rampData[half] + |
69 ' but got ' + data[i] + ' at the index ' + i); | 70 ' but got ' + data[i] + ' at the index ' + i); |
70 }).then(() => task.done()); | 71 }).then(() => task.done()); |
71 }); | 72 }); |
72 | 73 |
73 audit.run(); | 74 audit.run(); |
74 </script> | 75 </script> |
75 </body> | 76 </body> |
76 | 77 |
77 </html> | 78 </html> |
OLD | NEW |