Commit c9ddc76 1 parent a9a1886 commit c9ddc76 Copy full SHA for c9ddc76
File tree 4 files changed +35
-0
lines changed
4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -313,6 +313,12 @@ impl StaticSoundData {
313
313
Duration :: from_secs_f64 ( self . num_frames ( ) as f64 / self . sample_rate as f64 )
314
314
}
315
315
316
+ /// Returns the total duration of the audio, regardless of its slice.
317
+ #[ must_use]
318
+ pub fn unsliced_duration ( & self ) -> Duration {
319
+ Duration :: from_secs_f64 ( self . frames . len ( ) as f64 / self . sample_rate as f64 )
320
+ }
321
+
316
322
/// Returns the nth [`Frame`] of audio in the [`StaticSoundData`].
317
323
///
318
324
/// If [`StaticSoundData::slice`] is `Some`, this will behave as if the [`StaticSoundData`]
Original file line number Diff line number Diff line change @@ -15,6 +15,17 @@ fn duration() {
15
15
assert_eq ! ( static_sound. duration( ) , Duration :: from_secs( 4 ) ) ;
16
16
}
17
17
18
+ #[ test]
19
+ fn unsliced_duration ( ) {
20
+ let static_sound = StaticSoundData {
21
+ sample_rate : 1 ,
22
+ frames : Arc :: new ( [ Frame :: from_mono ( 0.0 ) ; 4 ] ) ,
23
+ settings : Default :: default ( ) ,
24
+ slice : Some ( ( 2 , 3 ) ) ,
25
+ } ;
26
+ assert_eq ! ( static_sound. unsliced_duration( ) , Duration :: from_secs( 4 ) ) ;
27
+ }
28
+
18
29
#[ test]
19
30
fn sliced_duration ( ) {
20
31
let static_sound = StaticSoundData {
Original file line number Diff line number Diff line change @@ -291,6 +291,14 @@ impl<Error: Send> StreamingSoundData<Error> {
291
291
Duration :: from_secs_f64 ( self . num_frames ( ) as f64 / self . decoder . sample_rate ( ) as f64 )
292
292
}
293
293
294
+ /// Returns the total duration of the audio, regardless of its slice.
295
+ #[ must_use]
296
+ pub fn unsliced_duration ( & self ) -> Duration {
297
+ Duration :: from_secs_f64 (
298
+ self . decoder . num_frames ( ) as f64 / self . decoder . sample_rate ( ) as f64 ,
299
+ )
300
+ }
301
+
294
302
/**
295
303
Sets the portion of the audio this [`StreamingSoundData`] represents.
296
304
*/
Original file line number Diff line number Diff line change @@ -15,6 +15,16 @@ fn duration() {
15
15
assert_eq ! ( sound. duration( ) , Duration :: from_secs( 4 ) ) ;
16
16
}
17
17
18
+ #[ test]
19
+ fn unsliced_duration ( ) {
20
+ let sound = StreamingSoundData {
21
+ decoder : Box :: new ( MockDecoder :: new ( vec ! [ Frame :: from_mono( 0.5 ) ; 4 ] ) ) ,
22
+ settings : Default :: default ( ) ,
23
+ slice : Some ( ( 2 , 3 ) ) ,
24
+ } ;
25
+ assert_eq ! ( sound. unsliced_duration( ) , Duration :: from_secs( 4 ) ) ;
26
+ }
27
+
18
28
#[ test]
19
29
fn sliced_duration ( ) {
20
30
let sound = StreamingSoundData {
You can’t perform that action at this time.
0 commit comments