mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-05 02:39:53 +02:00
Various code improvements (#777)
* Remove deprecated use of std::u16::MAX * Use `FromStr` for fallible `&str` conversions * DRY up strings into constants * Change `as_ref().map()` into `as_deref()` * Use `Duration` for time constants and functions * Optimize `Vec` with response times * Move comments for `rustdoc` to parse
This commit is contained in:
parent
bae1834988
commit
ad19b69bfb
27 changed files with 433 additions and 309 deletions
|
@ -61,7 +61,7 @@ impl Ditherer for TriangularDitherer {
|
|||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Triangular"
|
||||
Self::NAME
|
||||
}
|
||||
|
||||
fn noise(&mut self) -> f64 {
|
||||
|
@ -69,6 +69,10 @@ impl Ditherer for TriangularDitherer {
|
|||
}
|
||||
}
|
||||
|
||||
impl TriangularDitherer {
|
||||
pub const NAME: &'static str = "tpdf";
|
||||
}
|
||||
|
||||
pub struct GaussianDitherer {
|
||||
cached_rng: ThreadRng,
|
||||
distribution: Normal<f64>,
|
||||
|
@ -84,7 +88,7 @@ impl Ditherer for GaussianDitherer {
|
|||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Gaussian"
|
||||
Self::NAME
|
||||
}
|
||||
|
||||
fn noise(&mut self) -> f64 {
|
||||
|
@ -92,6 +96,10 @@ impl Ditherer for GaussianDitherer {
|
|||
}
|
||||
}
|
||||
|
||||
impl GaussianDitherer {
|
||||
pub const NAME: &'static str = "gpdf";
|
||||
}
|
||||
|
||||
pub struct HighPassDitherer {
|
||||
active_channel: usize,
|
||||
previous_noises: [f64; NUM_CHANNELS],
|
||||
|
@ -110,7 +118,7 @@ impl Ditherer for HighPassDitherer {
|
|||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Triangular, High Passed"
|
||||
Self::NAME
|
||||
}
|
||||
|
||||
fn noise(&mut self) -> f64 {
|
||||
|
@ -122,6 +130,10 @@ impl Ditherer for HighPassDitherer {
|
|||
}
|
||||
}
|
||||
|
||||
impl HighPassDitherer {
|
||||
pub const NAME: &'static str = "tpdf_hp";
|
||||
}
|
||||
|
||||
pub fn mk_ditherer<D: Ditherer + 'static>() -> Box<dyn Ditherer> {
|
||||
Box::new(D::new())
|
||||
}
|
||||
|
@ -130,9 +142,9 @@ pub type DithererBuilder = fn() -> Box<dyn Ditherer>;
|
|||
|
||||
pub fn find_ditherer(name: Option<String>) -> Option<DithererBuilder> {
|
||||
match name.as_deref() {
|
||||
Some("tpdf") => Some(mk_ditherer::<TriangularDitherer>),
|
||||
Some("gpdf") => Some(mk_ditherer::<GaussianDitherer>),
|
||||
Some("tpdf_hp") => Some(mk_ditherer::<HighPassDitherer>),
|
||||
Some(TriangularDitherer::NAME) => Some(mk_ditherer::<TriangularDitherer>),
|
||||
Some(GaussianDitherer::NAME) => Some(mk_ditherer::<GaussianDitherer>),
|
||||
Some(HighPassDitherer::NAME) => Some(mk_ditherer::<HighPassDitherer>),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue