Skip to content

Commit

Permalink
Merge pull request #483 from nbraud/samplerate/ops
Browse files Browse the repository at this point in the history
SampleRate: Implement std::ops::{Div, Mul}
  • Loading branch information
est31 authored Oct 4, 2020
2 parents 2b31fe4 + ec81882 commit a777589
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pub use platform::{
};
pub use samples_formats::{Sample, SampleFormat};
use std::convert::TryInto;
use std::ops::{Div, Mul};
use std::time::Duration;

mod error;
Expand All @@ -180,6 +181,26 @@ pub type ChannelCount = u16;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct SampleRate(pub u32);

impl<T> Mul<T> for SampleRate
where
u32: Mul<T, Output = u32>,
{
type Output = Self;
fn mul(self, rhs: T) -> Self {
SampleRate(self.0 * rhs)
}
}

impl<T> Div<T> for SampleRate
where
u32: Div<T, Output = u32>,
{
type Output = Self;
fn div(self, rhs: T) -> Self {
SampleRate(self.0 / rhs)
}
}

/// The desired number of frames for the hardware buffer.
pub type FrameCount = u32;

Expand Down

0 comments on commit a777589

Please sign in to comment.