OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
| 3 <head> |
| 4 <title> |
| 5 audiobuffersource-playbackrate-zero.html |
| 6 </title> |
| 7 <script src="../../resources/testharness.js"></script> |
| 8 <script src="../../resources/testharnessreport.js"></script> |
| 9 <script src="../resources/audit-util.js"></script> |
| 10 <script src="../resources/audit.js"></script> |
| 11 </head> |
| 12 <body> |
| 13 <script id="layout-test-code"> |
| 14 // Sample rate should be power of 128 to observe the change of AudioParam |
| 15 // at the beginning of rendering quantum. (playbackRate is k-rate) This is |
| 16 // the minimum sample rate in the valid sample rate range. |
| 17 let sampleRate = 4096; |
3 | 18 |
4 <head> | 19 // The render duration in seconds, and the length in samples. |
5 <script src="../../resources/testharness.js"></script> | 20 let renderDuration = 1.0; |
6 <script src="../../resources/testharnessreport.js"></script> | 21 let renderLength = renderDuration * sampleRate; |
7 <script src="../resources/audit-util.js"></script> | |
8 <script src="../resources/audit.js"></script> | |
9 </head> | |
10 | 22 |
11 <body> | 23 let context = new OfflineAudioContext(1, renderLength, sampleRate); |
12 <script> | 24 let audit = Audit.createTaskRunner(); |
13 | |
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 | |
16 // minimum sample rate in the valid sample rate range. | |
17 let sampleRate = 4096; | |
18 | |
19 // The render duration in seconds, and the length in samples. | |
20 let renderDuration = 1.0; | |
21 let renderLength = renderDuration * sampleRate; | |
22 | |
23 let context = new OfflineAudioContext(1, renderLength, sampleRate); | |
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 let ramp = context.createBufferSource(); | 29 let ramp = context.createBufferSource(); |
30 let 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() |
43 let data = renderedBuffer.getChannelData(0); | 43 .then(function(renderedBuffer) { |
44 let rampData = rampBuffer.getChannelData(0); | 44 let data = renderedBuffer.getChannelData(0); |
45 let half = rampData.length / 2; | 45 let rampData = rampBuffer.getChannelData(0); |
46 let passed = true; | 46 let half = rampData.length / 2; |
47 let i; | 47 let passed = true; |
| 48 let i; |
48 | 49 |
49 for (i = 1; i < rampData.length; i++) { | 50 for (i = 1; i < rampData.length; i++) { |
50 if (i < half) { | 51 if (i < half) { |
51 // Before the half position, the actual should match with the | 52 // Before the half position, the actual should match with the |
52 // original ramp data. | 53 // original ramp data. |
53 if (data[i] !== rampData[i]) { | 54 if (data[i] !== rampData[i]) { |
54 passed = false; | 55 passed = false; |
55 break; | 56 break; |
56 } | 57 } |
57 } else { | 58 } else { |
58 // From the half position, the actual value should not change. | 59 // From the half position, the actual value should not change. |
59 if (data[i] !== rampData[half]) { | 60 if (data[i] !== rampData[half]) { |
60 passed = false; | 61 passed = false; |
61 break; | 62 break; |
62 } | 63 } |
63 } | 64 } |
64 } | 65 } |
65 | 66 |
66 should(passed, 'The zero playbackRate') | 67 should(passed, 'The zero playbackRate') |
67 .message( | 68 .message( |
68 'held the sample value correctly', | 69 'held the sample value correctly', |
69 'should hold the sample value. ' + 'Expected ' + rampData[half] + | 70 'should hold the sample value. ' + |
70 ' but got ' + data[i] + ' at the index ' + i); | 71 'Expected ' + rampData[half] + ' but got ' + data[i] + |
71 }).then(() => task.done()); | 72 ' at the index ' + i); |
72 }); | 73 }) |
| 74 .then(() => task.done()); |
| 75 }); |
73 | 76 |
74 audit.run(); | 77 audit.run(); |
75 </script> | 78 </script> |
76 </body> | 79 </body> |
77 | |
78 </html> | 80 </html> |
OLD | NEW |