OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title> | 4 <title> |
5 Validate Reduction Value of DynamicsComporessor after Disabling | 5 Validate Reduction Value of DynamicsComporessor after Disabling |
6 </title> | 6 </title> |
7 <script src="../../resources/testharness.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
8 <script src="../../resources/testharnessreport.js"></script> | 8 <script src="../../resources/testharnessreport.js"></script> |
9 <script src="../resources/audit-util.js"></script> | 9 <script src="../resources/audit-util.js"></script> |
10 <script src="../resources/audit.js"></script> | 10 <script src="../resources/audit.js"></script> |
11 </head> | 11 </head> |
12 <body> | 12 <body> |
13 <script id="layout-test-code"> | 13 <script id="layout-test-code"> |
14 let audit = Audit.createTaskRunner(); | 14 let audit = Audit.createTaskRunner(); |
15 let context; | 15 let context; |
16 let buffer; | 16 let buffer; |
17 let source; | 17 let source; |
18 let compressor; | 18 let compressor; |
19 | 19 |
20 let sampleRate = 44100; | 20 // Use a low sample rate to reduce complexity because we need to run for |
21 let testDurationSamples = 44100; | 21 // quite a few seconds to get the reduction to converge. |
| 22 let sampleRate = 8192; |
| 23 let testDurationSamples = 10 * 8192; |
22 | 24 |
23 audit.define( | 25 audit.define( |
24 { | 26 { |
25 label: 'test', | 27 label: 'test', |
26 description: | 28 description: |
27 'Validate Reduction Value of DynamicsCompressor after Disabling' | 29 'Validate Reduction Value of DynamicsCompressor after Disabling' |
28 }, | 30 }, |
29 function(task, should) { | 31 function(task, should) { |
30 // Create the offline context for the test. | 32 // Create the offline context for the test. |
31 context = | 33 context = |
32 new OfflineAudioContext(1, testDurationSamples, sampleRate); | 34 new OfflineAudioContext(1, testDurationSamples, sampleRate); |
33 | 35 |
34 // Create the constant sample buffer of 0.5 sec. | 36 // Create the constant sample buffer of 0.5 sec. |
35 buffer = createConstantBuffer(context, testDurationSamples / 2, 1); | 37 buffer = createConstantBuffer(context, testDurationSamples / 2, 1); |
36 | 38 |
37 // Create compressor and use default parameters for the compression. | 39 // Create compressor and use default parameters for the compression. |
38 compressor = context.createDynamicsCompressor(); | 40 compressor = context.createDynamicsCompressor(); |
39 | 41 |
40 // Create the source and connect it to the destination | 42 // Create the source and connect it to the destination |
41 source = context.createBufferSource(); | 43 source = context.createBufferSource(); |
42 source.buffer = buffer; | 44 source.buffer = buffer; |
43 source.connect(compressor); | 45 source.connect(compressor); |
44 compressor.connect(context.destination); | 46 compressor.connect(context.destination); |
45 source.start(0.0); | 47 source.start(0.0); |
46 | 48 |
47 // Render it! | 49 // Render it! |
48 context.startRendering().then(() => { | 50 context.startRendering().then(() => { |
49 // Check that the reduction value is 0.0. | 51 // Check that the reduction value sufficiently close to 0. |
50 should(compressor.reduction, 'compressor.reduction').beEqualTo(0); | 52 // Threshold experimentally determined. |
| 53 should( |
| 54 Math.abs(compressor.reduction), |
| 55 'Math.abs(compressor.reduction)') |
| 56 .beLessThanOrEqualTo(4.8223e-2); |
51 task.done(); | 57 task.done(); |
52 }); | 58 }); |
53 }); | 59 }); |
54 | 60 |
55 audit.run(); | 61 audit.run(); |
56 </script> | 62 </script> |
57 </body> | 63 </body> |
58 </html> | 64 </html> |
OLD | NEW |