Changeset 106612 in webkit


Ignore:
Timestamp:
Feb 2, 2012 6:40:49 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

noteGrainOn needs more tests
https://bugs.webkit.org/show_bug.cgi?id=77225

Patch by Raymond Toy <Raymond Toy> on 2012-02-02
Reviewed by Kenneth Russell.

  • webaudio/note-grain-on-play.html: Added.
  • webaudio/note-grain-on-play-expected.txt: Added.
  • webaudio/note-grain-on-timing.html: Refactored to use new

functions in note-grain-on-testing.js.

  • webaudio/note-grain-on-timing-expected.txt: Updated.
  • webaudio/resources/audio-testing.js:

(grainLengthInSampleFrames): Utility to compute length of a grain
in samples.

  • webaudio/resources/note-grain-on-testing.js: Added.

(createSignalBuffer):
(findStartAndEndSamples):
(playGrain):
(playAllGrains):
(verifyStarAndtEndTimes): Common functions for note-grain-on-play and
note-grain-on-timing tests to use.

Location:
trunk/LayoutTests
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r106611 r106612  
     12012-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
    1242012-02-02  Raymond Toy  <rtoy@google.com>
    225
  • trunk/LayoutTests/webaudio/note-grain-on-timing-expected.txt

    r106162 r106612  
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
    44
    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.
     5PASS Found all 100 grains.
     6PASS All 100 grains started at the correct time.
     7PASS All 100 grains ended at the correct time.
    88PASS noteGrainOn timing tests passed.
    99PASS successfullyParsed is true
  • trunk/LayoutTests/webaudio/note-grain-on-timing.html

    r106162 r106612  
    33  <head>
    44    <script src="resources/audio-testing.js"></script>
     5    <script src="resources/note-grain-on-testing.js"></script>
    56    <script src="../fast/js/resources/js-test-pre.js"></script>
    67  </head>
     
    1314      description("Test timing of noteGrainOn.");
    1415
    15       var sampleRate = 44100.0;
     16      var squarePulseBuffer;
    1617
    17       // HRTF extra frames.  This is a magic constant currently in
    18       // AudioBufferSourceNode::process that always extends the
    19       // duration by this number of samples.  See bug 77224
    20       // (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 played
    27       var duration = 0.01;
    28 
    29       // Time step between the start of each square pulse.  We need to
    30       // add a little bit of silence so we can detect pulse boundaries
    31       // 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 the
    46           // possible grain offsets still results in a square pulse of
    47           // of the requested duration.  (The extra 1 is for any
    48           // 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      
    6618      function checkResult(event) {
    6719          var buffer = event.renderedBuffer;
     
    7022
    7123          var success = true;
    72           var errorCountStart = 0;
    73           var errorCountEnd = 0;
    7424     
    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);
    9926
    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);
    10428
    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 our
    112           // 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 frames
    116               // 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      
    15729          if (success) {
    15830              testPassed("noteGrainOn timing tests passed.");
     
    16234
    16335          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 a
    171           // particular time.  See bug 77225
    172           // (https://bugs.webkit.org/show_bug.cgi?id=77225).
    173           bufferSource.noteGrainOn(time, grainOffset, duration);
    17436      }
    17537
     
    18446          // Create offline audio context.
    18547          context = new webkitAudioContext(2, sampleRate * renderTime, sampleRate);
    186           createSquarePulse(context);   
    18748
    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);
    19252
    19353          context.oncomplete = checkResult;
  • trunk/LayoutTests/webaudio/resources/audio-testing.js

    r106162 r106612  
    126126}
    127127
     128// Compute the number of sample frames consumed by noteGrainOn with
     129// the specified |grainOffset|, |duration|, and |sampleRate|.
     130function 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.