@@ -7,7 +7,7 @@ use std::time::Duration;
7
7
///
8
8
/// Only the crossfaded portion (beginning of fadeout, beginning of fadein) is
9
9
/// returned.
10
- pub fn crossfade < I1 , I2 > (
10
+ pub ( crate ) fn crossfade < I1 , I2 > (
11
11
input_fadeout : I1 ,
12
12
input_fadein : I2 ,
13
13
duration : Duration ,
28
28
/// Only the crossfaded portion (beginning of fadeout, beginning of fadein) is
29
29
/// covered.
30
30
pub type Crossfade < I1 , I2 > = Mix < TakeDuration < I1 > , FadeIn < TakeDuration < I2 > > > ;
31
-
32
- #[ cfg( test) ]
33
- mod tests {
34
- use super :: * ;
35
- use crate :: buffer:: SamplesBuffer ;
36
- use crate :: source:: Zero ;
37
-
38
- fn dummy_source ( length : u8 ) -> SamplesBuffer {
39
- let data: Vec < f32 > = ( 1 ..=length) . map ( f32:: from) . collect ( ) ;
40
- SamplesBuffer :: new ( 1 , 1 , data)
41
- }
42
-
43
- #[ test]
44
- fn test_crossfade_with_self ( ) {
45
- let source1 = dummy_source ( 10 ) ;
46
- let source2 = dummy_source ( 10 ) ;
47
- let mut mixed = crossfade (
48
- source1,
49
- source2,
50
- Duration :: from_secs ( 5 ) + Duration :: from_nanos ( 1 ) ,
51
- ) ;
52
- assert_eq ! ( mixed. next( ) , Some ( 1.0 ) ) ;
53
- assert_eq ! ( mixed. next( ) , Some ( 2.0 ) ) ;
54
- assert_eq ! ( mixed. next( ) , Some ( 3.0 ) ) ;
55
- assert_eq ! ( mixed. next( ) , Some ( 4.0 ) ) ;
56
- assert_eq ! ( mixed. next( ) , Some ( 5.0 ) ) ;
57
- assert_eq ! ( mixed. next( ) , None ) ;
58
- }
59
-
60
- #[ test]
61
- fn test_crossfade ( ) {
62
- let source1 = dummy_source ( 10 ) ;
63
- let source2 = Zero :: new ( 1 , 1 ) ;
64
- let mixed = crossfade (
65
- source1,
66
- source2,
67
- Duration :: from_secs ( 5 ) + Duration :: from_nanos ( 1 ) ,
68
- ) ;
69
- let result = mixed. collect :: < Vec < _ > > ( ) ;
70
- assert_eq ! ( result. len( ) , 5 ) ;
71
- assert ! ( result
72
- . iter( )
73
- . zip( vec![ 1.0 , 2.0 * 0.8 , 3.0 * 0.6 , 4.0 * 0.4 , 5.0 * 0.2 ] )
74
- . all( |( a, b) | ( a - b) . abs( ) < 1e-6 ) ) ;
75
- }
76
- }
0 commit comments