|
63 | 63 | /// speedup's and delay's into account. Its recommended therefore to apply
|
64 | 64 | /// track_position after speedup's and delay's.
|
65 | 65 | #[inline]
|
66 |
| - pub fn get_pos(&self) -> f64 { |
67 |
| - self.samples_counted as f64 / self.input.sample_rate() as f64 / self.input.channels() as f64 |
68 |
| - + self.offset_duration |
| 66 | + pub fn get_pos(&self) -> Duration { |
| 67 | + let seconds = self.samples_counted as f64 |
| 68 | + / self.input.sample_rate() as f64 |
| 69 | + / self.input.channels() as f64 |
| 70 | + + self.offset_duration; |
| 71 | + Duration::from_secs_f64(seconds) |
69 | 72 | }
|
70 | 73 |
|
71 | 74 | #[inline]
|
@@ -166,14 +169,30 @@ mod tests {
|
166 | 169 | let inner = SamplesBuffer::new(1, 1, vec![10i16, -10, 10, -10, 20, -20]);
|
167 | 170 | let mut source = inner.track_position();
|
168 | 171 |
|
169 |
| - assert_eq!(source.get_pos(), 0.0); |
| 172 | + assert_eq!(source.get_pos().as_secs_f32(), 0.0); |
170 | 173 | source.next();
|
171 |
| - assert_eq!(source.get_pos(), 1.0); |
| 174 | + assert_eq!(source.get_pos().as_secs_f32(), 1.0); |
172 | 175 |
|
173 | 176 | source.next();
|
174 |
| - assert_eq!(source.get_pos(), 2.0); |
| 177 | + assert_eq!(source.get_pos().as_secs_f32(), 2.0); |
175 | 178 |
|
176 | 179 | assert_eq!(source.try_seek(Duration::new(1, 0)).is_ok(), true);
|
177 |
| - assert_eq!(source.get_pos(), 1.0); |
| 180 | + assert_eq!(source.get_pos().as_secs_f32(), 1.0); |
| 181 | + } |
| 182 | + |
| 183 | + #[test] |
| 184 | + fn test_position_in_presence_of_speedup() { |
| 185 | + let inner = SamplesBuffer::new(1, 1, vec![10i16, -10, 10, -10, 20, -20]); |
| 186 | + let mut source = inner.speed(2.0).track_position(); |
| 187 | + |
| 188 | + assert_eq!(source.get_pos().as_secs_f32(), 0.0); |
| 189 | + source.next(); |
| 190 | + assert_eq!(source.get_pos().as_secs_f32(), 0.5); |
| 191 | + |
| 192 | + source.next(); |
| 193 | + assert_eq!(source.get_pos().as_secs_f32(), 1.0); |
| 194 | + |
| 195 | + assert_eq!(source.try_seek(Duration::new(1, 0)).is_ok(), true); |
| 196 | + assert_eq!(source.get_pos().as_secs_f32(), 1.0); |
178 | 197 | }
|
179 | 198 | }
|
0 commit comments