Index: third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-float-data.html |
diff --git a/third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-float-data.html b/third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-float-data.html |
index d1b54dbe41f68d30fab8ec41b27393b89ff582a0..bbaf02a6f3e39e8980f10d4483e45b7c499ff5f9 100644 |
--- a/third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-float-data.html |
+++ b/third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-float-data.html |
@@ -1,116 +1,138 @@ |
-<!doctype html> |
+<!DOCTYPE html> |
<html> |
<head> |
+ <title> |
+ Test AnalyserNode getFloatTimeDomainData |
+ </title> |
<script src="../../resources/testharness.js"></script> |
- <script src="../../resources/testharnessreport.js"></script> |
+ <script src="../../resources/testharnessreport.js"></script> |
<script src="../resources/audit-util.js"></script> |
<script src="../resources/audit.js"></script> |
- <title>Test AnalyserNode getFloatTimeDomainData</title> |
</head> |
- |
<body> |
- <script> |
- // Use a power of two to eliminate any round-off in the computation of the times for |
- // context.suspend(). |
- var sampleRate = 32768; |
- |
- // The largest FFT size for the analyser node is 32768. We want to render longer than this so |
- // that we have at least one complete buffer of data of 32768 samples. |
- var renderFrames = 2 * 32768; |
- var renderDuration = renderFrames / sampleRate; |
- |
- var audit = Audit.createTaskRunner(); |
- |
- // Test that getFloatTimeDomainData handles short and long vectors correctly. |
- audit.define("short and long vector", (task, should) => { |
- var fftSize = 32; |
- var graphInfo = createGraph(fftSize); |
- var context = graphInfo.context; |
- var analyser = graphInfo.analyser; |
- var signalBuffer = graphInfo.signalBuffer; |
- var signal = signalBuffer.getChannelData(0); |
- |
- var success = true; |
- var sampleFrame = 128; |
- |
- context.suspend(sampleFrame / sampleRate).then(function () { |
- var shortData = new Float32Array(8); |
- // Initialize the array to Infinity to represent uninitialize data. |
- shortData.fill(Infinity); |
- |
- analyser.getFloatTimeDomainData(shortData); |
- |
- // The short array should be filled with the expected data, with no errors thrown. |
- |
- var expected = signal.subarray(sampleFrame - fftSize, sampleFrame); |
- should(shortData, shortData.length + "-element time domain data") |
- .beEqualToArray(expected.subarray(0, shortData.length)); |
- |
- var longData = new Float32Array(2 * fftSize); |
- // Initialize the array to Infinity to represent uninitialize data. |
- longData.fill(Infinity); |
- |
- analyser.getFloatTimeDomainData(longData); |
- |
- // The long array should filled with the expected data but the extra elements should be |
- // untouched. |
- should(longData.subarray(0, fftSize), "longData.subarray(0, " + fftSize + ")") |
- .beEqualToArray(expected); |
- |
- should(longData.subarray(fftSize), "Unfilled elements longData.subarray(" + fftSize + ")") |
- .beConstantValueOf(Infinity); |
- }).then(context.resume.bind(context)); |
+ <script id="layout-test-code"> |
+ // Use a power of two to eliminate any round-off in the computation of the |
+ // times for context.suspend(). |
+ let sampleRate = 32768; |
+ |
+ // The largest FFT size for the analyser node is 32768. We want to render |
+ // longer than this so that we have at least one complete buffer of data |
+ // of 32768 samples. |
+ let renderFrames = 2 * 32768; |
+ let renderDuration = renderFrames / sampleRate; |
+ |
+ let audit = Audit.createTaskRunner(); |
+ |
+ // Test that getFloatTimeDomainData handles short and long vectors |
+ // correctly. |
+ audit.define('short and long vector', (task, should) => { |
+ let fftSize = 32; |
+ let graphInfo = createGraph(fftSize); |
+ let context = graphInfo.context; |
+ let analyser = graphInfo.analyser; |
+ let signalBuffer = graphInfo.signalBuffer; |
+ let signal = signalBuffer.getChannelData(0); |
+ |
+ let success = true; |
+ let sampleFrame = 128; |
+ |
+ context.suspend(sampleFrame / sampleRate) |
+ .then(function() { |
+ let shortData = new Float32Array(8); |
+ // Initialize the array to Infinity to represent uninitialize |
+ // data. |
+ shortData.fill(Infinity); |
+ |
+ analyser.getFloatTimeDomainData(shortData); |
+ |
+ // The short array should be filled with the expected data, with |
+ // no errors thrown. |
+ |
+ let expected = |
+ signal.subarray(sampleFrame - fftSize, sampleFrame); |
+ should(shortData, shortData.length + '-element time domain data') |
+ .beEqualToArray(expected.subarray(0, shortData.length)); |
+ |
+ let longData = new Float32Array(2 * fftSize); |
+ // Initialize the array to Infinity to represent uninitialize |
+ // data. |
+ longData.fill(Infinity); |
+ |
+ analyser.getFloatTimeDomainData(longData); |
+ |
+ // The long array should filled with the expected data but the |
+ // extra elements should be untouched. |
+ should( |
+ longData.subarray(0, fftSize), |
+ 'longData.subarray(0, ' + fftSize + ')') |
+ .beEqualToArray(expected); |
+ |
+ should( |
+ longData.subarray(fftSize), |
+ 'Unfilled elements longData.subarray(' + fftSize + ')') |
+ .beConstantValueOf(Infinity); |
+ }) |
+ .then(context.resume.bind(context)); |
context.startRendering().then(() => task.done()); |
}); |
- var success = true; |
+ let success = true; |
// Generate tests for all valid FFT sizes for an AnalyserNode. |
- for (var k = 5; k < 16; ++k) { |
- var fftSize = Math.pow(2, k); |
- (function (n) { |
+ for (let k = 5; k < 16; ++k) { |
+ let fftSize = Math.pow(2, k); |
+ (function(n) { |
// We grab a sample at (roughly) half the rendering duration. |
- audit.define("fftSize " + n, (task, should) => { |
+ audit.define('fftSize ' + n, (task, should) => { |
runTest(n, renderDuration / 2, should).then(() => task.done()); |
}); |
})(fftSize); |
} |
- // Special case for a large size, but the sampling point is early. The initial part of the |
- // buffer should be filled with zeroes. |
+ // Special case for a large size, but the sampling point is early. The |
+ // initial part of the buffer should be filled with zeroes. |
- audit.define("initial zeroes", (task, should) => { |
- // Somewhat arbitrary size for the analyser. It should be greater than one rendering |
- // quantum. |
- var fftSize = 2048; |
- var graphInfo = createGraph(fftSize); |
- var context = graphInfo.context; |
- var analyser = graphInfo.analyser; |
- var signalBuffer = graphInfo.signalBuffer; |
+ audit.define('initial zeroes', (task, should) => { |
+ // Somewhat arbitrary size for the analyser. It should be greater than |
+ // one rendering quantum. |
+ let fftSize = 2048; |
+ let graphInfo = createGraph(fftSize); |
+ let context = graphInfo.context; |
+ let analyser = graphInfo.analyser; |
+ let signalBuffer = graphInfo.signalBuffer; |
- var data = new Float32Array(fftSize); |
+ let data = new Float32Array(fftSize); |
success = true; |
// Suspend every rendering quantum and examine the analyser data. |
- for (var k = 128; k <= fftSize; k += 128) { |
- context.suspend(k / sampleRate).then(function () { |
- analyser.getFloatTimeDomainData(data); |
- var sampleFrame = context.currentTime * sampleRate; |
- |
- // Verify that the last k frames are not zero, but the first fftSize - k frames are. |
- var prefix = "At frame " + (sampleFrame - 1) + ": data.subarray"; |
- if (sampleFrame < fftSize) { |
- should(data.subarray(0, fftSize - sampleFrame), |
- prefix + "(0, " + (fftSize - sampleFrame) + ")") |
- .beConstantValueOf(0) && success; |
- } |
- |
- var signal = signalBuffer.getChannelData(0); |
- should(data.subarray(fftSize - sampleFrame, fftSize), |
- prefix + "(" + (fftSize - sampleFrame) + ", " + fftSize + ")") |
- .beEqualToArray(signal.subarray(0, sampleFrame)) && success; |
- }).then(context.resume.bind(context)); |
+ for (let k = 128; k <= fftSize; k += 128) { |
+ context.suspend(k / sampleRate) |
+ .then(function() { |
+ analyser.getFloatTimeDomainData(data); |
+ let sampleFrame = context.currentTime * sampleRate; |
+ |
+ // Verify that the last k frames are not zero, but the first |
+ // fftSize - k frames are. |
+ let prefix = |
+ 'At frame ' + (sampleFrame - 1) + ': data.subarray'; |
+ if (sampleFrame < fftSize) { |
+ should( |
+ data.subarray(0, fftSize - sampleFrame), |
+ prefix + '(0, ' + (fftSize - sampleFrame) + ')') |
+ .beConstantValueOf(0) && |
+ success; |
+ } |
+ |
+ let signal = signalBuffer.getChannelData(0); |
+ should( |
+ data.subarray(fftSize - sampleFrame, fftSize), |
+ prefix + '(' + (fftSize - sampleFrame) + ', ' + fftSize + |
+ ')') |
+ .beEqualToArray(signal.subarray(0, sampleFrame)) && |
+ success; |
+ }) |
+ .then(context.resume.bind(context)); |
} |
context.startRendering().then(() => task.done()); |
@@ -118,52 +140,61 @@ |
audit.run(); |
- // Run test of an AnalyserNode with fftSize of |fftSize|, and with the data from the node |
- // being requested at time |sampletime|. The result from the analyser node is compared |
- // against the expected data. The result of startRendering() is returned. |
+ // Run test of an AnalyserNode with fftSize of |fftSize|, and with the |
+ // data from the node being requested at time |sampletime|. The result |
+ // from the analyser node is compared against the expected data. The |
+ // result of startRendering() is returned. |
function runTest(fftSize, sampleTime, should) { |
- var graphInfo = createGraph(fftSize); |
- var context = graphInfo.context; |
- var analyser = graphInfo.analyser; |
- var signalBuffer = graphInfo.signalBuffer; |
+ let graphInfo = createGraph(fftSize); |
+ let context = graphInfo.context; |
+ let analyser = graphInfo.analyser; |
+ let signalBuffer = graphInfo.signalBuffer; |
// Grab the data at the requested time. |
- context.suspend(sampleTime).then(function () { |
- var lastFrame = Math.floor(context.currentTime * sampleRate); |
- |
- // Grab the time domain data from the analyzer and compare against the expected result. |
- var actualFloatData = new Float32Array(fftSize); |
- analyser.getFloatTimeDomainData(actualFloatData); |
- |
- // Compare against the expected result. |
- var signal = signalBuffer.getChannelData(0); |
- var message = actualFloatData.length + "-point analyser time domain data"; |
- should(actualFloatData, message) |
- .beEqualToArray(signal.subarray(lastFrame - actualFloatData.length, lastFrame)) && success; |
- }).then(context.resume.bind(context)); |
+ context.suspend(sampleTime) |
+ .then(function() { |
+ let lastFrame = Math.floor(context.currentTime * sampleRate); |
+ |
+ // Grab the time domain data from the analyzer and compare against |
+ // the expected result. |
+ let actualFloatData = new Float32Array(fftSize); |
+ analyser.getFloatTimeDomainData(actualFloatData); |
+ |
+ // Compare against the expected result. |
+ let signal = signalBuffer.getChannelData(0); |
+ let message = |
+ actualFloatData.length + '-point analyser time domain data'; |
+ should(actualFloatData, message) |
+ .beEqualToArray(signal.subarray( |
+ lastFrame - actualFloatData.length, lastFrame)) && |
+ success; |
+ }) |
+ .then(context.resume.bind(context)); |
return context.startRendering(); |
} |
- // Create the audio graph with an AnalyserNode with fftSize |fftSize|. A simple |
- // integer-valued linear ramp is the source so we can easily verify the results. A dictionary |
- // consisting of the context, the analyser node, and the signal is returned. |
+ // Create the audio graph with an AnalyserNode with fftSize |fftSize|. A |
+ // simple integer-valued linear ramp is the source so we can easily verify |
+ // the results. A dictionary consisting of the context, the analyser |
+ // node, and the signal is returned. |
function createGraph(fftSize) { |
- var context = new OfflineAudioContext(1, renderFrames, sampleRate); |
+ let context = new OfflineAudioContext(1, renderFrames, sampleRate); |
- var src = context.createBufferSource(); |
+ let src = context.createBufferSource(); |
- // Use a simple linear ramp as the source. For simplicity of inspecting results, the ramp |
- // starts at 1 with an increment of 1. |
- var signalBuffer = context.createBuffer(1, renderFrames, context.sampleRate); |
- var data = signalBuffer.getChannelData(0); |
- for (var k = 0; k < data.length; ++k) { |
+ // Use a simple linear ramp as the source. For simplicity of inspecting |
+ // results, the ramp starts at 1 with an increment of 1. |
+ let signalBuffer = |
+ context.createBuffer(1, renderFrames, context.sampleRate); |
+ let data = signalBuffer.getChannelData(0); |
+ for (let k = 0; k < data.length; ++k) { |
data[k] = k + 1; |
} |
src.buffer = signalBuffer; |
- var analyser = context.createAnalyser(); |
+ let analyser = context.createAnalyser(); |
analyser.fftSize = fftSize; |
src.connect(analyser); |