From e1108abe7185a1c104f7b1f8f8e4cd5b927aa902 Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 9 Jun 2024 22:58:15 +0200 Subject: [PATCH 1/5] Add TrackPosition to Source This adds a new TrackPosition trait which counts the amount of times `next()` is called (where it returns `Some`) and provide a function to get the position, which is a simple calculation. This is added to the Sink struct by default and the accuracy of this depends on the interval of `periodic_access`. I wasn't able to add testing to the sink counter part, because I wanted to also test `try_seek`, but it seems like I would need to have some threading code to call `next` on sink in another thread, which didn't look that good and resulted in a flaky test so only a 'unit test' in ``position.rs`. Resolves #457 Closes #510 --- src/sink.rs | 14 +++++ src/source/mod.rs | 9 +++ src/source/position.rs | 133 +++++++++++++++++++++++++++++++++++++++++ src/spatial_sink.rs | 6 ++ 4 files changed, 162 insertions(+) create mode 100644 src/source/position.rs diff --git a/src/sink.rs b/src/sink.rs index 2d7478b9..f682ab2b 100644 --- a/src/sink.rs +++ b/src/sink.rs @@ -64,6 +64,7 @@ struct Controls { speed: Mutex, to_clear: Mutex, seek: Mutex>, + position: Mutex, } impl Sink { @@ -90,6 +91,7 @@ impl Sink { speed: Mutex::new(1.0), to_clear: Mutex::new(0), seek: Mutex::new(None), + position: Mutex::new(0.0), }), sound_count: Arc::new(AtomicUsize::new(0)), detached: false, @@ -119,6 +121,7 @@ impl Sink { let source = source .speed(1.0) + .trackable() .pausable(false) .amplify(1.0) .skippable() @@ -127,12 +130,16 @@ impl Sink { .periodic_access(Duration::from_millis(5), move |src| { if controls.stopped.load(Ordering::SeqCst) { src.stop(); + *controls.position.lock().unwrap() = 0.0; } { let mut to_clear = controls.to_clear.lock().unwrap(); if *to_clear > 0 { src.inner_mut().skip(); *to_clear -= 1; + *controls.position.lock().unwrap() = 0.0; + } else { + *controls.position.lock().unwrap() = src.inner().inner().inner().inner().get_pos(); } } let amp = src.inner_mut().inner_mut(); @@ -140,6 +147,7 @@ impl Sink { amp.inner_mut() .set_paused(controls.pause.load(Ordering::SeqCst)); amp.inner_mut() + .inner_mut() .inner_mut() .set_factor(*controls.speed.lock().unwrap()); if let Some(seek) = controls.seek.lock().unwrap().take() { @@ -309,6 +317,12 @@ impl Sink { pub fn len(&self) -> usize { self.sound_count.load(Ordering::Relaxed) } + + /// Returns the position of the sound that's being played. + #[inline] + pub fn get_pos(&self) -> f64 { + *self.controls.position.lock().unwrap() + } } impl Drop for Sink { diff --git a/src/source/mod.rs b/src/source/mod.rs index 789f1695..8d1a63bb 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -21,6 +21,7 @@ pub use self::from_iter::{from_iter, FromIter}; pub use self::mix::Mix; pub use self::pausable::Pausable; pub use self::periodic::PeriodicAccess; +pub use self::position::TrackPosition; pub use self::repeat::Repeat; pub use self::samples_converter::SamplesConverter; pub use self::sine::SineWave; @@ -48,6 +49,7 @@ mod from_iter; mod mix; mod pausable; mod periodic; +mod position; mod repeat; mod samples_converter; mod sine; @@ -333,6 +335,13 @@ where skippable::skippable(self) } + fn trackable(self) -> TrackPosition + where + Self: Sized, + { + position::trackable(self) + } + /// Applies a low-pass filter to the source. /// **Warning**: Probably buggy. #[inline] diff --git a/src/source/position.rs b/src/source/position.rs new file mode 100644 index 00000000..8a23900d --- /dev/null +++ b/src/source/position.rs @@ -0,0 +1,133 @@ +use std::time::Duration; + +use crate::{Sample, Source}; + +use super::SeekError; + +/// Internal function that builds a `TrackPosition` object. +pub fn trackable(source: I) -> TrackPosition { + TrackPosition { + input: source, + samples_elapsed: 0, + } +} + +#[derive(Clone, Debug)] +pub struct TrackPosition { + input: I, + samples_elapsed: usize, +} + +impl TrackPosition { + /// Returns a reference to the inner source. + #[inline] + pub fn inner(&self) -> &I { + &self.input + } + + /// Returns a mutable reference to the inner source. + #[inline] + pub fn inner_mut(&mut self) -> &mut I { + &mut self.input + } + + /// Returns the inner source. + #[inline] + pub fn into_inner(self) -> I { + self.input + } +} + +impl TrackPosition +where + I: Source, + I::Item: Sample, +{ + /// Returns the inner source. + #[inline] + pub fn get_pos(&self) -> f64 { + self.samples_elapsed as f64 / self.input.sample_rate() as f64 / self.input.channels() as f64 + } +} + +impl Iterator for TrackPosition +where + I: Source, + I::Item: Sample, +{ + type Item = I::Item; + + #[inline] + fn next(&mut self) -> Option { + let item = self.input.next(); + if item.is_some() { + self.samples_elapsed += 1; + }; + item + } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + self.input.size_hint() + } +} + +impl Source for TrackPosition +where + I: Source, + I::Item: Sample, +{ + #[inline] + fn current_frame_len(&self) -> Option { + self.input.current_frame_len() + } + + #[inline] + fn channels(&self) -> u16 { + self.input.channels() + } + + #[inline] + fn sample_rate(&self) -> u32 { + self.input.sample_rate() + } + + #[inline] + fn total_duration(&self) -> Option { + self.input.total_duration() + } + + #[inline] + fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> { + let result = self.input.try_seek(pos); + if result.is_ok() { + self.samples_elapsed = (pos.as_secs_f64() + * self.input.sample_rate() as f64 + * self.input.channels() as f64) as usize; + } + result + } +} + +#[cfg(test)] +mod tests { + use std::time::Duration; + + use crate::buffer::SamplesBuffer; + use crate::source::Source; + + #[test] + fn test_position() { + let inner = SamplesBuffer::new(1, 1, vec![10i16, -10, 10, -10, 20, -20]); + let mut source = inner.trackable(); + + assert_eq!(source.get_pos(), 0.0); + source.next(); + assert_eq!(source.get_pos(), 1.0); + source.next(); + assert_eq!(source.get_pos(), 2.0); + + assert_eq!(source.try_seek(Duration::new(1, 0)).is_ok(), true); + assert_eq!(source.get_pos(), 1.0); + } +} diff --git a/src/spatial_sink.rs b/src/spatial_sink.rs index cb787bc0..4de5fd1d 100644 --- a/src/spatial_sink.rs +++ b/src/spatial_sink.rs @@ -195,4 +195,10 @@ impl SpatialSink { pub fn try_seek(&self, pos: Duration) -> Result<(), SeekError> { self.sink.try_seek(pos) } + + /// Returns the position of the sound that's being played. + #[inline] + pub fn get_pos(&self) -> f64 { + self.sink.get_pos() + } } From 0e6d5a1da2d75d462f145dcd4ad54d5821599deb Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 11 Jun 2024 01:47:03 +0200 Subject: [PATCH 2/5] Handle variable channels and sample rate --- src/source/position.rs | 51 +++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/source/position.rs b/src/source/position.rs index 8a23900d..dab444d9 100644 --- a/src/source/position.rs +++ b/src/source/position.rs @@ -8,14 +8,22 @@ use super::SeekError; pub fn trackable(source: I) -> TrackPosition { TrackPosition { input: source, - samples_elapsed: 0, + samples_collected: 0, + offset_duration: 0.0, + current_frame_sample_rate: 0, + current_frame_channels: 0, + current_frame_len: None, } } #[derive(Clone, Debug)] pub struct TrackPosition { input: I, - samples_elapsed: usize, + samples_collected: usize, + offset_duration: f64, + current_frame_sample_rate: u32, + current_frame_channels: u16, + current_frame_len: Option, } impl TrackPosition { @@ -43,10 +51,20 @@ where I: Source, I::Item: Sample, { - /// Returns the inner source. + /// Returns the position of the source. #[inline] pub fn get_pos(&self) -> f64 { - self.samples_elapsed as f64 / self.input.sample_rate() as f64 / self.input.channels() as f64 + self.samples_collected as f64 + / self.input.sample_rate() as f64 + / self.input.channels() as f64 + + self.offset_duration + } + + #[inline] + fn set_current_frame(&mut self) { + self.current_frame_len = self.current_frame_len(); + self.current_frame_sample_rate = self.sample_rate(); + self.current_frame_channels = self.channels(); } } @@ -59,9 +77,28 @@ where #[inline] fn next(&mut self) -> Option { + // This should only be executed once at the first call to next. + if self.current_frame_len.is_none() { + self.set_current_frame(); + } + let item = self.input.next(); if item.is_some() { - self.samples_elapsed += 1; + self.samples_collected += 1; + + // At the end of a frame add the duration of this frame to + // offset_duration and start collecting samples again. + if let Some(frame_len) = self.current_frame_len() { + if self.samples_collected == frame_len { + self.offset_duration += self.samples_collected as f64 + / self.current_frame_sample_rate as f64 + / self.current_frame_channels as f64; + + // Reset. + self.samples_collected = 0; + self.set_current_frame(); + }; + }; }; item } @@ -101,9 +138,7 @@ where fn try_seek(&mut self, pos: Duration) -> Result<(), SeekError> { let result = self.input.try_seek(pos); if result.is_ok() { - self.samples_elapsed = (pos.as_secs_f64() - * self.input.sample_rate() as f64 - * self.input.channels() as f64) as usize; + self.offset_duration = pos.as_secs_f64(); } result } From ca43ad088526d29612c25bb8e83063f1c5657d1b Mon Sep 17 00:00:00 2001 From: Gusted Date: Sun, 16 Jun 2024 18:07:36 +0200 Subject: [PATCH 3/5] Refactoring --- src/sink.rs | 36 ++++++++++++++++++------ src/source/mod.rs | 6 ++-- src/source/position.rs | 64 +++++++++++++++++++++++++----------------- 3 files changed, 69 insertions(+), 37 deletions(-) diff --git a/src/sink.rs b/src/sink.rs index f682ab2b..39cc5c9a 100644 --- a/src/sink.rs +++ b/src/sink.rs @@ -1,4 +1,4 @@ -use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; use std::time::Duration; @@ -12,6 +12,28 @@ use crate::stream::{OutputStreamHandle, PlayError}; use crate::{queue, source::Done, Sample, Source}; use cpal::FromSample; +#[derive(Debug)] +pub struct AtomicF64 { + storage: AtomicU64, +} + +impl AtomicF64 { + pub fn new(value: f64) -> Self { + let as_u64 = value.to_bits(); + Self { + storage: AtomicU64::new(as_u64), + } + } + pub fn store(&self, value: f64, ordering: Ordering) { + let as_u64 = value.to_bits(); + self.storage.store(as_u64, ordering) + } + pub fn load(&self, ordering: Ordering) -> f64 { + let as_u64 = self.storage.load(ordering); + f64::from_bits(as_u64) + } +} + /// Handle to a device that outputs sounds. /// /// Dropping the `Sink` stops all sounds. You can use `detach` if you want the sounds to continue @@ -22,6 +44,7 @@ pub struct Sink { controls: Arc, sound_count: Arc, + position: Arc, detached: bool, } @@ -64,7 +87,6 @@ struct Controls { speed: Mutex, to_clear: Mutex, seek: Mutex>, - position: Mutex, } impl Sink { @@ -91,9 +113,9 @@ impl Sink { speed: Mutex::new(1.0), to_clear: Mutex::new(0), seek: Mutex::new(None), - position: Mutex::new(0.0), }), sound_count: Arc::new(AtomicUsize::new(0)), + position: Arc::new(AtomicF64::new(0.0)), detached: false, }; (sink, queue_rx) @@ -121,7 +143,7 @@ impl Sink { let source = source .speed(1.0) - .trackable() + .trackable(self.position.clone()) .pausable(false) .amplify(1.0) .skippable() @@ -130,16 +152,12 @@ impl Sink { .periodic_access(Duration::from_millis(5), move |src| { if controls.stopped.load(Ordering::SeqCst) { src.stop(); - *controls.position.lock().unwrap() = 0.0; } { let mut to_clear = controls.to_clear.lock().unwrap(); if *to_clear > 0 { src.inner_mut().skip(); *to_clear -= 1; - *controls.position.lock().unwrap() = 0.0; - } else { - *controls.position.lock().unwrap() = src.inner().inner().inner().inner().get_pos(); } } let amp = src.inner_mut().inner_mut(); @@ -321,7 +339,7 @@ impl Sink { /// Returns the position of the sound that's being played. #[inline] pub fn get_pos(&self) -> f64 { - *self.controls.position.lock().unwrap() + self.position.load(Ordering::Relaxed) } } diff --git a/src/source/mod.rs b/src/source/mod.rs index 8d1a63bb..066ac500 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -1,9 +1,11 @@ //! Sources of sound and various filters. +use std::sync::Arc; use std::time::Duration; use cpal::FromSample; +use crate::sink::AtomicF64; use crate::Sample; pub use self::amplify::Amplify; @@ -335,11 +337,11 @@ where skippable::skippable(self) } - fn trackable(self) -> TrackPosition + fn trackable(self, position: Arc) -> TrackPosition where Self: Sized, { - position::trackable(self) + position::trackable(self, position) } /// Applies a low-pass filter to the source. diff --git a/src/source/position.rs b/src/source/position.rs index dab444d9..93baa67c 100644 --- a/src/source/position.rs +++ b/src/source/position.rs @@ -1,26 +1,31 @@ -use std::time::Duration; +use std::{ + sync::{atomic::Ordering, Arc}, + time::Duration, +}; -use crate::{Sample, Source}; +use crate::{sink::AtomicF64, Sample, Source}; use super::SeekError; /// Internal function that builds a `TrackPosition` object. -pub fn trackable(source: I) -> TrackPosition { +pub fn trackable(source: I, position: Arc) -> TrackPosition { TrackPosition { input: source, - samples_collected: 0, + samples_counted: 0, offset_duration: 0.0, + position, current_frame_sample_rate: 0, current_frame_channels: 0, current_frame_len: None, } } -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct TrackPosition { input: I, - samples_collected: usize, + samples_counted: usize, offset_duration: f64, + position: Arc, current_frame_sample_rate: u32, current_frame_channels: u16, current_frame_len: Option, @@ -53,10 +58,8 @@ where { /// Returns the position of the source. #[inline] - pub fn get_pos(&self) -> f64 { - self.samples_collected as f64 - / self.input.sample_rate() as f64 - / self.input.channels() as f64 + fn get_pos(&self) -> f64 { + self.samples_counted as f64 / self.input.sample_rate() as f64 / self.input.channels() as f64 + self.offset_duration } @@ -84,22 +87,21 @@ where let item = self.input.next(); if item.is_some() { - self.samples_collected += 1; + self.samples_counted += 1; // At the end of a frame add the duration of this frame to // offset_duration and start collecting samples again. - if let Some(frame_len) = self.current_frame_len() { - if self.samples_collected == frame_len { - self.offset_duration += self.samples_collected as f64 - / self.current_frame_sample_rate as f64 - / self.current_frame_channels as f64; - - // Reset. - self.samples_collected = 0; - self.set_current_frame(); - }; + if Some(self.samples_counted) == self.current_frame_len() { + self.offset_duration += self.samples_counted as f64 + / self.current_frame_sample_rate as f64 + / self.current_frame_channels as f64; + + // Reset. + self.samples_counted = 0; + self.set_current_frame(); }; }; + self.position.store(self.get_pos(), Ordering::Relaxed); item } @@ -139,6 +141,11 @@ where let result = self.input.try_seek(pos); if result.is_ok() { self.offset_duration = pos.as_secs_f64(); + // This assumes that the seek implementation of the codec always + // starts again at the beginning of a frame. Which is the case with + // symphonia. + self.samples_counted = 0; + self.position.store(self.get_pos(), Ordering::Relaxed); } result } @@ -146,23 +153,28 @@ where #[cfg(test)] mod tests { + use std::sync::atomic::Ordering; + use std::sync::Arc; use std::time::Duration; use crate::buffer::SamplesBuffer; + use crate::sink::AtomicF64; use crate::source::Source; #[test] fn test_position() { let inner = SamplesBuffer::new(1, 1, vec![10i16, -10, 10, -10, 20, -20]); - let mut source = inner.trackable(); + let position = Arc::new(AtomicF64::new(0.0)); + let mut source = inner.trackable(position.clone()); - assert_eq!(source.get_pos(), 0.0); + assert_eq!(position.load(Ordering::Relaxed), 0.0); source.next(); - assert_eq!(source.get_pos(), 1.0); + assert_eq!(position.load(Ordering::Relaxed), 1.0); + source.next(); - assert_eq!(source.get_pos(), 2.0); + assert_eq!(position.load(Ordering::Relaxed), 2.0); assert_eq!(source.try_seek(Duration::new(1, 0)).is_ok(), true); - assert_eq!(source.get_pos(), 1.0); + assert_eq!(position.load(Ordering::Relaxed), 1.0); } } From 80277e03f6369a0658acbfa5d66470cee4418287 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 17 Jun 2024 13:00:26 +0200 Subject: [PATCH 4/5] Revert Arc stuff --- src/sink.rs | 36 +++++++++--------------------------- src/source/mod.rs | 6 ++---- src/source/position.rs | 29 +++++++++-------------------- 3 files changed, 20 insertions(+), 51 deletions(-) diff --git a/src/sink.rs b/src/sink.rs index 39cc5c9a..e93ceb73 100644 --- a/src/sink.rs +++ b/src/sink.rs @@ -1,4 +1,4 @@ -use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; use std::time::Duration; @@ -12,28 +12,6 @@ use crate::stream::{OutputStreamHandle, PlayError}; use crate::{queue, source::Done, Sample, Source}; use cpal::FromSample; -#[derive(Debug)] -pub struct AtomicF64 { - storage: AtomicU64, -} - -impl AtomicF64 { - pub fn new(value: f64) -> Self { - let as_u64 = value.to_bits(); - Self { - storage: AtomicU64::new(as_u64), - } - } - pub fn store(&self, value: f64, ordering: Ordering) { - let as_u64 = value.to_bits(); - self.storage.store(as_u64, ordering) - } - pub fn load(&self, ordering: Ordering) -> f64 { - let as_u64 = self.storage.load(ordering); - f64::from_bits(as_u64) - } -} - /// Handle to a device that outputs sounds. /// /// Dropping the `Sink` stops all sounds. You can use `detach` if you want the sounds to continue @@ -44,7 +22,6 @@ pub struct Sink { controls: Arc, sound_count: Arc, - position: Arc, detached: bool, } @@ -87,6 +64,7 @@ struct Controls { speed: Mutex, to_clear: Mutex, seek: Mutex>, + position: Mutex, } impl Sink { @@ -113,9 +91,9 @@ impl Sink { speed: Mutex::new(1.0), to_clear: Mutex::new(0), seek: Mutex::new(None), + position: Mutex::new(0.0), }), sound_count: Arc::new(AtomicUsize::new(0)), - position: Arc::new(AtomicF64::new(0.0)), detached: false, }; (sink, queue_rx) @@ -143,7 +121,7 @@ impl Sink { let source = source .speed(1.0) - .trackable(self.position.clone()) + .trackable() .pausable(false) .amplify(1.0) .skippable() @@ -152,12 +130,16 @@ impl Sink { .periodic_access(Duration::from_millis(5), move |src| { if controls.stopped.load(Ordering::SeqCst) { src.stop(); + *controls.position.lock().unwrap() = 0.0; } { let mut to_clear = controls.to_clear.lock().unwrap(); if *to_clear > 0 { src.inner_mut().skip(); *to_clear -= 1; + *controls.position.lock().unwrap() = 0.0; + } else { + *controls.position.lock().unwrap() = src.inner().inner().inner().inner().get_pos(); } } let amp = src.inner_mut().inner_mut(); @@ -339,7 +321,7 @@ impl Sink { /// Returns the position of the sound that's being played. #[inline] pub fn get_pos(&self) -> f64 { - self.position.load(Ordering::Relaxed) + *self.controls.position.lock().unwrap() } } diff --git a/src/source/mod.rs b/src/source/mod.rs index 066ac500..8d1a63bb 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -1,11 +1,9 @@ //! Sources of sound and various filters. -use std::sync::Arc; use std::time::Duration; use cpal::FromSample; -use crate::sink::AtomicF64; use crate::Sample; pub use self::amplify::Amplify; @@ -337,11 +335,11 @@ where skippable::skippable(self) } - fn trackable(self, position: Arc) -> TrackPosition + fn trackable(self) -> TrackPosition where Self: Sized, { - position::trackable(self, position) + position::trackable(self) } /// Applies a low-pass filter to the source. diff --git a/src/source/position.rs b/src/source/position.rs index 93baa67c..1b1952eb 100644 --- a/src/source/position.rs +++ b/src/source/position.rs @@ -1,19 +1,15 @@ -use std::{ - sync::{atomic::Ordering, Arc}, - time::Duration, -}; +use std::time::Duration; -use crate::{sink::AtomicF64, Sample, Source}; +use crate::{Sample, Source}; use super::SeekError; /// Internal function that builds a `TrackPosition` object. -pub fn trackable(source: I, position: Arc) -> TrackPosition { +pub fn trackable(source: I) -> TrackPosition { TrackPosition { input: source, samples_counted: 0, offset_duration: 0.0, - position, current_frame_sample_rate: 0, current_frame_channels: 0, current_frame_len: None, @@ -25,7 +21,6 @@ pub struct TrackPosition { input: I, samples_counted: usize, offset_duration: f64, - position: Arc, current_frame_sample_rate: u32, current_frame_channels: u16, current_frame_len: Option, @@ -58,7 +53,7 @@ where { /// Returns the position of the source. #[inline] - fn get_pos(&self) -> f64 { + pub fn get_pos(&self) -> f64 { self.samples_counted as f64 / self.input.sample_rate() as f64 / self.input.channels() as f64 + self.offset_duration } @@ -101,7 +96,6 @@ where self.set_current_frame(); }; }; - self.position.store(self.get_pos(), Ordering::Relaxed); item } @@ -145,7 +139,6 @@ where // starts again at the beginning of a frame. Which is the case with // symphonia. self.samples_counted = 0; - self.position.store(self.get_pos(), Ordering::Relaxed); } result } @@ -153,28 +146,24 @@ where #[cfg(test)] mod tests { - use std::sync::atomic::Ordering; - use std::sync::Arc; use std::time::Duration; use crate::buffer::SamplesBuffer; - use crate::sink::AtomicF64; use crate::source::Source; #[test] fn test_position() { let inner = SamplesBuffer::new(1, 1, vec![10i16, -10, 10, -10, 20, -20]); - let position = Arc::new(AtomicF64::new(0.0)); - let mut source = inner.trackable(position.clone()); + let mut source = inner.trackable(); - assert_eq!(position.load(Ordering::Relaxed), 0.0); + assert_eq!(source.get_pos(), 0.0); source.next(); - assert_eq!(position.load(Ordering::Relaxed), 1.0); + assert_eq!(source.get_pos(), 1.0); source.next(); - assert_eq!(position.load(Ordering::Relaxed), 2.0); + assert_eq!(source.get_pos(), 2.0); assert_eq!(source.try_seek(Duration::new(1, 0)).is_ok(), true); - assert_eq!(position.load(Ordering::Relaxed), 1.0); + assert_eq!(source.get_pos(), 1.0); } } From 16a1440d04ede86c77ca3f35e2c3fe6281232b0d Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 17 Jun 2024 18:24:53 +0200 Subject: [PATCH 5/5] Better naming --- src/sink.rs | 2 +- src/source/mod.rs | 4 ++-- src/source/position.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sink.rs b/src/sink.rs index e93ceb73..722dc8bf 100644 --- a/src/sink.rs +++ b/src/sink.rs @@ -121,7 +121,7 @@ impl Sink { let source = source .speed(1.0) - .trackable() + .track_position() .pausable(false) .amplify(1.0) .skippable() diff --git a/src/source/mod.rs b/src/source/mod.rs index 8d1a63bb..72640430 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -335,11 +335,11 @@ where skippable::skippable(self) } - fn trackable(self) -> TrackPosition + fn track_position(self) -> TrackPosition where Self: Sized, { - position::trackable(self) + position::track_position(self) } /// Applies a low-pass filter to the source. diff --git a/src/source/position.rs b/src/source/position.rs index 1b1952eb..e59c60a2 100644 --- a/src/source/position.rs +++ b/src/source/position.rs @@ -5,7 +5,7 @@ use crate::{Sample, Source}; use super::SeekError; /// Internal function that builds a `TrackPosition` object. -pub fn trackable(source: I) -> TrackPosition { +pub fn track_position(source: I) -> TrackPosition { TrackPosition { input: source, samples_counted: 0, @@ -154,7 +154,7 @@ mod tests { #[test] fn test_position() { let inner = SamplesBuffer::new(1, 1, vec![10i16, -10, 10, -10, 20, -20]); - let mut source = inner.trackable(); + let mut source = inner.track_position(); assert_eq!(source.get_pos(), 0.0); source.next();