| Index: third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-multiple-calls.html
|
| diff --git a/third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-multiple-calls.html b/third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-multiple-calls.html
|
| index 18c65e9686e3b3f6e9f3656b76840ad126e6be53..34060e956a039c95803146877cce7078698aa23a 100644
|
| --- a/third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-multiple-calls.html
|
| +++ b/third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-multiple-calls.html
|
| @@ -1,99 +1,118 @@
|
| -<!doctype html>
|
| +<!DOCTYPE html>
|
| <html>
|
| <head>
|
| + <title>
|
| + Test Multiple Calls to getFloatFrequencyData
|
| + </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 Multiple Calls to getFloatFrequencyData</title>
|
| </head>
|
| -
|
| <body>
|
| - <script>
|
| - var sampleRate = 48000;
|
| - // Render enough data to run the test.
|
| - var renderFrames = 2*1024;
|
| - var renderDuration = renderFrames / sampleRate;
|
| + <script id="layout-test-code">
|
| + let sampleRate = 48000;
|
| + // Render enough data to run the test.
|
| + let renderFrames = 2 * 1024;
|
| + let renderDuration = renderFrames / sampleRate;
|
|
|
| - var audit = Audit.createTaskRunner();
|
| + let audit = Audit.createTaskRunner();
|
|
|
| - audit.define("test", (task, should) => {
|
| + audit.define('test', (task, should) => {
|
|
|
| - var context = new OfflineAudioContext(1, renderFrames, sampleRate);
|
| + let context = new OfflineAudioContext(1, renderFrames, sampleRate);
|
|
|
| - // Use sawtooth oscillator as the source because it has quite a bit of harmonic content.
|
| - // Otherwise, the type doesn't really matter.
|
| - var osc = context.createOscillator();
|
| - osc.type = "sawtooth";
|
| + // Use sawtooth oscillator as the source because it has quite a bit of
|
| + // harmonic content. Otherwise, the type doesn't really matter.
|
| + let osc = context.createOscillator();
|
| + osc.type = 'sawtooth';
|
|
|
| - // Create an analyser with 256-point FFT. The FFT size doesn't really matter much.
|
| - var analyser = context.createAnalyser();
|
| + // Create an analyser with 256-point FFT. The FFT size doesn't really
|
| + // matter much.
|
| + let analyser = context.createAnalyser();
|
| analyser.fftSize = 256;
|
|
|
| osc.connect(analyser);
|
| analyser.connect(context.destination);
|
|
|
| - var success = true;
|
| -
|
| - // Suspend after getting a full analyser frame. (Not really necessary, but it's nice that
|
| - // the frame doesn't include any initial zeroes.
|
| - var suspendFrame = analyser.fftSize;
|
| - context.suspend(suspendFrame / sampleRate).then(function () {
|
| - // Test successive calls to getFloatFrequencyData in the same rendering quantum.
|
| - let f1 = new Float32Array(analyser.frequencyBinCount);
|
| - let f2 = new Float32Array(analyser.frequencyBinCount);
|
| -
|
| - analyser.getFloatFrequencyData(f1);
|
| - analyser.getFloatFrequencyData(f2);
|
| - should(f2, "Second call to getFloatFrequencyData")
|
| - .beEqualToArray(f1);
|
| - }).then(context.resume.bind(context));
|
| + let success = true;
|
| +
|
| + // Suspend after getting a full analyser frame. (Not really necessary,
|
| + // but it's nice that the frame doesn't include any initial zeroes.
|
| + let suspendFrame = analyser.fftSize;
|
| + context.suspend(suspendFrame / sampleRate)
|
| + .then(function() {
|
| + // Test successive calls to getFloatFrequencyData in the same
|
| + // rendering quantum.
|
| + let f1 = new Float32Array(analyser.frequencyBinCount);
|
| + let f2 = new Float32Array(analyser.frequencyBinCount);
|
| +
|
| + analyser.getFloatFrequencyData(f1);
|
| + analyser.getFloatFrequencyData(f2);
|
| + should(f2, 'Second call to getFloatFrequencyData')
|
| + .beEqualToArray(f1);
|
| + })
|
| + .then(context.resume.bind(context));
|
|
|
| suspendFrame += 128;
|
| - context.suspend(suspendFrame / sampleRate).then(function () {
|
| - // Test successive calls to getByteFrequencyData in the same rendering quantum.
|
| - let f1 = new Uint8Array(analyser.frequencyBinCount);
|
| - let f2 = new Uint8Array(analyser.frequencyBinCount);
|
| + context.suspend(suspendFrame / sampleRate)
|
| + .then(function() {
|
| + // Test successive calls to getByteFrequencyData in the same
|
| + // rendering quantum.
|
| + let f1 = new Uint8Array(analyser.frequencyBinCount);
|
| + let f2 = new Uint8Array(analyser.frequencyBinCount);
|
|
|
| - analyser.getByteFrequencyData(f1);
|
| - analyser.getByteFrequencyData(f2);
|
| + analyser.getByteFrequencyData(f1);
|
| + analyser.getByteFrequencyData(f2);
|
|
|
| - should(f2, "Second call to getByteFrequencyData")
|
| - .beEqualToArray(f1);
|
| - }).then(context.resume.bind(context));
|
| + should(f2, 'Second call to getByteFrequencyData')
|
| + .beEqualToArray(f1);
|
| + })
|
| + .then(context.resume.bind(context));
|
|
|
| suspendFrame += 128;
|
| - context.suspend(suspendFrame / sampleRate).then(function () {
|
| - // Test calls to getFloatFrequencyData followed by getByteFrequencyData. The float data,
|
| - // when converted to byte values should be identical to the result from
|
| - // getByteFrequencyData.
|
| - let f1 = new Float32Array(analyser.frequencyBinCount);
|
| - let f2 = new Uint8Array(analyser.frequencyBinCount);
|
| -
|
| - analyser.getFloatFrequencyData(f1);
|
| - analyser.getByteFrequencyData(f2);
|
| -
|
| - var byteValuesFromFloat = convertFloatToByte(f1, analyser.minDecibels, analyser.maxDecibels);
|
| - should(byteValuesFromFloat, "Output of getByteFrequencyData after getFloatFrequencyData")
|
| - .beEqualToArray(f2);
|
| - }).then(context.resume.bind(context));
|
| + context.suspend(suspendFrame / sampleRate)
|
| + .then(function() {
|
| + // Test calls to getFloatFrequencyData followed by
|
| + // getByteFrequencyData. The float data, when converted to byte
|
| + // values should be identical to the result from
|
| + // getByteFrequencyData.
|
| + let f1 = new Float32Array(analyser.frequencyBinCount);
|
| + let f2 = new Uint8Array(analyser.frequencyBinCount);
|
| +
|
| + analyser.getFloatFrequencyData(f1);
|
| + analyser.getByteFrequencyData(f2);
|
| +
|
| + let byteValuesFromFloat = convertFloatToByte(
|
| + f1, analyser.minDecibels, analyser.maxDecibels);
|
| + should(
|
| + byteValuesFromFloat,
|
| + 'Output of getByteFrequencyData after getFloatFrequencyData')
|
| + .beEqualToArray(f2);
|
| + })
|
| + .then(context.resume.bind(context));
|
|
|
| suspendFrame += 128;
|
| - context.suspend(suspendFrame / sampleRate).then(function () {
|
| - // Test calls to getByteFrequencyData followed by getFloatFrequencyData. The float data,
|
| - // when converted to byte values should be identical to the result from
|
| - // getByteFrequencyData.
|
| - var f1 = new Uint8Array(analyser.frequencyBinCount);
|
| - var f2 = new Float32Array(analyser.frequencyBinCount);
|
| -
|
| - analyser.getByteFrequencyData(f1);
|
| - analyser.getFloatFrequencyData(f2);
|
| -
|
| - var byteValuesFromFloat = convertFloatToByte(f2, analyser.minDecibels, analyser.maxDecibels);
|
| - should(f1,
|
| - "Output of getFloatFrequenycData (converted to byte) after getByteFrequencyData")
|
| - .beEqualToArray(byteValuesFromFloat);
|
| - }).then(context.resume.bind(context));
|
| + context.suspend(suspendFrame / sampleRate)
|
| + .then(function() {
|
| + // Test calls to getByteFrequencyData followed by
|
| + // getFloatFrequencyData. The float data, when converted to byte
|
| + // values should be identical to the result from
|
| + // getByteFrequencyData.
|
| + let f1 = new Uint8Array(analyser.frequencyBinCount);
|
| + let f2 = new Float32Array(analyser.frequencyBinCount);
|
| +
|
| + analyser.getByteFrequencyData(f1);
|
| + analyser.getFloatFrequencyData(f2);
|
| +
|
| + let byteValuesFromFloat = convertFloatToByte(
|
| + f2, analyser.minDecibels, analyser.maxDecibels);
|
| + should(
|
| + f1,
|
| + 'Output of getFloatFrequenycData (converted to byte) after getByteFrequencyData')
|
| + .beEqualToArray(byteValuesFromFloat);
|
| + })
|
| + .then(context.resume.bind(context));
|
|
|
| osc.start();
|
| context.startRendering().then(() => task.done());
|
| @@ -101,13 +120,14 @@
|
|
|
| audit.run();
|
|
|
| - // Convert the float frequency data (in dB), |floatFreqData|, to byte values using the dB
|
| - // limits |minDecibels| and |maxDecibels|. The new byte array is returned.
|
| + // Convert the float frequency data (in dB), |floatFreqData|, to byte
|
| + // values using the dB limits |minDecibels| and |maxDecibels|. The new
|
| + // byte array is returned.
|
| function convertFloatToByte(floatFreqData, minDecibels, maxDecibels) {
|
| - var scale = 255 / (maxDecibels - minDecibels);
|
| + let scale = 255 / (maxDecibels - minDecibels);
|
|
|
| - return floatFreqData.map(function (x) {
|
| - var value = Math.floor(scale * (x - minDecibels));
|
| + return floatFreqData.map(function(x) {
|
| + let value = Math.floor(scale * (x - minDecibels));
|
| return Math.min(255, Math.max(0, value));
|
| });
|
| }
|
|
|