| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 132 |
| 133 function runWaveShaperOversamplingTest(testParams) { | 133 function runWaveShaperOversamplingTest(testParams) { |
| 134 sampleRate = testParams.sampleRate; | 134 sampleRate = testParams.sampleRate; |
| 135 nyquist = 0.5 * sampleRate; | 135 nyquist = 0.5 * sampleRate; |
| 136 oversample = testParams.oversample; | 136 oversample = testParams.oversample; |
| 137 fundamentalFrequency = testParams.fundamentalFrequency; | 137 fundamentalFrequency = testParams.fundamentalFrequency; |
| 138 acceptableAliasingThresholdDecibels = testParams.acceptableAliasingThreshold
Decibels; | 138 acceptableAliasingThresholdDecibels = testParams.acceptableAliasingThreshold
Decibels; |
| 139 | 139 |
| 140 let audit = Audit.createTaskRunner(); | 140 let audit = Audit.createTaskRunner(); |
| 141 | 141 |
| 142 audit.define("test", function (task, should) { | 142 audit.define({ |
| 143 task.describe(testParams.description); | 143 label: "test", |
| 144 description: testParams.description |
| 145 }, function (task, should) { |
| 144 | 146 |
| 145 // Create offline audio context. | 147 // Create offline audio context. |
| 146 var numberOfRenderFrames = sampleRate * lengthInSeconds; | 148 var numberOfRenderFrames = sampleRate * lengthInSeconds; |
| 147 context = new OfflineAudioContext(1, numberOfRenderFrames, sampleRate); | 149 context = new OfflineAudioContext(1, numberOfRenderFrames, |
| 150 sampleRate); |
| 148 | 151 |
| 149 // source -> waveshaper -> destination | 152 // source -> waveshaper -> destination |
| 150 var source = context.createBufferSource(); | 153 var source = context.createBufferSource(); |
| 151 source.buffer = createToneBuffer(context, fundamentalFrequency, lengthIn
Seconds, 1); | 154 source.buffer = createToneBuffer(context, fundamentalFrequency, |
| 155 lengthInSeconds, 1); |
| 152 | 156 |
| 153 // Apply a non-linear distortion curve. | 157 // Apply a non-linear distortion curve. |
| 154 waveshaper = context.createWaveShaper(); | 158 waveshaper = context.createWaveShaper(); |
| 155 waveshaper.curve = generateWaveShapingCurve(); | 159 waveshaper.curve = generateWaveShapingCurve(); |
| 156 waveshaper.oversample = oversample; | 160 waveshaper.oversample = oversample; |
| 157 | 161 |
| 158 source.connect(waveshaper); | 162 source.connect(waveshaper); |
| 159 waveshaper.connect(context.destination); | 163 waveshaper.connect(context.destination); |
| 160 | 164 |
| 161 source.start(0); | 165 source.start(0); |
| 162 | 166 |
| 163 context.startRendering() | 167 context.startRendering() |
| 164 .then(buffer => checkShapedCurve(buffer, should)) | 168 .then(buffer => checkShapedCurve(buffer, should)) |
| 165 .then(() => task.done()); | 169 .then(() => task.done()); |
| 166 }); | 170 }); |
| 167 | 171 |
| 168 audit.run(); | 172 audit.run(); |
| 169 } | 173 } |
| OLD | NEW |