namespace Bmp.Core.FFMpeg.CsCorePorts; /// /// Defines a base class for all time converts. A time converter can be used to convert raw positions (depending on the implementation i.e. bytes or samples) to a human /// readable . /// public abstract class TimeConverter { /// /// A for objects. /// public static readonly TimeConverter SampleSourceTimeConverter = new _SampleSourceTimeConverter(); /// /// A for objects. /// public static readonly TimeConverter WaveSourceTimeConverter = new _WaveSourceTimeConverter(); /// /// Converts a back to raw elements, a source works with. The unit of these raw elements depends on the implementation. For more information, see . /// /// The of the source which gets used to convert the . /// The to convert to raw elements. /// The converted in raw elements. public abstract long ToRawElements(WaveFormat waveFormat, TimeSpan timeSpan); /// /// Converts raw elements to a value. The unit of these raw elements depends on the implementation. For more information, see . /// /// The of the source which gets used to convert the . /// The raw elements to convert to a . /// The . public abstract TimeSpan ToTimeSpan(WaveFormat waveFormat, long rawElements); internal class _WaveSourceTimeConverter : TimeConverter { public override long ToRawElements(WaveFormat waveFormat, TimeSpan timeSpan) { return waveFormat.MillisecondsToBytes(timeSpan.TotalMilliseconds); } public override TimeSpan ToTimeSpan(WaveFormat waveFormat, long rawElements) { return TimeSpan.FromMilliseconds(waveFormat.BytesToMilliseconds(rawElements)); } } internal class _SampleSourceTimeConverter : TimeConverter { public override long ToRawElements(WaveFormat waveFormat, TimeSpan timeSpan) { return waveFormat.MillisecondsToBytes(timeSpan.TotalMilliseconds) / waveFormat.BytesPerSample; } public override TimeSpan ToTimeSpan(WaveFormat waveFormat, long rawElements) { return TimeSpan.FromMilliseconds(waveFormat.BytesToMilliseconds(rawElements * waveFormat.BytesPerSample)); } } }