Struct sampled_data_duration::MixedRateDuration
source · [−]pub struct MixedRateDuration { /* private fields */ }
Expand description
Represents a duration of a collection of datasets which may have been sampled at different rates.
Examples
Consider an audio playlist which at first consists of a single
audio file of 12_345_678
samples per channel recorded with at
44.1kHz sampling frequency. We then add another audio file to this
playlist which is recorded at 96kHz.
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mut mrd = MixedRateDuration::from(ConstantRateDuration::new(12_345_678, 48000));
// Note that the default string representation when there is only
// a single sampling rate is of the form `hh:mm:ss;samples`.
assert_eq!(mrd.to_string(), "00:04:17;9678");
// Now we add a 96kHz file
let crd = ConstantRateDuration::new(31_415_926, 96000);
assert_eq!(crd.to_string(), "00:05:27;23926");
mrd += crd;
// Note that the default string representation when there are
// multiple sampling rates is of the form `hh:mm:ss.s`.
assert_eq!(mrd.to_string(), "00:09:44.450854166");
Implementations
sourceimpl MixedRateDuration
impl MixedRateDuration
sourcepub fn new() -> MixedRateDuration
pub fn new() -> MixedRateDuration
Construct an empty MixedRateDuration
.
Examples
use sampled_data_duration::MixedRateDuration;
let mut mrd = MixedRateDuration::new();
assert_eq!(mrd.to_string(), "00:00:00");
sourcepub fn as_secs(&self) -> u64
pub fn as_secs(&self) -> u64
Returns the number of whole seconds contained by this
MixedRateDuration
.
The returned value does not include the fractional part of the
duration which can be obtained with subsec_secs
.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 * 62 + 123, 48000));
assert_eq!(mrd.to_string(), "00:01:02;123");
assert_eq!(mrd.as_secs(), 62);
sourcepub fn as_mins(&self) -> u64
pub fn as_mins(&self) -> u64
Returns the number of whole minutes contained by this MixedRateDuration
.
The returned value does not include the fractional part of the duration, and can be a value greater than 59.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 * 60 * 91, 48000));
assert_eq!(mrd.to_string(), "01:31:00;0");
assert_eq!(mrd.as_mins(), 91);
sourcepub fn as_hours(&self) -> u64
pub fn as_hours(&self) -> u64
Returns the number of whole hours contained by this MixedRateDuration
.
The returned value does not include the fractional part of the duration, and can be a value greater than 23.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 * 60 * 60 * 48 + 12345, 48000));
assert_eq!(mrd.to_string(), "48:00:00;12345");
assert_eq!(mrd.as_hours(), 48);
sourcepub fn as_days(&self) -> u64
pub fn as_days(&self) -> u64
Returns the number of whole days contained by this MixedRateDuration
.
The returned value does not include the fractional part of the duration, and can be a value greater than 6.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 * 60 * 60 * 48 + 12345, 48000));
assert_eq!(mrd.to_string(), "48:00:00;12345");
assert_eq!(mrd.as_days(), 2);
sourcepub fn as_weeks(&self) -> u64
pub fn as_weeks(&self) -> u64
Returns the number of whole weeks contained by this MixedRateDuration
.
The returned value does not include the fractional part of the duration.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 * 60 * 60 * 24 * 21 + 12345, 48000));
assert_eq!(mrd.to_string(), "504:00:00;12345");
assert_eq!(mrd.as_weeks(), 3);
sourcepub fn num_rates(&self) -> usize
pub fn num_rates(&self) -> usize
Return the number of different sampling rates used in this
MixedRateDuration
.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mut mrd = MixedRateDuration::from(ConstantRateDuration::new(1, 44100));
assert_eq!(mrd.num_rates(), 1);
mrd += ConstantRateDuration::new(1, 48000);
assert_eq!(mrd.num_rates(), 2);
mrd += ConstantRateDuration::new(1, 96000);
assert_eq!(mrd.num_rates(), 3);
mrd += ConstantRateDuration::new(2, 44100);
assert_eq!(mrd.num_rates(), 3);
sourcepub fn subsec_nanos(&self) -> u32
pub fn subsec_nanos(&self) -> u32
Returns the whole number of nanoseconds in the fractional part of this MixedRateDuration
.
The returned value will always be less than one second i.e. >
1_000_000_000
nanoseconds.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 + 24000, 48000));
assert_eq!(mrd.to_string(), "00:00:01;24000");
assert_eq!(mrd.subsec_nanos(), 500_000_000);
sourcepub fn subsec_secs(&self) -> f64
pub fn subsec_secs(&self) -> f64
Returns the whole number of seconds in the fractional part of this MixedRateDuration
.
The returned value will always be less than one second
i.e. 0.0 <= subsec_secs
< 1.0.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 + 24000, 48000));
assert_eq!(mrd.to_string(), "00:00:01;24000");
assert_eq!(mrd.subsec_secs(), 0.5);
sourcepub fn submin_secs(&self) -> u64
pub fn submin_secs(&self) -> u64
Returns the whole number of seconds left over when this duration is measured in minutes.
The returned value will always be 0 <= submin_secs
<= 59.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 * 65 + 32000, 48000));
assert_eq!(mrd.to_string(), "00:01:05;32000");
assert_eq!(mrd.submin_secs(), 5);
sourcepub fn subhour_mins(&self) -> u64
pub fn subhour_mins(&self) -> u64
Returns the whole number of minutes left over when this duration is measured in hours.
The returned value will always be 0 <= subhour_mins
<= 59.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 * 60 * 68, 48000));
assert_eq!(mrd.to_string(), "01:08:00;0");
assert_eq!(mrd.subhour_mins(), 8);
sourcepub fn subday_hours(&self) -> u64
pub fn subday_hours(&self) -> u64
Returns the whole number of hours left over when this duration is measured in days.
The returned value will always be 0 <= subday_hours
<= 23.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 * 60 * 60 * 25, 48000));
assert_eq!(mrd.to_string(), "25:00:00;0");
assert_eq!(mrd.subday_hours(), 1);
sourcepub fn subweek_days(&self) -> u64
pub fn subweek_days(&self) -> u64
Returns the whole number of days left over when this duration is measured in weeks.
The returned value will always be 0 <= subweek_days
<= 6.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 * 60 * 60 * 24 * 9, 48000));
assert_eq!(mrd.to_string(), "216:00:00;0");
assert_eq!(mrd.subweek_days(), 2);
sourcepub fn to_duration(&self) -> Duration
pub fn to_duration(&self) -> Duration
Return this MixedRateDuration
as a std::time::Duration
.
Example
use sampled_data_duration::ConstantRateDuration;
use sampled_data_duration::MixedRateDuration;
let mrd = MixedRateDuration::from(ConstantRateDuration::new(48000 * 42, 48000));
assert_eq!(mrd.to_string(), "00:00:42;0");
assert_eq!(mrd.to_duration().as_secs_f64(), 42.0);
Trait Implementations
sourceimpl Add<ConstantRateDuration> for MixedRateDuration
impl Add<ConstantRateDuration> for MixedRateDuration
sourcefn add(self, crd: ConstantRateDuration) -> MixedRateDuration
fn add(self, crd: ConstantRateDuration) -> MixedRateDuration
Add a ConstantRateDuration
to this MixedRateDuration
returning a new MixedRateDuration
.
type Output = MixedRateDuration
type Output = MixedRateDuration
The resulting type after applying the +
operator.
sourceimpl Add<MixedRateDuration> for MixedRateDuration
impl Add<MixedRateDuration> for MixedRateDuration
sourcefn add(self, mrd: MixedRateDuration) -> MixedRateDuration
fn add(self, mrd: MixedRateDuration) -> MixedRateDuration
Add a MixedRateDuration
to this MixedRateDuration
returning a new MixedRateDuration
.
type Output = MixedRateDuration
type Output = MixedRateDuration
The resulting type after applying the +
operator.
sourceimpl AddAssign<ConstantRateDuration> for MixedRateDuration
impl AddAssign<ConstantRateDuration> for MixedRateDuration
sourcefn add_assign(&mut self, crd: ConstantRateDuration)
fn add_assign(&mut self, crd: ConstantRateDuration)
Add a ConstantRateDuration
to this MixedRateDuration
.
sourceimpl AddAssign<MixedRateDuration> for MixedRateDuration
impl AddAssign<MixedRateDuration> for MixedRateDuration
sourcefn add_assign(&mut self, rhs: MixedRateDuration)
fn add_assign(&mut self, rhs: MixedRateDuration)
Add a MixedRateDuration
to this MixedRateDuration
.
sourceimpl Clone for MixedRateDuration
impl Clone for MixedRateDuration
sourcefn clone(&self) -> MixedRateDuration
fn clone(&self) -> MixedRateDuration
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for MixedRateDuration
impl Debug for MixedRateDuration
sourceimpl Default for MixedRateDuration
impl Default for MixedRateDuration
sourceimpl Display for MixedRateDuration
impl Display for MixedRateDuration
sourceimpl Div<u64> for MixedRateDuration
impl Div<u64> for MixedRateDuration
sourcefn div(self, rhs: u64) -> Self
fn div(self, rhs: u64) -> Self
Divide a MixedRateDuration
by a u64
returning a new
MixedRateDuration
.
type Output = MixedRateDuration
type Output = MixedRateDuration
The resulting type after applying the /
operator.
sourceimpl DivAssign<u64> for MixedRateDuration
impl DivAssign<u64> for MixedRateDuration
sourcefn div_assign(&mut self, rhs: u64)
fn div_assign(&mut self, rhs: u64)
Divide-assign a MixedRateDuration
by a u64
.
sourceimpl From<ConstantRateDuration> for MixedRateDuration
impl From<ConstantRateDuration> for MixedRateDuration
sourcefn from(crd: ConstantRateDuration) -> Self
fn from(crd: ConstantRateDuration) -> Self
Construct a MixedRateDuration
from a ConstantRateDuration
.
sourceimpl Mul<u64> for MixedRateDuration
impl Mul<u64> for MixedRateDuration
sourcefn mul(self, rhs: u64) -> Self
fn mul(self, rhs: u64) -> Self
Multiply a MixedRateDuration
by a u64
returning a new
MixedRateDuration
.
type Output = MixedRateDuration
type Output = MixedRateDuration
The resulting type after applying the *
operator.
sourceimpl MulAssign<u64> for MixedRateDuration
impl MulAssign<u64> for MixedRateDuration
sourcefn mul_assign(&mut self, rhs: u64)
fn mul_assign(&mut self, rhs: u64)
Multiply-assign a MixedRateDuration
by a u64
.
sourceimpl PartialEq<MixedRateDuration> for MixedRateDuration
impl PartialEq<MixedRateDuration> for MixedRateDuration
sourcefn eq(&self, other: &MixedRateDuration) -> bool
fn eq(&self, other: &MixedRateDuration) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &MixedRateDuration) -> bool
fn ne(&self, other: &MixedRateDuration) -> bool
This method tests for !=
.
sourceimpl Sub<ConstantRateDuration> for MixedRateDuration
impl Sub<ConstantRateDuration> for MixedRateDuration
sourcefn sub(self, crd: ConstantRateDuration) -> MixedRateDuration
fn sub(self, crd: ConstantRateDuration) -> MixedRateDuration
Perform a saturating subtraction of a ConstantRateDuration
from this MixedRateDuration
returning a new
MixedRateDuration
.
type Output = MixedRateDuration
type Output = MixedRateDuration
The resulting type after applying the -
operator.
sourceimpl Sub<MixedRateDuration> for MixedRateDuration
impl Sub<MixedRateDuration> for MixedRateDuration
sourcefn sub(self, mrd: MixedRateDuration) -> MixedRateDuration
fn sub(self, mrd: MixedRateDuration) -> MixedRateDuration
Perform a saturating subtraction of a MixedRateDuration
from
this MixedRateDuration
returning a new MixedRateDuration
.
type Output = MixedRateDuration
type Output = MixedRateDuration
The resulting type after applying the -
operator.
sourceimpl SubAssign<ConstantRateDuration> for MixedRateDuration
impl SubAssign<ConstantRateDuration> for MixedRateDuration
sourcefn sub_assign(&mut self, crd: ConstantRateDuration)
fn sub_assign(&mut self, crd: ConstantRateDuration)
Perform a saturating subtraction of a ConstantRateDuration
from this MixedRateDuration
.
sourceimpl SubAssign<MixedRateDuration> for MixedRateDuration
impl SubAssign<MixedRateDuration> for MixedRateDuration
sourcefn sub_assign(&mut self, rhs: MixedRateDuration)
fn sub_assign(&mut self, rhs: MixedRateDuration)
Perform a saturating subtraction of a MixedRateDuration
from
this MixedRateDuration
.
impl StructuralPartialEq for MixedRateDuration
Auto Trait Implementations
impl RefUnwindSafe for MixedRateDuration
impl Send for MixedRateDuration
impl Sync for MixedRateDuration
impl Unpin for MixedRateDuration
impl UnwindSafe for MixedRateDuration
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more