@@ -7,7 +7,7 @@ use std::time::Duration;
77///
88/// Only the crossfaded portion (beginning of fadeout, beginning of fadein) is
99/// returned.
10- pub fn crossfade < I1 , I2 > (
10+ pub ( crate ) fn crossfade < I1 , I2 > (
1111 input_fadeout : I1 ,
1212 input_fadein : I2 ,
1313 duration : Duration ,
2828/// Only the crossfaded portion (beginning of fadeout, beginning of fadein) is
2929/// covered.
3030pub 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