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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/audioparam-negative-exponentialRamp.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 <html>
3 <head>
4 <script src="../resources/js-test.js"></script>
5 <script src="resources/compatibility.js"></script>
6 <script src="resources/audit-util.js"></script>
7 <script src="resources/audio-testing.js"></script>
8 <title>Test Negative AudioParam.exponentialRampToValueAtTime</title>
9 </head>
10
11 <body>
12 <script>
13 description("Test AudioParam.exponentialRampToValueAtTime() with Negative Values.");
14 window.jsTestIsAsync = true;
15
16 var sampleRate = 48000;
17
18 var audit = Audit.createTaskRunner();
19
20 audit.defineTask("both negative values", function (done) {
21 var renderDuration = 0.125;
22
23 // Create context with two channels. Channel 0 contains the positive-va lued exponential and
24 // channel 1 contains the negative-valued exponential. We'll compare th e two channels to
25 // verify that they're the same, as they should be.
26 var context = new OfflineAudioContext(2, renderDuration * sampleRate, sa mpleRate);
27 var source = context.createBufferSource();
28 source.buffer = createConstantBuffer(context, 1, 1);
29 source.loop = true;
30
31 // Gain node gp is for the positive-valued exponential ramp, and gn is f or the negative-valued
32 // exponential ramp.
33 var gp = context.createGain();
34 var gn = context.createGain();
35 var merger = context.createChannelMerger(2);
36
37 source.connect(gp)
38 .connect(merger, 0, 0);
39 source.connect(gn)
40 .connect(merger, 0, 1);
41 merger.connect(context.destination);
42
43 gp.gain.setValueAtTime(1, 0);
44 gp.gain.exponentialRampToValueAtTime(2, renderDuration);
45
46 gn.gain.setValueAtTime(-1, 0);
47 gn.gain.exponentialRampToValueAtTime(-2, renderDuration);
48
49 source.start();
50
51 context.startRendering().then(function (resultBuffer) {
52 // Verify that channels have the same values, except for the sign.
53 var expected = resultBuffer.getChannelData(0);
54 var actual = resultBuffer.getChannelData(1);
55 var inverted = expected.map(sample => -sample);
56
57 Should("Negative exponential ramp from -1 to -2", actual)
58 .beEqualToArray(inverted);
59 }).then(done);
60 });
61
62 audit.defineTask("negative-end", function (done) {
63 // Positive start value and negative end value should just do nothing.
64 var renderDuration = 0.125;
65 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa mpleRate);
66 var source = context.createBufferSource();
67 source.buffer = createConstantBuffer(context, 1, 1);
68 source.loop = true;
69
70 // Gain node gp is for the positive-valued exponential ramp, and gn is f or the negative-valued
71 // exponential ramp.
72 var g = context.createGain();
73
74 g.gain.setValueAtTime(2, 0);
75 g.gain.exponentialRampToValueAtTime(-1, renderDuration);
76
77 source.connect(g)
78 .connect(context.destination);
79
80 source.start();
81
82 context.startRendering().then(function (resultBuffer) {
83 var actual = resultBuffer.getChannelData(0);
84
85 Should("Exponential ramp from 2 to -1", actual)
86 .beConstantValueOf(2);
87 }).then(done);
88 });
89
90 audit.defineTask("positive-end", function (done) {
91 // Positive start value and negative end value should just do nothing.
92 var renderDuration = 0.125;
93 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa mpleRate);
94 var source = context.createBufferSource();
95 source.buffer = createConstantBuffer(context, 1, 1);
96 source.loop = true;
97
98 var g = context.createGain();
99
100 g.gain.setValueAtTime(-1, 0);
101 g.gain.exponentialRampToValueAtTime(1, renderDuration);
102
103 source.connect(g)
104 .connect(context.destination);
105 source.start();
106
107 context.startRendering().then(function (resultBuffer) {
108 var actual = resultBuffer.getChannelData(0);
109
110 Should("Exponential ramp from -1 to 1", actual)
111 .beConstantValueOf(-1);
112 }).then(done);
113 });
114
115 audit.defineTask("propagate", function (done) {
116 // Test propagation of ramp if the exponential ramp start and end values have opposite sign.
117 var renderDuration = 0.125;
118 var linearRampEnd = renderDuration / 4;
119 var exponentialRampEnd = renderDuration / 2;
120
121 var context = new OfflineAudioContext(1, renderDuration * sampleRate, sa mpleRate);
122 var source = context.createBufferSource();
123 source.buffer = createConstantBuffer(context, 1, 1);
124 source.loop = true;
125
126 var g = context.createGain();
127
128 g.gain.setValueAtTime(2, 0);
129 g.gain.linearRampToValueAtTime(-1, linearRampEnd);
130 g.gain.exponentialRampToValueAtTime(1, exponentialRampEnd);
131
132 source.connect(g)
133 .connect(context.destination);
134 source.start();
135
136 context.startRendering().then(function (resultBuffer) {
137 var actual = resultBuffer.getChannelData(0);
138
139 // Since the start value of the exponential ramp is -1 and the end val ue is 1, the ramp
140 // should just propagate -1 from the end of the linear ramp "forever".
141 var endFrame = Math.ceil(linearRampEnd * sampleRate);
142 Should("Exponential ramp from -1 to 1 after the end of the linear ramp ",
143 actual.slice(endFrame))
144 .beConstantValueOf(-1);
145 }).then(done);
146
147 });
148
149 audit.defineTask("finish", function (done) {
150 finishJSTest();
151 done();
152 });
153
154 audit.runTasks();
155 </script>
156 </body>
157 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698