| OLD | NEW |
| 1 <!DOCTYPE HTML> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title> |
| 5 dynamicscompressor-simple.html |
| 6 </title> |
| 4 <script src="../../resources/testharness.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | 8 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 9 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audit.js"></script> | 10 <script src="../resources/audit.js"></script> |
| 8 </head> | 11 </head> |
| 9 | |
| 10 <body> | 12 <body> |
| 11 <script> | 13 <script id="layout-test-code"> |
| 12 var audit = Audit.createTaskRunner(); | 14 let audit = Audit.createTaskRunner(); |
| 13 var context; | 15 let context; |
| 14 var compressor; | 16 let compressor; |
| 15 var sampleRate = 44100; | 17 let sampleRate = 44100; |
| 16 var lengthInSeconds = 1; | 18 let lengthInSeconds = 1; |
| 17 var renderedData; | 19 let renderedData; |
| 18 // This threshold experimentally determined. It depends on the the gain va
lue of the gain node | 20 // This threshold experimentally determined. It depends on the the gain |
| 19 // below and the dynamics compressor. When the DynamicsCompressor had the
pre-emphasis | 21 // value of the gain node below and the dynamics compressor. When the |
| 20 // filters, the peak value is about 0.21. Without it, the peak is about 0
.84. | 22 // DynamicsCompressor had the pre-emphasis filters, the peak value is |
| 21 var peakThreshold = 0.83; | 23 // about 0.21. Without it, the peak is about 0.84. |
| 24 let peakThreshold = 0.83; |
| 22 | 25 |
| 23 function checkResult(renderedBuffer, should) { | 26 function checkResult(renderedBuffer, should) { |
| 24 renderedData = renderedBuffer.getChannelData(0); | 27 renderedData = renderedBuffer.getChannelData(0); |
| 25 // Search for a peak in the last part of the data. | 28 // Search for a peak in the last part of the data. |
| 26 var startSample = sampleRate * (lengthInSeconds - .1); | 29 let startSample = sampleRate * (lengthInSeconds - .1); |
| 27 var endSample = renderedData.length; | 30 let endSample = renderedData.length; |
| 28 var k; | 31 let k; |
| 29 var peak = -1; | 32 let peak = -1; |
| 30 | 33 |
| 31 for (k = startSample; k < endSample; ++k) { | 34 for (k = startSample; k < endSample; ++k) { |
| 32 var sample = Math.abs(renderedData[k]); | 35 let sample = Math.abs(renderedData[k]); |
| 33 if (peak < sample) | 36 if (peak < sample) |
| 34 peak = sample; | 37 peak = sample; |
| 35 } | 38 } |
| 36 | 39 |
| 37 should(peak >= peakThreshold, "Pre-emphasis effect not applied") | 40 should(peak >= peakThreshold, 'Pre-emphasis effect not applied') |
| 38 .beTrue(); | 41 .beTrue(); |
| 39 | 42 |
| 40 should(compressor.reduction !== 0, | 43 should(compressor.reduction !== 0, 'Reduction value changed').beTrue(); |
| 41 "Reduction value changed") | |
| 42 .beTrue(); | |
| 43 } | 44 } |
| 44 | 45 |
| 45 audit.define({ | 46 audit.define( |
| 46 label: "test", | 47 { |
| 47 description: "Test pre-emphasis in DynamicsCompressor is removed" | 48 label: 'test', |
| 48 }, function (task, should) { | 49 description: 'Test pre-emphasis in DynamicsCompressor is removed' |
| 50 }, |
| 51 function(task, should) { |
| 49 | 52 |
| 50 context = new OfflineAudioContext(1, sampleRate * lengthInSeconds, sampl
eRate); | 53 context = new OfflineAudioContext( |
| 51 // Connect an oscillator to a gain node to the compressor. The | 54 1, sampleRate * lengthInSeconds, sampleRate); |
| 52 // oscillator frequency is set to a high value for the (original) | 55 // Connect an oscillator to a gain node to the compressor. The |
| 53 // emphasis to kick in. The gain is a little extra boost to get the | 56 // oscillator frequency is set to a high value for the (original) |
| 54 // compressor enabled. | 57 // emphasis to kick in. The gain is a little extra boost to get the |
| 55 // | 58 // compressor enabled. |
| 56 var osc = context.createOscillator(); | 59 // |
| 57 osc.frequency.value = 15000; | 60 let osc = context.createOscillator(); |
| 58 var gain = context.createGain(); | 61 osc.frequency.value = 15000; |
| 59 gain.gain.value = 1.5; | 62 let gain = context.createGain(); |
| 60 compressor = context.createDynamicsCompressor(); | 63 gain.gain.value = 1.5; |
| 61 osc.connect(gain); | 64 compressor = context.createDynamicsCompressor(); |
| 62 gain.connect(compressor); | 65 osc.connect(gain); |
| 63 compressor.connect(context.destination); | 66 gain.connect(compressor); |
| 64 osc.start(); | 67 compressor.connect(context.destination); |
| 68 osc.start(); |
| 65 | 69 |
| 66 context.startRendering() | 70 context.startRendering() |
| 67 .then(buffer => checkResult(buffer, should)) | 71 .then(buffer => checkResult(buffer, should)) |
| 68 .then(() => task.done());; | 72 .then(() => task.done()); |
| 69 }); | 73 ; |
| 70 | 74 }); |
| 75 |
| 71 audit.run(); | 76 audit.run(); |
| 72 </script> | 77 </script> |
| 73 | |
| 74 </body> | 78 </body> |
| 75 </html> | 79 </html> |
| OLD | NEW |