Advertisement
Guest User

correctTimeToSyncSample

a guest
Mar 9th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. public double correctTimeToSyncSample(Track track, double cutHere, boolean next) {
  2.         double[] timeOfSyncSamples = new double[track.getSyncSamples().length];
  3.         long currentSample = 0;
  4.         double currentTime = 0;
  5.         for (int i = 0; i < track.getDecodingTimeEntries().size(); i++) {
  6.             TimeToSampleBox.Entry entry = track.getDecodingTimeEntries().get(i);
  7.             for (int j = 0; j < entry.getCount(); j++) {
  8.                 if (Arrays.binarySearch(track.getSyncSamples(),
  9.                         currentSample + 1) >= 0) {
  10.                     // samples always start with 1 but we start with zero
  11.                     // therefore +1
  12.                     timeOfSyncSamples[Arrays.binarySearch(
  13.                             track.getSyncSamples(), currentSample + 1)] = currentTime;
  14.                 }
  15.                 currentTime += (double) entry.getDelta()
  16.                         / (double) track.getTrackMetaData().getTimescale();
  17.                 currentSample++;
  18.             }
  19.         }
  20.         double previous = 0;
  21.         for (double timeOfSyncSample : timeOfSyncSamples) {
  22.             if (timeOfSyncSample > cutHere) {
  23.                 if (next) {
  24.                     return timeOfSyncSample;
  25.                 } else {
  26.                     return previous;
  27.                 }
  28.             }
  29.             previous = timeOfSyncSample;
  30.         }
  31.         return timeOfSyncSamples[timeOfSyncSamples.length - 1];
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement