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

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

Issue 2581463002: Refactor WebAudio test directory (Closed)
Patch Set: Use correct path for wav result files Created 4 years 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
OLDNEW
(Empty)
1 <!DOCTYPE html>
2
3 <!--
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.
6 The 11th note will be of gain 0.0, so it should be silent (at the end in the ren dered output).
7 -->
8
9 <html>
10 <head>
11 <script src="resources/audit-util.js"></script>
12 <script src="resources/audio-testing.js"></script>
13
14 </head>
15 <body>
16
17 <script>
18
19 window.onload = init;
20
21 var sampleRate = 44100.0;
22 var bufferDurationSeconds = 0.125;
23 var numberOfNotes = 11;
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
30 function createSinWaveBuffer(lengthInSeconds, frequency) {
31 var audioBuffer = context.createBuffer(2, lengthInSeconds * sampleRate, samp leRate);
32
33 var n = audioBuffer.length;
34 var channelL = audioBuffer.getChannelData(0);
35 var channelR = audioBuffer.getChannelData(1);
36
37 for (var i = 0; i < n; ++i) {
38 channelL[i] = Math.sin(frequency * 2.0*Math.PI * i / sampleRate);
39 channelR[i] = channelL[i];
40 }
41
42 return audioBuffer;
43 }
44
45 function playNote(time, gain) {
46 var source = context.createBufferSource();
47 source.buffer = sinWaveBuffer;
48
49 var gainNode = context.createGain();
50 gainNode.gain.value = gain;
51
52 source.connect(gainNode);
53 gainNode.connect(context.destination);
54
55 source.start(time);
56 }
57
58 function init() {
59 if (!window.testRunner)
60 return;
61
62 // Create offline audio context.
63 context = new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRat e);
64
65 // Create a buffer for a short "note".
66 sinWaveBuffer = createSinWaveBuffer(bufferDurationSeconds, 880.0);
67
68 // Render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1.
69 // The last note will be of gain 0.0, so shouldn't be perceptible in the ren dered output.
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
76 context.oncomplete = finishAudioTest;
77 context.startRendering();
78
79 testRunner.waitUntilDone();
80 }
81
82 </script>
83
84 </body>
85 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698