Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / webaudio / gain.html
blob373d18c1d5bc66e280649a3f956fc7e20267660b
1 <!DOCTYPE html>
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 rendered output).
7 -->
9 <html>
10 <head>
11 <script type="text/javascript" src="resources/audio-testing.js"></script>
13 </head>
14 <body>
16 <script>
18 window.onload = init;
20 var sampleRate = 44100.0;
21 var bufferDurationSeconds = 0.125;
22 var numberOfNotes = 11;
23 var noteSpacing = bufferDurationSeconds + 0.020; // leave 20ms of silence between each "note"
24 var lengthInSeconds = numberOfNotes * noteSpacing;
26 var context = 0;
27 var sinWaveBuffer = 0;
29 function createSinWaveBuffer(lengthInSeconds, frequency) {
30 var audioBuffer = context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate);
32 var n = audioBuffer.length;
33 var channelL = audioBuffer.getChannelData(0);
34 var channelR = audioBuffer.getChannelData(1);
36 for (var i = 0; i < n; ++i) {
37 channelL[i] = Math.sin(frequency * 2.0*Math.PI * i / sampleRate);
38 channelR[i] = channelL[i];
41 return audioBuffer;
44 function playNote(time, gain) {
45 var source = context.createBufferSource();
46 source.buffer = sinWaveBuffer;
48 var gainNode = context.createGain();
49 gainNode.gain.value = gain;
51 source.connect(gainNode);
52 gainNode.connect(context.destination);
54 source.start(time);
57 function init() {
58 if (!window.testRunner)
59 return;
61 // Create offline audio context.
62 context = new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
64 // Create a buffer for a short "note".
65 sinWaveBuffer = createSinWaveBuffer(bufferDurationSeconds, 880.0);
67 // Render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1.
68 // The last note will be of gain 0.0, so shouldn't be perceptible in the rendered output.
69 for (var i = 0; i < numberOfNotes; ++i) {
70 var time = i * noteSpacing;
71 var gain = 1.0 - i / (numberOfNotes - 1);
72 playNote(time, gain);
75 context.oncomplete = finishAudioTest;
76 context.startRendering();
78 testRunner.waitUntilDone();
81 </script>
83 </body>
84 </html>