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

Unified Diff: LayoutTests/webaudio/osc-low-freq.html

Issue 1180613007: Allow larger arrays up to size 8192 for PeriodicWave (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/webaudio/osc-low-freq.html
diff --git a/LayoutTests/webaudio/osc-low-freq.html b/LayoutTests/webaudio/osc-low-freq.html
new file mode 100644
index 0000000000000000000000000000000000000000..706bcf8655ea176c3353c157d2fd783d29911711
--- /dev/null
+++ b/LayoutTests/webaudio/osc-low-freq.html
@@ -0,0 +1,87 @@
+<!doctype html>
+<html>
+ <head>
+ <title>Test Custom Oscillator at Very Low Frequency</title>
+ <script src="../resources/js-test.js"></script>
+ <script src="resources/compatibility.js"></script>
+ <script src="resources/audio-testing.js"></script>
+ </head>
+
+ <body>
+ <script>
+ description("Test Custom Oscillator at Very Low Frequency");
+ window.jsTestIsAsync = true;
+
+ // Create a custom oscillator and verify that the parts of a periodic wave that should be
+ // ignored really are ignored.
+
+ var sampleRate = 48000;
+ var highSampleRate = 192000;
hongchan 2015/07/22 21:01:19 This is unused.
Raymond Toy 2015/07/23 15:33:09 Done.
+
+ // The desired frequency of the oscillator. The value to be used depends on the
+ // implementation of the PeriodicWave and should be less than then lowest fundamental
+ // frequency. The lowest frequency is the Nyquist frequency divided by the max number of
+ // partials used for the FFT. In the current implementation, the max number of partials is
+ // 2048 so the lowest frequency is 24000/2048 = 11.78 Hz.
hongchan 2015/07/22 21:01:19 Partials are not linearly arranged over the freque
Raymond Toy 2015/07/23 15:33:09 I've rewritten the comment. Let me if it's better.
+ var desiredFrequencyHz = 1;
+
+ // Minimum allowed SNR between the actual oscillator and the expected result. Experimentally
+ // determined.
+ var snrThreshold = 130;
+
+ var context;
+ var osc;
+ var actual;
+
+ var audit = Audit.createTaskRunner();
+
+ function checkSineResult(result, freq, rate) {
hongchan 2015/07/22 21:01:19 Perhaps would |checkCosineResult| fit better for t
Raymond Toy 2015/07/23 15:33:09 Done.
+ // Compute the SNR between the actual result and expected cosine wave
hongchan 2015/07/22 21:01:19 How about moving this to the line 37? Also a perio
Raymond Toy 2015/07/23 15:33:09 Done.
+ var signal = 0;
+ var noise = 0;
+ var omega = 2 * Math.PI * freq / rate;
+
+ actual = result.getChannelData(0);
+
+ for (var k = 0; k < actual.length; ++k) {
+ var x = Math.cos(omega * k);
+ var diff = x - actual[k];
+ signal += x * x;
+ noise += diff * diff;
+ }
+
+ var snr = 10 * Math.log10(signal / noise);
+
+ Should("SNR of " + desiredFrequencyHz + " Hz sine wave", snr).beGreaterThanOrEqualTo(snrThreshold);
+ testPassed("PeriodicWave coefficients that must be ignored were correctly ignored.");
+ }
+
+ function runTest() {
+ context = new OfflineAudioContext(1, sampleRate, sampleRate);
+ osc = context.createOscillator();
+
+ // Create the custom oscillator. For simplicity of testing, we use just a cosine wave, but
+ // the initial elements of the real and imaginary parts are explicitly set to non-zero to
+ // test that they are ignored.
+ var r = new Float32Array(2);
+ var i = new Float32Array(2);
+ r[0] = 1; // DC component to be ignored
+ r[1] = 1; // Fundamental
+ i[0] = 1; // Sine term that doesn't actually exist in a Fourier series
+ i[1] = 0;
+ var wave = context.createPeriodicWave(r, i);
+
+ osc.setPeriodicWave(wave);
+ osc.frequency.value = desiredFrequencyHz;
+ osc.connect(context.destination);
+ osc.start();
+ context.startRendering().then(function (b) {
hongchan 2015/07/22 21:01:19 Let's use |buffer| instead of |b|.
+ checkSineResult(b, desiredFrequencyHz, sampleRate);
+ }).then(finishJSTest);
+ };
+
+ runTest();
+ successfullyParsed = true;
+ </script>
+ </body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698