1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <script src="resources/audio-testing.js"></script>
5 <script src="resources/note-grain-on-testing.js"></script>
6 <script src="../fast/js/resources/js-test-pre.js"></script>
10 <div id="description"></div>
11 <div id="console"></div>
14 description("Test noteGrainOn offset rendering.");
16 // To test noteGrainOn, a single ramp signal is created.
17 // Various sections of the ramp are rendered by noteGrainOn() at
18 // different times, and we verify that the actual output
19 // consists of the correct section of the ramp at the correct
24 // Array of the grain offset used for each ramp played.
25 var grainOffsetTime = [];
27 // Verify the received signal is a ramp from the correct section
28 // of our ramp signal.
29 function verifyGrain(renderedData, startFrame, endFrame, grainIndex) {
30 var grainOffsetFrame = timeToSampleFrame(grainOffsetTime[grainIndex], sampleRate);
31 var grainFrameLength = endFrame - startFrame;
32 var ramp = linearRampBuffer.getChannelData(0);
39 for (var k = 0; k < grainFrameLength; ++k) {
40 if (renderedData[startFrame + k] != ramp[grainOffsetFrame + k]) {
41 expected = ramp[grainOffsetFrame + k];
42 actual = renderedData[startFrame + k];
43 frame = startFrame + k;
48 return { verified: isCorrect,
54 function checkResult(event) {
55 var buffer = event.renderedBuffer;
56 renderedData = buffer.getChannelData(0);
57 var nSamples = renderedData.length;
61 // Number of grains that we found that have incorrect data.
62 var invalidGrainDataCount = 0;
64 var startEndFrames = findStartAndEndSamples(renderedData);
66 // Verify the start and stop times. Not strictly needed for
67 // this test, but it's useful to know that if the ramp data
68 // appears to be incorrect.
69 success = success && verifyStartAndEndFrames(startEndFrames);
71 // Loop through each of the rendered grains and check that
72 // each grain contains our expected ramp.
73 for (var k = 0; k < startEndFrames.start.length; ++k) {
74 // Verify that the rendered data matches the expected
75 // section of our ramp signal.
76 var result = verifyGrain(renderedData, startEndFrames.start[k], startEndFrames.end[k], k);
78 if (!result.verified) {
79 testFailed("Grain " + k + " incorrect. Expected " + result.expected + " but received " + result.actual + " at sample frame " + result.frame);
80 ++invalidGrainDataCount;
85 if (!invalidGrainDataCount) {
86 testPassed("All " + numberOfTests + " grains contained the correct data.");
88 testFailed(invalidGrainDataCount + " grains out of " + numberOfTests + " did not contain the expected data.");
93 testPassed("noteGrainOn offset rendering tests passed.");
95 testFailed("noteGrainOn offset rendering tests failed.");
102 if (window.testRunner) {
103 testRunner.dumpAsText();
104 testRunner.waitUntilDone();
107 window.jsTestIsAsync = true;
109 // Create offline audio context.
110 context = new webkitOfflineAudioContext(2, sampleRate * renderTime, sampleRate);
112 // Create a linear ramp for testing noteGrainOn.
113 linearRampBuffer = createSignalBuffer(context,
115 // Want the ramp to start
120 var grainInfo = playAllGrains(context, linearRampBuffer, numberOfTests);
122 grainOffsetTime = grainInfo.grainOffsetTimes;
124 context.oncomplete = checkResult;
125 context.startRendering();
129 successfullyParsed = true;
133 <script src="../fast/js/resources/js-test-post.js"></script>