diff options
author | François Laignel <fengalin@free.fr> | 2021-10-09 13:17:05 +0300 |
---|---|---|
committer | François Laignel <fengalin@free.fr> | 2021-10-18 16:09:47 +0300 |
commit | 27b9f0d868f436e9b2bcc3e51f393c40b56fcc02 (patch) | |
tree | 93c0db7b1cf26ea7d0e3a4d70a7d2844c2e00975 /audio/csound | |
parent | bd8a7e8df7e8ebf751b2d00fe6a096d726683c00 (diff) |
Improve usability thanks to opt-ops
The crate option-operations simplifies usage when dealing with
`Option`s, which is often the case with `ClockTime`.
Diffstat (limited to 'audio/csound')
-rw-r--r-- | audio/csound/src/filter/imp.rs | 5 | ||||
-rw-r--r-- | audio/csound/tests/csound_filter.rs | 2 |
2 files changed, 4 insertions, 3 deletions
diff --git a/audio/csound/src/filter/imp.rs b/audio/csound/src/filter/imp.rs index b3c649ae..c6f479c9 100644 --- a/audio/csound/src/filter/imp.rs +++ b/audio/csound/src/filter/imp.rs @@ -120,8 +120,9 @@ impl State { // pts at the beginning of the adapter. let samples = distance / self.in_info.bpf() as u64; prev_pts - .zip(self.samples_to_time(samples)) - .map(|(prev_pts, time_offset)| prev_pts + time_offset) + .opt_checked_add(self.samples_to_time(samples)) + .ok() + .flatten() } fn buffer_duration(&self, buffer_size: u64) -> Option<gst::ClockTime> { diff --git a/audio/csound/tests/csound_filter.rs b/audio/csound/tests/csound_filter.rs index 702d47e5..54f856a2 100644 --- a/audio/csound/tests/csound_filter.rs +++ b/audio/csound/tests/csound_filter.rs @@ -181,7 +181,7 @@ fn csound_filter_eos() { let samples_at_eos = (EOS_NUM_BUFFERS * EOS_NUM_SAMPLES) % ksmps; assert_eq!( buffer.as_ref().pts(), - duration_from_samples(samples_at_eos as _, sr as _).map(|duration| in_pts - duration) + in_pts.opt_sub(duration_from_samples(samples_at_eos as _, sr as _)) ); let map = buffer.into_mapped_buffer_readable().unwrap(); |