Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/oscillator-testing.js

Issue 2766883002: Allow status = 0 when XHR is completed in Audit.loadFileFromUrl(). (Closed)
Patch Set: Fixed threshold after revert Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Notes about generated waveforms: 1 // Notes about generated waveforms:
2 // 2 //
3 // QUESTION: Why does the wave shape not look like the exact shape (sharp edges) ? 3 // QUESTION: Why does the wave shape not look like the exact shape (sharp edges) ?
4 // ANSWER: Because a shape with sharp edges has infinitely high frequency conten t. 4 // ANSWER: Because a shape with sharp edges has infinitely high frequency conten t.
5 // Since a digital audio signal must be band-limited based on the nyquist freque ncy (half the sample-rate) 5 // Since a digital audio signal must be band-limited based on the nyquist freque ncy (half the sample-rate)
6 // in order to avoid aliasing, this creates more rounded edges and "ringing" in the 6 // in order to avoid aliasing, this creates more rounded edges and "ringing" in the
7 // appearance of the waveform. See Nyquist-Shannon sampling theorem: 7 // appearance of the waveform. See Nyquist-Shannon sampling theorem:
8 // http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem 8 // http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem
9 // 9 //
10 // QUESTION: Why does the very end of the generated signal appear to get slightl y weaker? 10 // QUESTION: Why does the very end of the generated signal appear to get slightl y weaker?
(...skipping 25 matching lines...) Expand all
36 36
37 // SNR must be greater than this to pass the test. 37 // SNR must be greater than this to pass the test.
38 // Q: Why is the SNR threshold not infinity? 38 // Q: Why is the SNR threshold not infinity?
39 // A: The reference result is a 16-bit WAV file, so it won't compare exactly wit h the 39 // A: The reference result is a 16-bit WAV file, so it won't compare exactly wit h the
40 // floating point result. 40 // floating point result.
41 var thresholdSNR = 10000; 41 var thresholdSNR = 10000;
42 42
43 // Max diff must be less than this to pass the test. 43 // Max diff must be less than this to pass the test.
44 var thresholdDiff = 0; 44 var thresholdDiff = 0;
45 45
46 // Count the number of differences between the expected and actual result. The t ests passes
47 // if the count is less than this threshold.
48 var thresholdDiffCount = 0;
49
50 // Mostly for debugging 46 // Mostly for debugging
51 47
52 // An AudioBuffer for the reference (expected) result. 48 // An AudioBuffer for the reference (expected) result.
53 var reference = 0; 49 var reference = 0;
54 50
55 // Signal power of the reference 51 // Signal power of the reference
56 var signalPower = 0; 52 var signalPower = 0;
57 53
58 // Noise power of the difference between the reference and actual result. 54 // Noise power of the difference between the reference and actual result.
59 var noisePower = 0; 55 var noisePower = 0;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 var diffCount = 0; 112 var diffCount = 0;
117 113
118 for (var k = 0; k < renderedData.length; ++k) { 114 for (var k = 0; k < renderedData.length; ++k) {
119 var diff = renderedData[k] - reference[k]; 115 var diff = renderedData[k] - reference[k];
120 noisePower += diff * diff; 116 noisePower += diff * diff;
121 signalPower += reference[k] * reference[k]; 117 signalPower += reference[k] * reference[k];
122 if (Math.abs(diff) > maxError) { 118 if (Math.abs(diff) > maxError) {
123 maxError = Math.abs(diff); 119 maxError = Math.abs(diff);
124 errorPosition = k; 120 errorPosition = k;
125 } 121 }
126 // The reference file is a 16-bit WAV file, so we will almost never get an exact match
127 // between it and the actual floating-point result.
128 if (diff > 0) {
129 diffCount++;
130 }
131 } 122 }
132 123
133 var snr = calculateSNR(signalPower, noisePower); 124 var snr = calculateSNR(signalPower, noisePower);
134 should(snr, "SNR") 125 should(snr, "SNR")
135 .beGreaterThanOrEqualTo(thresholdSNR); 126 .beGreaterThanOrEqualTo(thresholdSNR);
136 should(maxError, "Maximum difference") 127 should(maxError, "Maximum difference")
137 .beLessThanOrEqualTo(thresholdDiff); 128 .beLessThanOrEqualTo(thresholdDiff);
138 129
139 should(diffCount,
140 "Number of differences between actual and expected result out of "
141 + renderedData.length + " frames")
142 .beLessThanOrEqualTo(thresholdDiffCount);
143
144 var filename = "oscillator-" + oscType + "-actual.wav"; 130 var filename = "oscillator-" + oscType + "-actual.wav";
145 if (downloadAudioBuffer(renderedBuffer, filename, true)) 131 if (downloadAudioBuffer(renderedBuffer, filename, true))
146 should(true, "Saved reference file").message(filename, ""); 132 should(true, "Saved reference file").message(filename, "");
147 } 133 }
148 134
149 function setThresholds(thresholds) { 135 function setThresholds(thresholds) {
150 thresholdSNR = thresholds.snr; 136 thresholdSNR = thresholds.snr;
151 thresholdDiff = thresholds.maxDiff; 137 thresholdDiff = thresholds.maxDiff;
152 thresholdDiffCount = thresholds.diffCount; 138 thresholdDiffCount = thresholds.diffCount;
153 } 139 }
154 140
155 function runTest(context, oscType, description, task, should) { 141 function runTest(context, oscType, description, task, should) {
156 loadReferenceAndRunTest(context, oscType, task, should); 142 loadReferenceAndRunTest(context, oscType, task, should);
157 } 143 }
158 144
159 return { 145 return {
160 sampleRate: sampleRate, 146 sampleRate: sampleRate,
161 lengthInSeconds: lengthInSeconds, 147 lengthInSeconds: lengthInSeconds,
162 thresholdSNR: thresholdSNR, 148 thresholdSNR: thresholdSNR,
163 thresholdDiff: thresholdDiff, 149 thresholdDiff: thresholdDiff,
164 thresholdDiffCount: thresholdDiffCount,
165 waveScaleFactor: waveScaleFactor, 150 waveScaleFactor: waveScaleFactor,
166 setThresholds: setThresholds, 151 setThresholds: setThresholds,
167 runTest: runTest, 152 runTest: runTest,
168 }; 153 };
169 154
170 }()); 155 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698