File tree Expand file tree Collapse file tree 4 files changed +36
-3
lines changed Expand file tree Collapse file tree 4 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,8 @@ impl Sink {
121
121
122
122
let source = source
123
123
. speed ( 1.0 )
124
- . track_position ( )
124
+ // must be placed before pausable but after speed & delay
125
+ . track_position ( )
125
126
. pausable ( false )
126
127
. amplify ( 1.0 )
127
128
. skippable ( )
@@ -319,6 +320,12 @@ impl Sink {
319
320
}
320
321
321
322
/// 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.
322
329
#[ inline]
323
330
pub fn get_pos ( & self ) -> f64 {
324
331
* self . controls . position . lock ( ) . unwrap ( )
Original file line number Diff line number Diff line change @@ -335,6 +335,16 @@ where
335
335
skippable:: skippable ( self )
336
336
}
337
337
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.
338
348
fn track_position ( self ) -> TrackPosition < Self >
339
349
where
340
350
Self : Sized ,
Original file line number Diff line number Diff line change @@ -4,7 +4,8 @@ use crate::{Sample, Source};
4
4
5
5
use super :: SeekError ;
6
6
7
- /// Internal function that builds a `TrackPosition` object.
7
+ /// Internal function that builds a `TrackPosition` object. See trait docs for
8
+ /// details
8
9
pub fn track_position < I > ( source : I ) -> TrackPosition < I > {
9
10
TrackPosition {
10
11
input : source,
51
52
I : Source ,
52
53
I :: Item : Sample ,
53
54
{
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.
55
65
#[ inline]
56
66
pub fn get_pos ( & self ) -> f64 {
57
67
self . samples_counted as f64 / self . input . sample_rate ( ) as f64 / self . input . channels ( ) as f64
Original file line number Diff line number Diff line change @@ -197,6 +197,12 @@ impl SpatialSink {
197
197
}
198
198
199
199
/// 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.
200
206
#[ inline]
201
207
pub fn get_pos ( & self ) -> f64 {
202
208
self . sink . get_pos ( )
You can’t perform that action at this time.
0 commit comments