Logo Search packages:      
Sourcecode: scummvm version File versions

Timestamp Audio::Timestamp::convertToFramerate ( uint  newFramerate ) const

Return a timestamp which represents as closely as possible the point in time describes by this timestamp, but with a different framerate.

Definition at line 53 of file timestamp.cpp.

References _framerate, _framerateFactor, _numFrames, framerate(), and normalize().

Referenced by Audio::convertTimeToStreamPos().

                                                               {
      Timestamp ts(*this);

      if (ts.framerate() != newFramerate) {
            ts._framerateFactor = 1000 / Common::gcd<uint>(1000, newFramerate);
            ts._framerate = newFramerate * ts._framerateFactor;

            const uint g = Common::gcd(_framerate, ts._framerate);
            const uint p = _framerate / g;
            const uint q = ts._framerate / g;

            // Convert the frame offset to the new framerate.
            // We round to the nearest (as opposed to always
            // rounding down), to minimize rounding errors during
            // round trip conversions.
            ts._numFrames = (ts._numFrames * q + p/2) / p;

            ts.normalize();
      }

      return ts;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index