Class Timebase

java.lang.Object
com.peterphi.std.types.Timebase

public class Timebase extends Object
Describes a timebase, expressed as a rational number. This is primarily designed for timebases where the numerator is 1 (i.e. where the denominator is the number of samples per second)
  • Field Details

    • WARN_ON_PRECISION_LOSS

      public static final boolean WARN_ON_PRECISION_LOSS
      See Also:
    • HZ_24

      public static final Timebase HZ_24
    • HZ_25

      public static final Timebase HZ_25
    • HZ_30

      public static final Timebase HZ_30
    • HZ_50

      public static final Timebase HZ_50
    • HZ_60

      public static final Timebase HZ_60
    • HZ_44100

      public static final Timebase HZ_44100
    • HZ_48000

      public static final Timebase HZ_48000
    • HZ_96000

      public static final Timebase HZ_96000
    • HZ_192000

      public static final Timebase HZ_192000
    • HZ_1000000

      public static final Timebase HZ_1000000
      1 MHz (Vidispine transcoder default sampling rate)
    • HZ_27000000

      public static final Timebase HZ_27000000
      27 MHz (sampling rate used by Carbon)
    • HZ_1000

      public static final Timebase HZ_1000
      1 kHz (1 frame = 1 millisecond. One of the ways MediaInfo uses to express durations/offsets)
    • HZ_1

      public static final Timebase HZ_1
      1 Hz (1 frame = 1 second)
    • NTSC

      public static final Timebase NTSC
      29.97 Hz (NTSC. Supports drop frame and non-drop-frame)
    • NTSC_24

      public static final Timebase NTSC_24
      23.976 Hz (24p). N.B. does not support drop-frame
    • NTSC_60

      public static final Timebase NTSC_60
      59.94 Hz. Supports drop-frame and non-drop-frame
  • Constructor Details

    • Timebase

      public Timebase(int numerator, int denominator)
      Parameters:
      numerator - the numerator (the top part of the fraction) - generally 1
      denominator - the denominator (the bottom part of the fraction) - e.g. 25 for PAL (with a numerator of 1)
  • Method Details

    • getNumerator

      public int getNumerator()
    • getDenominator

      public int getDenominator()
    • canBeDropFrame

      public boolean canBeDropFrame()
    • getSamplesPerSecond

      public double getSamplesPerSecond()
      The number of samples each second
      Returns:
    • getIntSamplesPerSecond

      public int getIntSamplesPerSecond()
      Samples per second, cast to an integer (rounded in the case of fractional frames per second)
      Returns:
    • getSecondsPerSample

      public double getSecondsPerSample()
      The number of seconds each sample represents
      Returns:
    • resample

      public long resample(long samples, Timebase oldRate)
      Convert a sample count from one timebase to another
      Note that this may result in data loss due to rounding.
      Parameters:
      samples -
      oldRate -
      Returns:
    • resamplePrecise

      public long resamplePrecise(long samples, Timebase oldRate) throws ResamplingException
      Convert a sample count from one timebase to another, throwing an exception if precision is lost
      Parameters:
      samples -
      oldRate -
      Returns:
      Throws:
      ResamplingException - if precision is lost during the conversion
    • resample

      public long resample(long samples, Timebase oldRate, boolean failOnPrecisionLoss) throws ResamplingException
      Convert a sample count from one timebase to another
      Note that this may result in data loss due to rounding.
      Parameters:
      samples -
      oldRate -
      failOnPrecisionLoss - if true, precision losing operations will fail by throwing a PrecisionLostException
      Returns:
      Throws:
      ResamplingException
    • resample

      public double resample(double samples, Timebase oldRate)
      Convert a sample count from one timebase to another
      Parameters:
      samples -
      oldRate -
      Returns:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toEncodedString

      public String toEncodedString()
      Return the encoded string representation of this Timebase
      N.B. does not return string constants such as NTSC or NTSC30
      Returns:
    • getInstance

      @Deprecated public static Timebase getInstance(String rate)
      Deprecated.
      use valueOf(String) instead
      Parameters:
      rate -
      Returns:
    • valueOf

      public static Timebase valueOf(String rate)
      Parses an encoded timebase.

      The following textual representations are valid for time bases:

        Its inverse as a rational number. The syntax is {denominator}[:{numerator}], where numerator can be omitted if its value is 1.
      • A TimeBaseConstant string
      • TimeBaseConstant

      The following TimeBaseConstants are currently defined:

      TimeBaseConstant Time base
      PAL 25:1
      NTSC or 29.97 30000:1001
      23.976 24000:1001
      59.94 60000:1001
      NTSC30 30:1
      Parameters:
      rate -
      Returns: