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

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

Issue 2768773002: Revert of Allow status = 0 when XHR is completed in Audit.loadFileFromUrl(). (Closed)
Patch Set: 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
46 // Mostly for debugging 50 // Mostly for debugging
47 51
48 // An AudioBuffer for the reference (expected) result. 52 // An AudioBuffer for the reference (expected) result.
49 var reference = 0; 53 var reference = 0;
50 54
51 // Signal power of the reference 55 // Signal power of the reference
52 var signalPower = 0; 56 var signalPower = 0;
53 57
54 // Noise power of the difference between the reference and actual result. 58 // Noise power of the difference between the reference and actual result.
55 var noisePower = 0; 59 var noisePower = 0;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 var diffCount = 0; 116 var diffCount = 0;
113 117
114 for (var k = 0; k < renderedData.length; ++k) { 118 for (var k = 0; k < renderedData.length; ++k) {
115 var diff = renderedData[k] - reference[k]; 119 var diff = renderedData[k] - reference[k];
116 noisePower += diff * diff; 120 noisePower += diff * diff;
117 signalPower += reference[k] * reference[k]; 121 signalPower += reference[k] * reference[k];
118 if (Math.abs(diff) > maxError) { 122 if (Math.abs(diff) > maxError) {
119 maxError = Math.abs(diff); 123 maxError = Math.abs(diff);
120 errorPosition = k; 124 errorPosition = k;
121 } 125 }
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 }
122 } 131 }
123 132
124 var snr = calculateSNR(signalPower, noisePower); 133 var snr = calculateSNR(signalPower, noisePower);
125 should(snr, "SNR") 134 should(snr, "SNR")
126 .beGreaterThanOrEqualTo(thresholdSNR); 135 .beGreaterThanOrEqualTo(thresholdSNR);
127 should(maxError, "Maximum difference") 136 should(maxError, "Maximum difference")
128 .beLessThanOrEqualTo(thresholdDiff); 137 .beLessThanOrEqualTo(thresholdDiff);
129 138
139 should(diffCount,
140 "Number of differences between actual and expected result out of "
141 + renderedData.length + " frames")
142 .beLessThanOrEqualTo(thresholdDiffCount);
143
130 var filename = "oscillator-" + oscType + "-actual.wav"; 144 var filename = "oscillator-" + oscType + "-actual.wav";
131 if (downloadAudioBuffer(renderedBuffer, filename, true)) 145 if (downloadAudioBuffer(renderedBuffer, filename, true))
132 should(true, "Saved reference file").message(filename, ""); 146 should(true, "Saved reference file").message(filename, "");
133 } 147 }
134 148
135 function setThresholds(thresholds) { 149 function setThresholds(thresholds) {
136 thresholdSNR = thresholds.snr; 150 thresholdSNR = thresholds.snr;
137 thresholdDiff = thresholds.maxDiff; 151 thresholdDiff = thresholds.maxDiff;
138 thresholdDiffCount = thresholds.diffCount; 152 thresholdDiffCount = thresholds.diffCount;
139 } 153 }
140 154
141 function runTest(context, oscType, description, task, should) { 155 function runTest(context, oscType, description, task, should) {
142 loadReferenceAndRunTest(context, oscType, task, should); 156 loadReferenceAndRunTest(context, oscType, task, should);
143 } 157 }
144 158
145 return { 159 return {
146 sampleRate: sampleRate, 160 sampleRate: sampleRate,
147 lengthInSeconds: lengthInSeconds, 161 lengthInSeconds: lengthInSeconds,
148 thresholdSNR: thresholdSNR, 162 thresholdSNR: thresholdSNR,
149 thresholdDiff: thresholdDiff, 163 thresholdDiff: thresholdDiff,
164 thresholdDiffCount: thresholdDiffCount,
150 waveScaleFactor: waveScaleFactor, 165 waveScaleFactor: waveScaleFactor,
151 setThresholds: setThresholds, 166 setThresholds: setThresholds,
152 runTest: runTest, 167 runTest: runTest,
153 }; 168 };
154 169
155 }()); 170 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698