Index: third_party/WebKit/LayoutTests/webaudio/Gain/gain.html |
diff --git a/third_party/WebKit/LayoutTests/webaudio/Gain/gain.html b/third_party/WebKit/LayoutTests/webaudio/Gain/gain.html |
index b7bf8ccc97d00886b025f0dc2a2f1b31ca1192f1..eceeda5e7c94b438a61a9fec1ce238b93d2388b6 100644 |
--- a/third_party/WebKit/LayoutTests/webaudio/Gain/gain.html |
+++ b/third_party/WebKit/LayoutTests/webaudio/Gain/gain.html |
@@ -1,122 +1,118 @@ |
<!DOCTYPE html> |
- |
<!-- |
Tests that GainNode is properly scaling the gain. |
We'll render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1. |
The 11th note will be of gain 0.0, so it should be silent (at the end in the rendered output). |
--> |
- |
<html> |
-<head> |
-<script src="../../resources/testharness.js"></script> |
-<script src="../../resources/testharnessreport.js"></script> |
-<script src="../resources/audit-util.js"></script> |
-<script src="../resources/audit.js"></script> |
-<script src="../resources/buffer-loader.js"></script> |
-</head> |
-<body> |
- |
-<script> |
-let audit = Audit.createTaskRunner(); |
- |
-let sampleRate = 44100.0; |
-let bufferDurationSeconds = 0.125; |
-let numberOfNotes = 11; |
-let noteSpacing = |
- bufferDurationSeconds + 0.020; // leave 20ms of silence between each "note" |
-let lengthInSeconds = numberOfNotes * noteSpacing; |
- |
-let context = 0; |
-let sinWaveBuffer = 0; |
-let reference = 0; |
- |
-function createSinWaveBuffer(lengthInSeconds, frequency) { |
- let audioBuffer = |
- context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate); |
- |
- let n = audioBuffer.length; |
- let channelL = audioBuffer.getChannelData(0); |
- let channelR = audioBuffer.getChannelData(1); |
- |
- for (let i = 0; i < n; ++i) { |
- channelL[i] = Math.sin(frequency * 2.0 * Math.PI * i / sampleRate); |
- channelR[i] = channelL[i]; |
- } |
- |
- return audioBuffer; |
-} |
- |
-function playNote(time, gain) { |
- let source = context.createBufferSource(); |
- source.buffer = sinWaveBuffer; |
- |
- let gainNode = context.createGain(); |
- gainNode.gain.value = gain; |
- |
- source.connect(gainNode); |
- gainNode.connect(context.destination); |
- |
- source.start(time); |
-} |
- |
-audit.define({ |
- label: 'create context', |
- description: 'Create context for test' |
-}, function(task, should) { |
- // Create offline audio context. |
- context = |
- new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate); |
- task.done(); |
-}); |
- |
-audit.define({ |
- label: 'load-ref', |
- description: 'Load reference audio file' |
-}, function(task, should) { |
- let bufferLoader = |
- new BufferLoader(context, ['gain-expected.wav'], bufferList => { |
- reference = bufferList[0].getChannelData(0); |
- task.done(); |
- }); |
- |
- bufferLoader.load(); |
-}); |
- |
-audit.define({ |
- label: 'test', |
- description: 'GainNode functionality' |
-}, function(task, should) { |
- |
- // Create a buffer for a short "note". |
- sinWaveBuffer = createSinWaveBuffer(bufferDurationSeconds, 880.0); |
- |
- // Render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1. |
- // The last note will be of gain 0.0, so shouldn't be perceptible in the |
- // rendered output. |
- for (let i = 0; i < numberOfNotes; ++i) { |
- let time = i * noteSpacing; |
- let gain = 1.0 - i / (numberOfNotes - 1); |
- playNote(time, gain); |
- } |
- |
- context.startRendering() |
- .then(buffer => { |
- let actual = buffer.getChannelData(0); |
- should(actual, 'Output from gain node').beCloseToArray(reference, { |
- absoluteThreshold: 3.0503e-5 |
- }); |
- let snr = 10 * Math.log10(computeSNR(actual, reference)); |
- should(snr, 'SNR (in dB)').beGreaterThanOrEqualTo(89.088); |
- let filename = 'gain-actual.wav'; |
- if (downloadAudioBuffer(buffer, filename)) |
- should(true, 'Saved reference file').message(filename, ""); |
- }) |
- .then(() => task.done()); |
- ; |
-}); |
- |
-audit.run(); |
-</script> |
- |
-</body> |
+ <head> |
+ <title> |
+ gain.html |
+ </title> |
+ <script src="../../resources/testharness.js"></script> |
+ <script src="../../resources/testharnessreport.js"></script> |
+ <script src="../resources/audit-util.js"></script> |
+ <script src="../resources/audit.js"></script> |
+ <script src="../resources/buffer-loader.js"></script> |
+ </head> |
+ <body> |
+ <script id="layout-test-code"> |
+ let audit = Audit.createTaskRunner(); |
+ |
+ let sampleRate = 44100.0; |
+ let bufferDurationSeconds = 0.125; |
+ let numberOfNotes = 11; |
+ let noteSpacing = bufferDurationSeconds + |
+ 0.020; // leave 20ms of silence between each "note" |
+ let lengthInSeconds = numberOfNotes * noteSpacing; |
+ |
+ let context = 0; |
+ let sinWaveBuffer = 0; |
+ let reference = 0; |
+ |
+ function createSinWaveBuffer(lengthInSeconds, frequency) { |
+ let audioBuffer = |
+ context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate); |
+ |
+ let n = audioBuffer.length; |
+ let channelL = audioBuffer.getChannelData(0); |
+ let channelR = audioBuffer.getChannelData(1); |
+ |
+ for (let i = 0; i < n; ++i) { |
+ channelL[i] = Math.sin(frequency * 2.0 * Math.PI * i / sampleRate); |
+ channelR[i] = channelL[i]; |
+ } |
+ |
+ return audioBuffer; |
+ } |
+ |
+ function playNote(time, gain) { |
+ let source = context.createBufferSource(); |
+ source.buffer = sinWaveBuffer; |
+ |
+ let gainNode = context.createGain(); |
+ gainNode.gain.value = gain; |
+ |
+ source.connect(gainNode); |
+ gainNode.connect(context.destination); |
+ |
+ source.start(time); |
+ } |
+ |
+ audit.define( |
+ {label: 'create context', description: 'Create context for test'}, |
+ function(task, should) { |
+ // Create offline audio context. |
+ context = new OfflineAudioContext( |
+ 2, sampleRate * lengthInSeconds, sampleRate); |
+ task.done(); |
+ }); |
+ |
+ audit.define( |
+ {label: 'load-ref', description: 'Load reference audio file'}, |
+ function(task, should) { |
+ let bufferLoader = |
+ new BufferLoader(context, ['gain-expected.wav'], bufferList => { |
+ reference = bufferList[0].getChannelData(0); |
+ task.done(); |
+ }); |
+ |
+ bufferLoader.load(); |
+ }); |
+ |
+ audit.define( |
+ {label: 'test', description: 'GainNode functionality'}, |
+ function(task, should) { |
+ |
+ // Create a buffer for a short "note". |
+ sinWaveBuffer = createSinWaveBuffer(bufferDurationSeconds, 880.0); |
+ |
+ // Render 11 notes, starting at a gain of 1.0, decreasing in gain by |
+ // 0.1. The last note will be of gain 0.0, so shouldn't be |
+ // perceptible in the rendered output. |
+ for (let i = 0; i < numberOfNotes; ++i) { |
+ let time = i * noteSpacing; |
+ let gain = 1.0 - i / (numberOfNotes - 1); |
+ playNote(time, gain); |
+ } |
+ |
+ context.startRendering() |
+ .then(buffer => { |
+ let actual = buffer.getChannelData(0); |
+ should(actual, 'Output from gain node') |
+ .beCloseToArray( |
+ reference, {absoluteThreshold: 3.0503e-5}); |
+ let snr = 10 * Math.log10(computeSNR(actual, reference)); |
+ should(snr, 'SNR (in dB)').beGreaterThanOrEqualTo(89.088); |
+ let filename = 'gain-actual.wav'; |
+ if (downloadAudioBuffer(buffer, filename)) |
+ should(true, 'Saved reference file').message(filename, ''); |
+ }) |
+ .then(() => task.done()); |
+ ; |
+ }); |
+ |
+ audit.run(); |
+ </script> |
+ </body> |
</html> |