Package com.peterphi.std.types
Class Timebase
java.lang.Object
com.peterphi.std.types.Timebase
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Timebase1 Hz (1 frame = 1 second)static final Timebase1 kHz (1 frame = 1 millisecond.static final Timebase1 MHz (Vidispine transcoder default sampling rate)static final Timebasestatic final Timebasestatic final Timebasestatic final Timebase27 MHz (sampling rate used by Carbon)static final Timebasestatic final Timebasestatic final Timebasestatic final Timebasestatic final Timebasestatic final Timebasestatic final Timebase29.97 Hz (NTSC.static final Timebase23.976 Hz (24p).static final Timebase59.94 Hz.static final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanintstatic TimebasegetInstance(String rate) Deprecated.intSamples per second, cast to an integer (rounded in the case of fractional frames per second)intdoubleThe number of samples each seconddoubleThe number of seconds each sample representsinthashCode()doubleConvert a sample count from one timebase to anotherlongConvert a sample count from one timebase to another
Note that this may result in data loss due to rounding.longConvert a sample count from one timebase to another
Note that this may result in data loss due to rounding.longresamplePrecise(long samples, Timebase oldRate) Convert a sample count from one timebase to another, throwing an exception if precision is lostReturn the encoded string representation of this Timebase
N.B.toString()static TimebaseParses an encoded timebase.
-
Field Details
-
WARN_ON_PRECISION_LOSS
public static final boolean WARN_ON_PRECISION_LOSS- See Also:
-
HZ_24
-
HZ_25
-
HZ_30
-
HZ_50
-
HZ_60
-
HZ_44100
-
HZ_48000
-
HZ_96000
-
HZ_192000
-
HZ_1000000
1 MHz (Vidispine transcoder default sampling rate) -
HZ_27000000
27 MHz (sampling rate used by Carbon) -
HZ_1000
1 kHz (1 frame = 1 millisecond. One of the ways MediaInfo uses to express durations/offsets) -
HZ_1
1 Hz (1 frame = 1 second) -
NTSC
29.97 Hz (NTSC. Supports drop frame and non-drop-frame) -
NTSC_24
23.976 Hz (24p). N.B. does not support drop-frame -
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 1denominator- 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
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
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
Convert a sample count from one timebase to another- Parameters:
samples-oldRate-- Returns:
-
hashCode
public int hashCode() -
equals
-
toString
-
toEncodedString
Return the encoded string representation of this Timebase
N.B. does not return string constants such as NTSC or NTSC30- Returns:
-
getInstance
Deprecated.usevalueOf(String)instead- Parameters:
rate-- Returns:
-
valueOf
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:
-
valueOf(String)instead