1
0
Fork 0
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:
Roderick van Domburg 2021-05-31 22:32:39 +02:00 committed by GitHub
parent bae1834988
commit ad19b69bfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 433 additions and 309 deletions

View file

@ -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,
}
}