@@ -50,38 +50,39 @@ let bar: [u8; 2] = foo.map(Sample::to_sample);
50
50
assert_eq! (bar , [128u8 , 128 ]);
51
51
```
52
52
53
- Use the ** Signal** trait for working with ` Iterator ` s that yield ` Frame ` s.
54
- To complement the ` Iterator ` trait, ** Signal** provides methods for adding,
55
- scaling, offsetting, multiplying, clipping and generating frame iterators and
56
- more. Working with ** Signal** s allows for easy, readable creation of rich and
57
- complex DSP graphs with a simple and familiar API.
53
+ Use the ** Signal** trait for working with infinite-iterator-like types that
54
+ yield ` Frame ` s. ** Signal** provides methods for adding, scaling, offsetting ,
55
+ multiplying, clipping and generating streams of ` Frame ` s. Working with
56
+ ** Signal** s allows for easy, readable creation of rich and complex DSP graphs
57
+ with a simple and familiar API.
58
58
59
59
``` rust
60
60
// Clip to an amplitude of 0.9.
61
61
let frames = [[1.2 , 0.8 ], [- 0.7 , - 1.4 ]];
62
- let clipped : Vec <_ > = frames . iter () . cloned () . clip_amp (0.9 ). collect ();
62
+ let clipped : Vec <_ > = signal :: from_slice ( & frames ) . clip_amp (0.9 ) . take ( 2 ). collect ();
63
63
assert_eq! (clipped , vec! [[0.9 , 0.8 ], [- 0.7 , - 0.9 ]]);
64
64
65
65
// Add `a` with `b` and yield the result.
66
66
let a = [[0.2 ], [- 0.6 ], [0.5 ]];
67
67
let b = [[0.2 ], [0.1 ], [- 0.8 ]];
68
- let a_signal = a . iter () . cloned ( );
69
- let b_signal = b . iter () . cloned ( );
70
- let added : Vec <[f32 ; 1 ]> = a_signal . add_amp (b_signal ). collect ();
68
+ let a_signal = signal :: from_slice ( & a );
69
+ let b_signal = signal :: from_slice ( & b );
70
+ let added : Vec <[f32 ; 1 ]> = a_signal . add_amp (b_signal ). take ( 3 ) . collect ();
71
71
assert_eq! (added , vec! [[0.4 ], [- 0.5 ], [- 0.3 ]]);
72
72
73
73
// Scale the playback rate by `0.5`.
74
74
let foo = [[0.0 ], [1.0 ], [0.0 ], [- 1.0 ]];
75
- let mut source = foo . iter () . cloned ( );
76
- let interp = Linear :: from_source (& mut source ). unwrap () ;
77
- let frames : Vec <_ > = source . scale_hz (interp , 0.5 ). collect ();
75
+ let mut source = signal :: from_slice ( & foo );
76
+ let interp = Linear :: from_source (& mut source );
77
+ let frames : Vec <_ > = source . scale_hz (interp , 0.5 ). take ( 8 ) . collect ();
78
78
assert_eq! (& frames [.. ], & [[0.0 ], [0.5 ], [1.0 ], [0.5 ], [0.0 ], [- 0.5 ], [- 1.0 ], [- 0.5 ]][.. ]);
79
79
```
80
80
81
81
The ** signal** module also provides a series of ** Signal** source types,
82
82
including:
83
83
84
- - ` FromInterleavedSamples `
84
+ - ` FromIterator `
85
+ - ` FromInterleavedSamplesIterator `
85
86
- ` Equilibrium ` (silent signal)
86
87
- ` Phase `
87
88
- ` Sine `
0 commit comments