Skip to content

Commit

Permalink
Fix bugs with nearest sample rate (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: andermatt64 <andy@airframes.io>
  • Loading branch information
andermatt64 and andermatt64 authored Nov 24, 2023
1 parent 816b0b3 commit 2d8108e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/modules/hfdl/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ impl HfdlModule {

pub fn get_settings(&self) -> Result<Data<RwLock<ModuleSettings>>, io::Error> {
let Some(ref settings) = self.settings else {
return Err(io::Error::new(io::ErrorKind::InvalidData, "ModuleSettings is None"));
return Err(io::Error::new(
io::ErrorKind::InvalidData,
"ModuleSettings is None",
));
};
Ok(settings.clone())
}
Expand Down Expand Up @@ -126,7 +129,7 @@ impl HfdlModule {
}

pub fn nearest_sample_rate(&self, sample_rate: u64) -> Option<u64> {
if let Some(idx) = self.sample_rates.iter().position(|&x| sample_rate >= x) {
if let Some(idx) = self.sample_rates.iter().position(|&x| x >= sample_rate) {
Some(self.sample_rates[idx])
} else {
None
Expand All @@ -139,7 +142,7 @@ impl HfdlModule {

match (bands.first(), bands.last()) {
(Some(min_freq), Some(max_freq)) => {
self.nearest_sample_rate(((max_freq - min_freq) as f64 * 0.8) as u64)
self.nearest_sample_rate(((max_freq - min_freq) as f64 * 1.2) as u64 * 1000)
}
_ => None,
}
Expand Down

0 comments on commit 2d8108e

Please sign in to comment.