OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
| 3 <head> |
| 4 <title> |
| 5 oscillator-late-start.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 let audit = Audit.createTaskRunner(); |
3 | 15 |
4 <head> | 16 let sampleRate = 44100; |
5 <script src="../../resources/testharness.js"></script> | 17 let renderLength = 1; |
6 <script src="../../resources/testharnessreport.js"></script> | |
7 <script src="../resources/audit-util.js"></script> | |
8 <script src="../resources/audit.js"></script> | |
9 </head> | |
10 | 18 |
11 <body> | 19 let context; |
12 <script> | 20 let node; |
13 let audit = Audit.createTaskRunner(); | |
14 | 21 |
15 let sampleRate = 44100; | 22 // Test the oscillator node is rendered correctly when the start time of |
16 let renderLength = 1; | 23 // start() call is in the past in terms of the context time. |
| 24 audit.define('initialize', (task, should) => { |
| 25 should( |
| 26 () => context = new OfflineAudioContext( |
| 27 1, sampleRate * renderLength, sampleRate), |
| 28 'Creating offline context for testing') |
| 29 .notThrow(); |
| 30 should(() => { |
| 31 // Set up a dummy signal path to keep the audio context running and |
| 32 // spend processing time before calling start(0). |
| 33 let osc = context.createOscillator(); |
| 34 let silent = context.createGain(); |
17 | 35 |
18 let context; | 36 osc.connect(silent); |
19 let node; | 37 silent.connect(context.destination); |
| 38 silent.gain.setValueAtTime(0.0, 0); |
| 39 osc.start(); |
20 | 40 |
21 // Test the oscillator node is rendered correctly when the start time of | 41 node = context.createOscillator(); |
22 // start() call is in the past in terms of the context time. | 42 node.connect(context.destination); |
23 audit.define('initialize', (task, should) => { | 43 }, 'Creating graph for testing').notThrow(); |
24 should( | 44 task.done(); |
25 () => context = | |
26 new OfflineAudioContext(1, sampleRate * renderLength, sampleRate), | |
27 'Creating offline context for testing') | |
28 .notThrow(); | |
29 should(() => { | |
30 // Set up a dummy signal path to keep the audio context running and | |
31 // spend processing time before calling start(0). | |
32 let osc = context.createOscillator(); | |
33 let silent = context.createGain(); | |
34 | |
35 osc.connect(silent); | |
36 silent.connect(context.destination); | |
37 silent.gain.setValueAtTime(0.0, 0); | |
38 osc.start(); | |
39 | |
40 node = context.createOscillator(); | |
41 node.connect(context.destination); | |
42 }, 'Creating graph for testing').notThrow(); | |
43 task.done(); | |
44 }); | |
45 | |
46 audit.define('test-late-start', (task, should) => { | |
47 // The node's start time will be clamped to the render quantum boundary | |
48 // >0.1 sec. Thus the rendered buffer will have non-zero frames. | |
49 // See issue: crbug.com/462167 | |
50 let suspendTime = 0.1; | |
51 let suspendFrame = 128 * Math.floor(0.1 * context.sampleRate / 128); | |
52 | |
53 context.suspend(suspendTime).then(() => { | |
54 node.start(0); | |
55 context.resume(); | |
56 }); | 45 }); |
57 | 46 |
58 // Start rendering and verify result: this verifies if 1) the rendered | 47 audit.define('test-late-start', (task, should) => { |
59 // buffer contains at least one non-zero value and 2) the non-zero value | 48 // The node's start time will be clamped to the render quantum boundary |
60 // is found later than the first output sample. | 49 // >0.1 sec. Thus the rendered buffer will have non-zero frames. |
61 context.startRendering() | 50 // See issue: crbug.com/462167 |
62 .then(buffer => { | 51 let suspendTime = 0.1; |
63 let channelData = buffer.getChannelData(0); | 52 let suspendFrame = 128 * Math.floor(0.1 * context.sampleRate / 128); |
64 let nonZeroValueIndex = channelData.findIndex(x => x != 0); | |
65 | 53 |
66 should( | 54 context.suspend(suspendTime).then(() => { |
67 nonZeroValueIndex, | 55 node.start(0); |
68 'The index (' + nonZeroValueIndex + | 56 context.resume(); |
69 ') of first non-zero output value') | 57 }); |
70 .beGreaterThanOrEqualTo(suspendFrame); | |
71 | 58 |
72 should( | 59 // Start rendering and verify result: this verifies if 1) the rendered |
73 channelData.slice(0, suspendFrame), | 60 // buffer contains at least one non-zero value and 2) the non-zero value |
74 'Output[0:' + (suspendFrame - 1) + ']') | 61 // is found later than the first output sample. |
75 .beConstantValueOf(0); | 62 context.startRendering() |
76 }) | 63 .then(buffer => { |
77 .then(() => task.done()); | 64 let channelData = buffer.getChannelData(0); |
78 ; | 65 let nonZeroValueIndex = channelData.findIndex(x => x != 0); |
79 }); | |
80 | 66 |
81 audit.run(); | 67 should( |
82 </script> | 68 nonZeroValueIndex, |
83 </body> | 69 'The index (' + nonZeroValueIndex + |
| 70 ') of first non-zero output value') |
| 71 .beGreaterThanOrEqualTo(suspendFrame); |
84 | 72 |
| 73 should( |
| 74 channelData.slice(0, suspendFrame), |
| 75 'Output[0:' + (suspendFrame - 1) + ']') |
| 76 .beConstantValueOf(0); |
| 77 }) |
| 78 .then(() => task.done()); |
| 79 ; |
| 80 }); |
| 81 |
| 82 audit.run(); |
| 83 </script> |
| 84 </body> |
85 </html> | 85 </html> |
OLD | NEW |