Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB

  1. // Copyright (c) 1996 Microsoft Corporation. All Rights Reserved.
  2. /**********************************************************************
  3. Timecode helper routines
  4. With a bit of care to not overflow or bruise the potentialy large numbers...
  5. **********************************************************************/
  6. #include <wtypes.h> // LONGLONG
  7. #include <stdio.h>
  8. LONGLONG extrapolate(LONGLONG sample1, LONGLONG time1,
  9. LONGLONG sample2, LONGLONG time2, LONGLONG sampleN)
  10. {
  11. LONGLONG sampleTime;
  12. /* NOTE: deltas should be fairly small so we don't mind losing the bits */
  13. double deltaSample = (double)(sample2 - sample1);
  14. double deltaTime = (double)(time2 - time1);
  15. double ratio;
  16. ratio = deltaTime / deltaSample; // floating point ratio
  17. sampleTime = LONGLONG((double)(sampleN - sample1) * ratio);
  18. sampleTime+= time1; // add the offset
  19. return(sampleTime);
  20. }
  21. #ifdef TEST
  22. // XXX flesh out the test code!
  23. main()
  24. {
  25. LONGLONG foo = extrapolate(1, 1, 6, 3, 2);
  26. printf("%d",(int)foo);
  27. }
  28. #endif /* TEST */