Changeset 106612 in webkit
- Timestamp:
- Feb 2, 2012 6:40:49 PM (12 years ago)
- Location:
- trunk/LayoutTests
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r106611 r106612 1 2012-02-02 Raymond Toy <rtoy@google.com> 2 3 noteGrainOn needs more tests 4 https://bugs.webkit.org/show_bug.cgi?id=77225 5 6 Reviewed by Kenneth Russell. 7 8 * webaudio/note-grain-on-play.html: Added. 9 * webaudio/note-grain-on-play-expected.txt: Added. 10 * webaudio/note-grain-on-timing.html: Refactored to use new 11 functions in note-grain-on-testing.js. 12 * webaudio/note-grain-on-timing-expected.txt: Updated. 13 * webaudio/resources/audio-testing.js: 14 (grainLengthInSampleFrames): Utility to compute length of a grain 15 in samples. 16 * webaudio/resources/note-grain-on-testing.js: Added. 17 (createSignalBuffer): 18 (findStartAndEndSamples): 19 (playGrain): 20 (playAllGrains): 21 (verifyStarAndtEndTimes): Common functions for note-grain-on-play and 22 note-grain-on-timing tests to use. 23 1 24 2012-02-02 Raymond Toy <rtoy@google.com> 2 25 -
trunk/LayoutTests/webaudio/note-grain-on-timing-expected.txt
r106162 r106612 3 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 4 4 5 PASS Found all 100 pulses.6 PASS All 100 square pulses started at the correct time.7 PASS All 100 square pulses ended at the correct time.5 PASS Found all 100 grains. 6 PASS All 100 grains started at the correct time. 7 PASS All 100 grains ended at the correct time. 8 8 PASS noteGrainOn timing tests passed. 9 9 PASS successfullyParsed is true -
trunk/LayoutTests/webaudio/note-grain-on-timing.html
r106162 r106612 3 3 <head> 4 4 <script src="resources/audio-testing.js"></script> 5 <script src="resources/note-grain-on-testing.js"></script> 5 6 <script src="../fast/js/resources/js-test-pre.js"></script> 6 7 </head> … … 13 14 description("Test timing of noteGrainOn."); 14 15 15 var s ampleRate = 44100.0;16 var squarePulseBuffer; 16 17 17 // HRTF extra frames. This is a magic constant currently in18 // AudioBufferSourceNode::process that always extends the19 // duration by this number of samples. See bug 7722420 // (https://bugs.webkit.org/show_bug.cgi?id=77224).21 var extraFramesHRTF = 512;22 23 // How many square pulses to play.24 var numberOfTests = 100;25 26 // Duration of the square pulse to be played27 var duration = 0.01;28 29 // Time step between the start of each square pulse. We need to30 // add a little bit of silence so we can detect pulse boundaries31 // and also account for the extra frames for HRTF.32 var timeStep = duration + .005 + extraFramesHRTF / sampleRate;33 34 // Time step between the grain start for each square pulse.35 var grainOffsetStep = 0.005;36 37 // How long to render to cover all of the pulses.38 var renderTime = (numberOfTests + 1) * timeStep;39 40 var context;41 var squarePulseBuffer;42 var renderedData;43 44 function createSquarePulse(context) {45 // Create a square pulse that is long enough so that all the46 // possible grain offsets still results in a square pulse of47 // of the requested duration. (The extra 1 is for any48 // round-off.)49 50 var pulseLength = Math.floor(1 + extraFramesHRTF + sampleRate * (numberOfTests * grainOffsetStep + duration));51 52 squarePulseBuffer = context.createBuffer(2, pulseLength, sampleRate);53 var data = squarePulseBuffer.getChannelData(0);54 for (var k = 0; k < pulseLength; ++k) {55 data[k] = 1;56 }57 }58 59 function trueGrainLength(grainOffset, duration) {60 var startFrame = timeToSampleFrame(grainOffset, sampleRate);61 var endFrame = timeToSampleFrame(grainOffset + duration, sampleRate);62 63 return endFrame - startFrame;64 }65 66 18 function checkResult(event) { 67 19 var buffer = event.renderedBuffer; … … 70 22 71 23 var success = true; 72 var errorCountStart = 0;73 var errorCountEnd = 0;74 24 75 var startTime = []; 76 var endTime = []; 77 var lookForStart = true; 78 79 // Look through the rendered data to find the start and stop 80 // times of each pulse. 81 for (var k = 0; k < nSamples; ++k) { 82 if (lookForStart) { 83 // Find a non-zero point and record it. We're not 84 // concerned with the value in this test, only that 85 // the pulse started here. Other tests should cover 86 // this case. 87 if (renderedData[k] > 0) { 88 startTime.push(k); 89 lookForStart = false; 90 } 91 } else { 92 // Find a zero and record it. 93 if (renderedData[k] == 0) { 94 endTime.push(k); 95 lookForStart = true; 96 } 97 } 98 } 25 var startEndFrames = findStartAndEndSamples(renderedData); 99 26 100 if (startTime.length != endTime.length) { 101 testFailed("Could not find the beginning or end of a square pulse."); 102 success = false; 103 } 27 success = success && verifyStartAndEndFrames(startEndFrames); 104 28 105 if (startTime.length == numberOfTests && endTime.length == numberOfTests) {106 testPassed("Found all " + numberOfTests + " pulses.");107 } else {108 testFailed("Did not find all " + numberOfTests + " pulses.");109 }110 111 // Examine the start and stop times to see if they match our112 // expectations.113 for (var k = 0; k < startTime.length; ++k) {114 var expectedStart = timeToSampleFrame(k * timeStep, sampleRate);115 // The end point is the duration, plus the extra frames116 // for HRTF.117 var expectedEnd = extraFramesHRTF + expectedStart + trueGrainLength(k * grainOffsetStep, duration);118 119 if (startTime[k] != expectedStart) {120 testFailed("Pulse " + k + " started at " + startTime[k] + " but expected at " + expectedStart);121 ++errorCountStart;122 success = false;123 }124 125 if (endTime[k] != expectedEnd) {126 testFailed("Pulse " + k + " ended at " + endTime[k] + " but expected at " + expectedEnd);127 ++errorCountEnd;128 success = false;129 }130 }131 132 if (!errorCountStart) {133 if (startTime.length == numberOfTests) {134 testPassed("All " + numberOfTests + " square pulses started at the correct time.");135 } else {136 testFailed("All pulses started at the correct time, but only " + startTime.length + " pulses found.");137 success = false;138 }139 } else {140 testFailed(errorCountStart + " out of " + numberOfTests + " square pulses started at the wrong time.");141 success = false;142 }143 144 if (!errorCountEnd) {145 if (endTime.length == numberOfTests) {146 testPassed("All " + numberOfTests + " square pulses ended at the correct time.");147 } else {148 testFailed("All pulses ended at the correct time, but only " + endTime.length + " pulses found.");149 success = false;150 }151 } else {152 testFailed(errorCountEnd + " out of " + numberOfTests + " square pulses ended at the wrong time.");153 success = false;154 }155 156 157 29 if (success) { 158 30 testPassed("noteGrainOn timing tests passed."); … … 162 34 163 35 finishJSTest(); 164 }165 166 function playNote(time, grainOffset, duration) {167 var bufferSource = context.createBufferSource();168 bufferSource.buffer = squarePulseBuffer;169 bufferSource.connect(context.destination);170 // We're only testing that the source starts and ends at a171 // particular time. See bug 77225172 // (https://bugs.webkit.org/show_bug.cgi?id=77225).173 bufferSource.noteGrainOn(time, grainOffset, duration);174 36 } 175 37 … … 184 46 // Create offline audio context. 185 47 context = new webkitAudioContext(2, sampleRate * renderTime, sampleRate); 186 createSquarePulse(context);187 48 188 for (var i = 0; i < numberOfTests; ++i) { 189 var timeOffset = timeStep * i; 190 playNote(timeOffset, i * grainOffsetStep, duration); 191 } 49 squarePulseBuffer = createSignalBuffer(context, function (k) { return 1 }); 50 51 playAllGrains(context, squarePulseBuffer, numberOfTests); 192 52 193 53 context.oncomplete = checkResult; -
trunk/LayoutTests/webaudio/resources/audio-testing.js
r106162 r106612 126 126 } 127 127 128 // Compute the number of sample frames consumed by noteGrainOn with 129 // the specified |grainOffset|, |duration|, and |sampleRate|. 130 function grainLengthInSampleFrames(grainOffset, duration, sampleRate) { 131 var startFrame = timeToSampleFrame(grainOffset, sampleRate); 132 var endFrame = timeToSampleFrame(grainOffset + duration, sampleRate); 133 134 return endFrame - startFrame; 135 }
Note: See TracChangeset
for help on using the changeset viewer.