Skip to content

Commit 637aec4

Browse files
committed
adds more details to track_position/get_pos docs
1 parent edbe3f5 commit 637aec4

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

src/sink.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ impl Sink {
121121

122122
let source = source
123123
.speed(1.0)
124-
.track_position()
124+
// must be placed before pausable but after speed & delay
125+
.track_position()
125126
.pausable(false)
126127
.amplify(1.0)
127128
.skippable()
@@ -319,6 +320,12 @@ impl Sink {
319320
}
320321

321322
/// Returns the position of the sound that's being played.
323+
///
324+
/// This takes into account any speedup or delay applied.
325+
///
326+
/// Example: if you apply a speedup of *2* to an mp3 decoder source and
327+
/// [`get_pos()`](Sink::get_pos) returns *5s* then the position in the mp3
328+
/// recording is *10s* from its start.
322329
#[inline]
323330
pub fn get_pos(&self) -> f64 {
324331
*self.controls.position.lock().unwrap()

src/source/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,16 @@ where
335335
skippable::skippable(self)
336336
}
337337

338+
/// Start tracking the elapsed duration since the start of the underlying
339+
/// source.
340+
///
341+
/// If a speedup and or delay is applied after this that will not be reflected
342+
/// in the position returned by [`get_pos`](TrackPosition::get_pos).
343+
///
344+
/// This can get confusing when using [`get_pos()`](TrackPosition::get_pos)
345+
/// together with [`Source::try_seek()`] as the the latter does take all
346+
/// speedup's and delay's into account. Its recommended therefore to apply
347+
/// track_position after speedup's and delay's.
338348
fn track_position(self) -> TrackPosition<Self>
339349
where
340350
Self: Sized,

src/source/position.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::{Sample, Source};
44

55
use super::SeekError;
66

7-
/// Internal function that builds a `TrackPosition` object.
7+
/// Internal function that builds a `TrackPosition` object. See trait docs for
8+
/// details
89
pub fn track_position<I>(source: I) -> TrackPosition<I> {
910
TrackPosition {
1011
input: source,
@@ -51,7 +52,16 @@ where
5152
I: Source,
5253
I::Item: Sample,
5354
{
54-
/// Returns the position of the source.
55+
/// Returns the position of the underlying source relative to its start.
56+
///
57+
/// If a speedup and or delay is applied after applying a
58+
/// [`Source::track_position`] it will not be reflected in the position
59+
/// returned by [`get_pos`](TrackPosition::get_pos).
60+
///
61+
/// This can get confusing when using [`get_pos()`](TrackPosition::get_pos)
62+
/// together with [`Source::try_seek()`] as the the latter does take all
63+
/// speedup's and delay's into account. Its recommended therefore to apply
64+
/// track_position after speedup's and delay's.
5565
#[inline]
5666
pub fn get_pos(&self) -> f64 {
5767
self.samples_counted as f64 / self.input.sample_rate() as f64 / self.input.channels() as f64

src/spatial_sink.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ impl SpatialSink {
197197
}
198198

199199
/// Returns the position of the sound that's being played.
200+
///
201+
/// This takes into account any speedup or delay applied.
202+
///
203+
/// Example: if you apply a speedup of *2* to an mp3 decoder source and
204+
/// [`get_pos()`](Sink::get_pos) returns *5s* then the position in the mp3
205+
/// recording is *10s* from its start.
200206
#[inline]
201207
pub fn get_pos(&self) -> f64 {
202208
self.sink.get_pos()

0 commit comments

Comments
 (0)