Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 var context; | 1 var context; |
| 2 var lengthInSeconds = 2; | 2 var lengthInSeconds = 2; |
| 3 | 3 |
| 4 // Skip this many frames before comparing against reference to allow | 4 // Skip this many frames before comparing against reference to allow |
| 5 // a steady-state to be reached in the up-sampling filters. | 5 // a steady-state to be reached in the up-sampling filters. |
| 6 var filterStabilizeSkipFrames = 2048; | 6 var filterStabilizeSkipFrames = 2048; |
| 7 | 7 |
| 8 var numberOfCurveFrames = 65536; | 8 var numberOfCurveFrames = 65536; |
| 9 var waveShapingCurve; | 9 var waveShapingCurve; |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 // each of which is scaled. | 44 // each of which is scaled. |
| 45 for (var i = 0; i < n; ++i) { | 45 for (var i = 0; i < n; ++i) { |
| 46 var x = (i - n2) / n2; | 46 var x = (i - n2) / n2; |
| 47 var y = kScale * (T1(x) + T2(x) + T3(x) + T4(x)); | 47 var y = kScale * (T1(x) + T2(x) + T3(x) + T4(x)); |
| 48 curve[i] = y; | 48 curve[i] = y; |
| 49 } | 49 } |
| 50 | 50 |
| 51 return curve; | 51 return curve; |
| 52 } | 52 } |
| 53 | 53 |
| 54 function checkShapedCurve(event) { | 54 function checkShapedCurve(buffer, should) { |
| 55 var buffer = event.renderedBuffer; | |
| 56 | |
| 57 var outputData = buffer.getChannelData(0); | 55 var outputData = buffer.getChannelData(0); |
| 58 var n = buffer.length; | 56 var n = buffer.length; |
| 59 | 57 |
| 60 // The WaveShaperNode will have a processing latency if oversampling is used , | 58 // The WaveShaperNode will have a processing latency if oversampling is used , |
| 61 // so we should account for it. | 59 // so we should account for it. |
| 62 | 60 |
| 63 // FIXME: .latency should be exposed as an attribute of the node | 61 // FIXME: .latency should be exposed as an attribute of the node |
| 64 // var waveShaperLatencyFrames = waveshaper.latency * sampleRate; | 62 // var waveShaperLatencyFrames = waveshaper.latency * sampleRate; |
| 65 // But for now we'll use the hard-coded values corresponding to the actual l atencies: | 63 // But for now we'll use the hard-coded values corresponding to the actual l atencies: |
| 66 var waveShaperLatencyFrames = 0; | 64 var waveShaperLatencyFrames = 0; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 | 105 |
| 108 if (j >= filterStabilizeSkipFrames) { | 106 if (j >= filterStabilizeSkipFrames) { |
| 109 if (deltaInDecibels > worstDeltaInDecibels) { | 107 if (deltaInDecibels > worstDeltaInDecibels) { |
| 110 worstDeltaInDecibels = deltaInDecibels; | 108 worstDeltaInDecibels = deltaInDecibels; |
| 111 } | 109 } |
| 112 } | 110 } |
| 113 } | 111 } |
| 114 | 112 |
| 115 // console.log("worstDeltaInDecibels: " + worstDeltaInDecibels); | 113 // console.log("worstDeltaInDecibels: " + worstDeltaInDecibels); |
| 116 | 114 |
| 117 var success = worstDeltaInDecibels < acceptableAliasingThresholdDecibels; | 115 should(worstDeltaInDecibels, oversample + |
| 118 | 116 " WaveshaperNode oversampling error (in dBFS)") |
| 119 if (success) { | 117 .beLessThan(acceptableAliasingThresholdDecibels); |
| 120 testPassed(oversample + " WaveShaperNode oversampling within acceptable tolerance."); | |
| 121 } else { | |
| 122 testFailed(oversample + " WaveShaperNode oversampling not within accepta ble tolerance. Error = " + worstDeltaInDecibels + " dBFS"); | |
| 123 } | |
| 124 | |
| 125 finishJSTest(); | |
| 126 } | 118 } |
| 127 | 119 |
| 128 function createImpulseBuffer(context, sampleFrameLength) { | 120 function createImpulseBuffer(context, sampleFrameLength) { |
| 129 var audioBuffer = context.createBuffer(1, sampleFrameLength, context.sampleR ate); | 121 var audioBuffer = context.createBuffer(1, sampleFrameLength, context.sampleR ate); |
| 130 var n = audioBuffer.length; | 122 var n = audioBuffer.length; |
| 131 var dataL = audioBuffer.getChannelData(0); | 123 var dataL = audioBuffer.getChannelData(0); |
| 132 | 124 |
| 133 for (var k = 0; k < n; ++k) | 125 for (var k = 0; k < n; ++k) |
| 134 dataL[k] = 0; | 126 dataL[k] = 0; |
| 135 | 127 |
| 136 dataL[0] = 1; | 128 dataL[0] = 1; |
| 137 | 129 |
| 138 return audioBuffer; | 130 return audioBuffer; |
| 139 } | 131 } |
| 140 | 132 |
| 141 function runWaveShaperOversamplingTest(testParams) { | 133 function runWaveShaperOversamplingTest(testParams) { |
| 142 sampleRate = testParams.sampleRate; | 134 sampleRate = testParams.sampleRate; |
| 143 nyquist = 0.5 * sampleRate; | 135 nyquist = 0.5 * sampleRate; |
| 144 oversample = testParams.oversample; | 136 oversample = testParams.oversample; |
| 145 fundamentalFrequency = testParams.fundamentalFrequency; | 137 fundamentalFrequency = testParams.fundamentalFrequency; |
| 146 acceptableAliasingThresholdDecibels = testParams.acceptableAliasingThreshold Decibels; | 138 acceptableAliasingThresholdDecibels = testParams.acceptableAliasingThreshold Decibels; |
| 147 | 139 |
| 148 if (window.testRunner) { | 140 let audit = Audit.createTaskRunner(); |
| 149 testRunner.dumpAsText(); | |
| 150 testRunner.waitUntilDone(); | |
| 151 } | |
| 152 | 141 |
| 153 window.jsTestIsAsync = true; | 142 audit.define("test", function (task, should) { |
| 143 task.describe(testParams.description); | |
|
hongchan
2017/02/22 19:05:35
Ditto. How do we reconcile this with task.describe
Raymond Toy
2017/02/22 19:23:24
Wait until that's landed.
| |
| 154 | 144 |
| 155 // Create offline audio context. | 145 // Create offline audio context. |
| 156 var numberOfRenderFrames = sampleRate * lengthInSeconds; | 146 var numberOfRenderFrames = sampleRate * lengthInSeconds; |
| 157 context = new OfflineAudioContext(1, numberOfRenderFrames, sampleRate); | 147 context = new OfflineAudioContext(1, numberOfRenderFrames, sampleRate); |
| 158 | 148 |
| 159 // source -> waveshaper -> destination | 149 // source -> waveshaper -> destination |
| 160 var source = context.createBufferSource(); | 150 var source = context.createBufferSource(); |
| 161 source.buffer = createToneBuffer(context, fundamentalFrequency, lengthInSeco nds, 1); | 151 source.buffer = createToneBuffer(context, fundamentalFrequency, lengthIn Seconds, 1); |
| 162 | 152 |
| 163 // Apply a non-linear distortion curve. | 153 // Apply a non-linear distortion curve. |
| 164 waveshaper = context.createWaveShaper(); | 154 waveshaper = context.createWaveShaper(); |
| 165 waveshaper.curve = generateWaveShapingCurve(); | 155 waveshaper.curve = generateWaveShapingCurve(); |
| 166 waveshaper.oversample = oversample; | 156 waveshaper.oversample = oversample; |
| 167 | 157 |
| 168 source.connect(waveshaper); | 158 source.connect(waveshaper); |
| 169 waveshaper.connect(context.destination); | 159 waveshaper.connect(context.destination); |
| 170 | 160 |
| 171 source.start(0); | 161 source.start(0); |
| 172 | 162 |
| 173 context.oncomplete = checkShapedCurve; | 163 context.startRendering() |
| 174 context.startRendering(); | 164 .then(buffer => checkShapedCurve(buffer, should)) |
| 165 .then(task.done.bind(task)); | |
|
hongchan
2017/02/22 19:05:35
() => task.done()
Raymond Toy
2017/02/22 19:23:24
Done.
| |
| 166 }); | |
| 167 | |
| 168 audit.run(); | |
| 175 } | 169 } |
| OLD | NEW |