Class SampleCount

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

public class SampleCount extends Object
A number of samples at a given sample rate
  • Constructor Details

    • SampleCount

      public SampleCount(long samples, Timebase rate)
  • Method Details

    • resample

      public SampleCount resample(Timebase newRate)
      Resample this sample count to another rate
      Parameters:
      newRate -
      Returns:
    • add

      public SampleCount add(SampleCount that)
    • addPrecise

      public SampleCount addPrecise(SampleCount that) throws ResamplingException
      Throws:
      ResamplingException
    • subtract

      public SampleCount subtract(SampleCount that)
    • subtractPrecise

      public SampleCount subtractPrecise(SampleCount that) throws ResamplingException
      Parameters:
      that - the sample count to subtract
      Returns:
      Throws:
      ResamplingException - if the delta cannot be expressed without losing accuracy
    • getRate

      public Timebase getRate()
    • getSamples

      public long getSamples()
    • getSamples

      public long getSamples(Timebase newRate)
      Returns the number of samples represented by this SampleCount, converted to newRate.
      This method can lose precision if the samples cannot be precisely represented. Use getSamplesPrecise for lossless-or-exception resampling
      Parameters:
      newRate -
      Returns:
    • getSamplesPrecise

      public long getSamplesPrecise(Timebase newRate) throws ResamplingException
      Returns the number of samples represented by this SampleCount, converted to newRate. If precision would be lost this method throws an exception
      This method uses Timebase.resamplePrecise for lossless-or-exception resampling
      Parameters:
      newRate -
      Returns:
      Throws:
      ResamplingException - if precision would be lost by the resample
    • toString

      public String toString()
      Encode the SampleCount as samples@[str_timebase|nom[:denom]] (e.g. 124222@44100, 400@30000:1001)
      Overrides:
      toString in class Object
      Returns:
    • toFfmpegString

      public String toFfmpegString()
      Returns the sample count in FFmpeg's time-based duration format. The format of the sample count is hh:mm:ss:uuuuuu (where u = microseconds).
      Returns:
      See Also:
    • parseVidispine

      @Deprecated public static SampleCount parseVidispine(String countAndRate)
      Deprecated.
      Parse a vidispine sample count & timebase as represented in point 1 of http://wiki.vidispine.com/vidiwiki/Time#Time_codes
      N.B. This does NOT consider the case where only a sample count is specified: it MUST include a timebase
      Parameters:
      countAndRate - A sample count and a time base. The syntax is {number of samples}@{textual representation of time base} 124222@44100, 400@30000:1001, 400@NTSC
      Returns:
    • valueOf

      public static SampleCount valueOf(String countAndRate)
      Parse a sample count & timebase as samples@[str_timebase|nom[:denom]] N.B. This does NOT consider the case where only a sample count is specified: it MUST include a timebase
      Parameters:
      countAndRate - A sample count and a time base. The syntax is {number of samples}@{textual representation of time base} 124222@44100, 400@30000:1001, 400@NTSC
      Returns:
    • seconds

      public static SampleCount seconds(Timebase rate, long seconds)
    • toVidispineString

      @Deprecated public String toVidispineString()
      Deprecated.
    • getSeconds

      public double getSeconds()
      Compute the duration of this sample count in seconds
      The intention of this method is to be used for presentation, rather than accurate computation so it does not warn about resampling errors
      Returns:
    • hashCode

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object