Skip to content
  • commit-queue@webkit.org's avatar
    Round time to sample frame · 5b585ab6
    commit-queue@webkit.org authored
    https://bugs.webkit.org/show_bug.cgi?id=76659
    
    Source/WebCore:
    
    Three major changes:
    
    1. Modify timeToSampleFrame to round the time to the sample frame
    and add support for Visual Studio to round the time in the same
    way as on gcc. (The issue is that Visual Studio uses x87
    instructions with 80-bit floats.)  This makes Visual Studio more
    consistent with the results with gcc.
    
    2. Change the current time variable from keeping time in seconds
    to keeping time in sample frames.  This minimizes rounding except
    when needed for the Javascript API.
    
    3. Update AudioBufferSourceNode::process to use samples (instead
    of time) as much as possible to reduce round-off effects.
    
    Patch by Raymond Toy <rtoy@google.com> on 2012-01-27
    Reviewed by Kenneth Russell.
    
    Tests: Added note-grain-on test to exercise precise
    timing. Existing tests (gain and audiobuffersource-playbackrate)
    also cover some of these changes, and the equalpower panner test is
    modified to enable the tests for the offset of the impulses.
    
    * platform/audio/AudioUtilities.cpp:
    (WebCore::AudioUtilities::timeToSampleFrame): Moved from
    AudioParamTimeLine and slightly modified, and updated to round
    operations consistently.  Add special flags for Visual Studio to
    generate code with rounding that is consistent with gcc.
    * platform/audio/AudioUtilities.h: Declare new function.
    * webaudio/AudioBufferSourceNode.cpp:
    (WebCore::AudioBufferSourceNode::process): Use new functions to
    convert time to sample frame.  Update code to use integer
    arithmetic as much as possible.
    (WebCore::AudioBufferSourceNode::renderFromBuffer): Use
    timeToSampleFrame to convert time to sample frame.
    * webaudio/AudioContext.h: Define new currentSample method to get
    the current sample.
    * webaudio/AudioDestinationNode.cpp:
    (WebCore::AudioDestinationNode::provideInput): Use new function to
    convert sample frame to time.  Update
    * webaudio/AudioDestiationNode.h: Rename m_currentTime to
    m_currentSample, add method to return current Sample.  Update
    currentTime() method to compute time from the current sample.
    * webaudio/AudioParamTimeline.cpp:
    (WebCore::AudioParamTimeline::valuesForTimeRangeImpl): Remove
    timeToSampleFrame and use new function in AudioUtilities to
    convert time to sample frame.
    
    LayoutTests:
    
    Patch by Raymond Toy <rtoy@google.com> on 2012-01-27
    Reviewed by Kenneth Russell.
    
    * webaudio/audiobuffersource-playbackrate-expected.wav: Updated.
    * webaudio/gain-expected.wav: Updated.
    * webaudio/resources/audio-testing.js:
    (timeToSampleFrame): Utility to convert time to sample frame, to
    be consistent with the actual webaudio implementation.
    * webaudio/resources/panner-model-testing.js:
    (checkResult): Enable the tests for the offset of the impulses.
    Also fix a bug in printing the time where the max error was
    found.
    * webaudio/note-grain-on-timing.html: New test for noteGrainOn.
    Also tests the new currentSample implemenation and
    roundToSampleFrame.
    * webaudio/note-grain-on-timing-expected.txt: Added.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106162 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    5b585ab6