Skip to content

Commit

Permalink
Clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
HEnquist committed Oct 9, 2020
1 parent 7009533 commit 356ee73
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
7 changes: 2 additions & 5 deletions src/audiodevice.rs
Expand Up @@ -190,13 +190,10 @@ pub fn get_playback_device(conf: config::Devices) -> Box<dyn PlaybackDevice> {
}

pub fn resampler_is_async(conf: &config::Resampler) -> bool {
match &conf {
config::Resampler::FastAsync
matches!(&conf, config::Resampler::FastAsync
| config::Resampler::BalancedAsync
| config::Resampler::AccurateAsync
| config::Resampler::FreeAsync { .. } => true,
_ => false,
}
| config::Resampler::FreeAsync { .. })
}

pub fn get_async_parameters(
Expand Down
5 changes: 1 addition & 4 deletions src/config.rs
Expand Up @@ -89,10 +89,7 @@ impl SampleFormat {
}

pub fn is_float(&self) -> bool {
match self {
SampleFormat::FLOAT32LE | SampleFormat::FLOAT64LE => true,
_ => false,
}
matches!(self, SampleFormat::FLOAT32LE | SampleFormat::FLOAT64LE)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/filedevice.rs
Expand Up @@ -389,8 +389,7 @@ fn capture_loop(
}
let msg = AudioMessage::Audio(chunk);
msg_channels.audio.send(msg).unwrap();
}
else {
} else {
sleep_until_next(bytes_per_frame, params.capture_samplerate, capture_bytes);
}
}
Expand Down Expand Up @@ -550,7 +549,8 @@ fn read_retry(file: &mut dyn Read, mut buf: &mut [u8]) -> Res<usize> {
}

fn sleep_until_next(bytes_per_frame: usize, samplerate: usize, nbr_bytes: usize) {
let io_duration = Duration::from_millis((1000 * nbr_bytes) as u64 / (bytes_per_frame*samplerate) as u64);
let io_duration =
Duration::from_millis((1000 * nbr_bytes) as u64 / (bytes_per_frame * samplerate) as u64);
if io_duration > Duration::from_millis(2) {
thread::sleep(io_duration - Duration::from_millis(2));
}
Expand Down
19 changes: 15 additions & 4 deletions src/pulsedevice.rs
Expand Up @@ -161,7 +161,12 @@ impl PlaybackDevice for PulsePlaybackDevice {
}
_ => panic!("Unsupported sample format!"),
};
sleep_until_next(&last_instant, bytes_per_frame, samplerate, buffer.len());
sleep_until_next(
&last_instant,
bytes_per_frame,
samplerate,
buffer.len(),
);
let write_res = pulsedevice.write(&buffer);
last_instant = Instant::now();
match write_res {
Expand Down Expand Up @@ -409,10 +414,16 @@ impl CaptureDevice for PulseCaptureDevice {
}
}

fn sleep_until_next(last_instant: &Instant, bytes_per_frame: usize, samplerate: usize, nbr_bytes: usize) {
let io_duration = Duration::from_millis((1000 * nbr_bytes) as u64 / (bytes_per_frame*samplerate) as u64);
fn sleep_until_next(
last_instant: &Instant,
bytes_per_frame: usize,
samplerate: usize,
nbr_bytes: usize,
) {
let io_duration =
Duration::from_millis((1000 * nbr_bytes) as u64 / (bytes_per_frame * samplerate) as u64);
let time_spent = Instant::now().duration_since(*last_instant);
if (time_spent + Duration::from_millis(5)) < io_duration {
thread::sleep(io_duration - time_spent - Duration::from_millis(5));
}
}
}

0 comments on commit 356ee73

Please sign in to comment.