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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/note-grain-on-testing.js

Issue 2839063003: Implement tail processing for AudioNodes (Closed)
Patch Set: Make declaration order consistent Created 3 years, 5 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
OLDNEW
1 let sampleRate = 44100.0; 1 let sampleRate = 44100.0;
2 2
3 // HRTF extra frames. This is a magic constant currently in
4 // AudioBufferSourceNode::process that always extends the
5 // duration by this number of samples. See bug 77224
6 // (https://bugs.webkit.org/show_bug.cgi?id=77224).
7 let extraFramesHRTF = 512;
8
9 // How many grains to play. 3 // How many grains to play.
10 let numberOfTests = 100; 4 let numberOfTests = 100;
11 5
12 // Duration of each grain to be played 6 // Duration of each grain to be played
13 let duration = 0.01; 7 let duration = 0.01;
14 8
15 // Time step between the start of each grain. We need to add a little 9 // Time step between the start of each grain. We need to add a little
16 // bit of silence so we can detect grain boundaries and also account 10 // bit of silence so we can detect grain boundaries
17 // for the extra frames for HRTF. 11 let timeStep = duration + .005;
18 let timeStep = duration + .005 + extraFramesHRTF / sampleRate;
19 12
20 // Time step between the start for each grain. 13 // Time step between the start for each grain.
21 let grainOffsetStep = 0.001; 14 let grainOffsetStep = 0.001;
22 15
23 // How long to render to cover all of the grains. 16 // How long to render to cover all of the grains.
24 let renderTime = (numberOfTests + 1) * timeStep; 17 let renderTime = (numberOfTests + 1) * timeStep;
25 18
26 let context; 19 let context;
27 let renderedData; 20 let renderedData;
28 21
29 // Create a buffer containing the data that we want. The function f 22 // Create a buffer containing the data that we want. The function f
30 // returns the desired value at sample frame k. 23 // returns the desired value at sample frame k.
31 function createSignalBuffer(context, f) { 24 function createSignalBuffer(context, f) {
32 // Make sure the buffer has enough data for all of the possible 25 // Make sure the buffer has enough data for all of the possible
33 // grain offsets and durations. Need to include the extra frames 26 // grain offsets and durations. The additional 1 is for any
34 // for HRTF. The additional 1 is for any round-off errors. 27 // round-off errors.
35 let signalLength = Math.floor( 28 let signalLength =
36 1 + extraFramesHRTF + 29 Math.floor(1 + sampleRate * (numberOfTests * grainOffsetStep + duration));
37 sampleRate * (numberOfTests * grainOffsetStep + duration));
38 30
39 let buffer = context.createBuffer(2, signalLength, sampleRate); 31 let buffer = context.createBuffer(2, signalLength, sampleRate);
40 let data = buffer.getChannelData(0); 32 let data = buffer.getChannelData(0);
41 33
42 for (let k = 0; k < signalLength; ++k) { 34 for (let k = 0; k < signalLength; ++k) {
43 data[k] = f(k); 35 data[k] = f(k);
44 } 36 }
45 37
46 return buffer; 38 return buffer;
47 } 39 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 startFrames.length == endFrames.length, 'Found all grain starts and ends') 113 startFrames.length == endFrames.length, 'Found all grain starts and ends')
122 .beTrue(); 114 .beTrue();
123 115
124 should(startFrames.length, 'Number of start frames').beEqualTo(numberOfTests); 116 should(startFrames.length, 'Number of start frames').beEqualTo(numberOfTests);
125 should(endFrames.length, 'Number of end frames').beEqualTo(numberOfTests); 117 should(endFrames.length, 'Number of end frames').beEqualTo(numberOfTests);
126 118
127 // Examine the start and stop times to see if they match our 119 // Examine the start and stop times to see if they match our
128 // expectations. 120 // expectations.
129 for (let k = 0; k < startFrames.length; ++k) { 121 for (let k = 0; k < startFrames.length; ++k) {
130 let expectedStart = timeToSampleFrame(k * timeStep, sampleRate); 122 let expectedStart = timeToSampleFrame(k * timeStep, sampleRate);
131 // The end point is the duration, plus the extra frames 123 // The end point is the duration.
132 // for HRTF. 124 let expectedEnd = expectedStart +
133 let expectedEnd = extraFramesHRTF + expectedStart +
134 grainLengthInSampleFrames(k * grainOffsetStep, duration, sampleRate); 125 grainLengthInSampleFrames(k * grainOffsetStep, duration, sampleRate);
135 126
136 if (startFrames[k] != expectedStart) 127 if (startFrames[k] != expectedStart)
137 ++errorCountStart; 128 ++errorCountStart;
138 if (endFrames[k] != expectedEnd) 129 if (endFrames[k] != expectedEnd)
139 ++errorCountEnd; 130 ++errorCountEnd;
140 131
141 should([startFrames[k], endFrames[k]], 'Pulse ' + k + ' boundary') 132 should([startFrames[k], endFrames[k]], 'Pulse ' + k + ' boundary')
142 .beEqualToArray([expectedStart, expectedEnd]); 133 .beEqualToArray([expectedStart, expectedEnd]);
143 } 134 }
(...skipping 15 matching lines...) Expand all
159 should(endFrames.length, 'Number of grains that ended at the correct time') 150 should(endFrames.length, 'Number of grains that ended at the correct time')
160 .beEqualTo(numberOfTests); 151 .beEqualTo(numberOfTests);
161 } else { 152 } else {
162 should( 153 should(
163 errorCountEnd, 154 errorCountEnd,
164 'Number of grains out of ' + numberOfTests + 155 'Number of grains out of ' + numberOfTests +
165 ' that ended at the wrong time') 156 ' that ended at the wrong time')
166 .beEqualTo(0); 157 .beEqualTo(0);
167 } 158 }
168 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698