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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/Gain/gain.html

Issue 2671883002: Convert GainNode tests to testharness (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/Gain/gain-basic.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 2
3 <!-- 3 <!--
4 Tests that GainNode is properly scaling the gain. 4 Tests that GainNode is properly scaling the gain.
5 We'll render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1. 5 We'll render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1.
6 The 11th note will be of gain 0.0, so it should be silent (at the end in the ren dered output). 6 The 11th note will be of gain 0.0, so it should be silent (at the end in the ren dered output).
7 --> 7 -->
8 8
9 <html> 9 <html>
10 <head> 10 <head>
11 <script src="../../resources/testharness.js"></script>
12 <script src="../../resources/testharnessreport.js"></script>
11 <script src="../resources/audit-util.js"></script> 13 <script src="../resources/audit-util.js"></script>
12 <script src="../resources/audio-testing.js"></script> 14 <script src="../resources/audit.js"></script>
13 15 <script src="../resources/buffer-loader.js"></script>
14 </head> 16 </head>
15 <body> 17 <body>
16 18
17 <script> 19 <script>
20 let audit = Audit.createTaskRunner();
18 21
19 window.onload = init; 22 let sampleRate = 44100.0;
23 let bufferDurationSeconds = 0.125;
24 let numberOfNotes = 11;
25 let noteSpacing =
26 bufferDurationSeconds + 0.020; // leave 20ms of silence between each "note"
27 let lengthInSeconds = numberOfNotes * noteSpacing;
20 28
21 var sampleRate = 44100.0; 29 let context = 0;
22 var bufferDurationSeconds = 0.125; 30 let sinWaveBuffer = 0;
23 var numberOfNotes = 11; 31 let reference = 0;
24 var noteSpacing = bufferDurationSeconds + 0.020; // leave 20ms of silence betwee n each "note"
25 var lengthInSeconds = numberOfNotes * noteSpacing;
26
27 var context = 0;
28 var sinWaveBuffer = 0;
29 32
30 function createSinWaveBuffer(lengthInSeconds, frequency) { 33 function createSinWaveBuffer(lengthInSeconds, frequency) {
31 var audioBuffer = context.createBuffer(2, lengthInSeconds * sampleRate, samp leRate); 34 let audioBuffer =
35 context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate);
32 36
33 var n = audioBuffer.length; 37 let n = audioBuffer.length;
34 var channelL = audioBuffer.getChannelData(0); 38 let channelL = audioBuffer.getChannelData(0);
35 var channelR = audioBuffer.getChannelData(1); 39 let channelR = audioBuffer.getChannelData(1);
36 40
37 for (var i = 0; i < n; ++i) { 41 for (let i = 0; i < n; ++i) {
38 channelL[i] = Math.sin(frequency * 2.0*Math.PI * i / sampleRate); 42 channelL[i] = Math.sin(frequency * 2.0 * Math.PI * i / sampleRate);
39 channelR[i] = channelL[i]; 43 channelR[i] = channelL[i];
40 } 44 }
41 45
42 return audioBuffer; 46 return audioBuffer;
43 } 47 }
44 48
45 function playNote(time, gain) { 49 function playNote(time, gain) {
46 var source = context.createBufferSource(); 50 let source = context.createBufferSource();
47 source.buffer = sinWaveBuffer; 51 source.buffer = sinWaveBuffer;
48 52
49 var gainNode = context.createGain(); 53 let gainNode = context.createGain();
50 gainNode.gain.value = gain; 54 gainNode.gain.value = gain;
51 55
52 source.connect(gainNode); 56 source.connect(gainNode);
53 gainNode.connect(context.destination); 57 gainNode.connect(context.destination);
54 58
55 source.start(time); 59 source.start(time);
56 } 60 }
57 61
58 function init() { 62 audit.define('create context', function(task, should) {
59 if (!window.testRunner) 63 task.describe('Create context for test');
60 return; 64 // Create offline audio context.
65 context =
66 new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
67 task.done();
68 });
61 69
62 // Create offline audio context. 70 audit.define('load-ref', function(task, should) {
63 context = new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRat e); 71 task.describe('Load reference audio file');
72 let bufferLoader =
73 new BufferLoader(context, ['gain-expected.wav'], bufferList => {
74 reference = bufferList[0].getChannelData(0);
75 task.done();
76 });
64 77
65 // Create a buffer for a short "note". 78 bufferLoader.load();
66 sinWaveBuffer = createSinWaveBuffer(bufferDurationSeconds, 880.0); 79 });
67 80
68 // Render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1. 81 audit.define('test', function(task, should) {
69 // The last note will be of gain 0.0, so shouldn't be perceptible in the ren dered output. 82 task.describe('GainNode functionality');
70 for (var i = 0; i < numberOfNotes; ++i) {
71 var time = i * noteSpacing;
72 var gain = 1.0 - i / (numberOfNotes - 1);
73 playNote(time, gain);
74 }
75 83
76 context.oncomplete = finishAudioTest; 84 // Create a buffer for a short "note".
77 context.startRendering(); 85 sinWaveBuffer = createSinWaveBuffer(bufferDurationSeconds, 880.0);
78 86
79 testRunner.waitUntilDone(); 87 // Render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1.
80 } 88 // The last note will be of gain 0.0, so shouldn't be perceptible in the
89 // rendered output.
90 for (let i = 0; i < numberOfNotes; ++i) {
91 let time = i * noteSpacing;
92 let gain = 1.0 - i / (numberOfNotes - 1);
93 playNote(time, gain);
94 }
81 95
96 context.startRendering()
97 .then(buffer => {
98 let actual = buffer.getChannelData(0);
99 should(actual, 'Output from gain node').beCloseToArray(reference, {
100 absoluteThreshold: 3.0503e-5
101 });
102 let snr = 10 * Math.log10(computeSNR(actual, reference));
103 should(snr, 'SNR (in dB)').beGreaterThanOrEqualTo(89.088);
104 })
105 .then(task.done.bind(task));
hongchan 2017/02/06 17:34:28 task => task.done()
106 ;
107 });
108
109 audit.run();
82 </script> 110 </script>
83 111
84 </body> 112 </body>
85 </html> 113 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/Gain/gain-basic.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698