Skip to content

Commit 19e6d80

Browse files
committed
Fix #49: Revise the README doc
Change example to illustrate that the interpolated sample tapers to 0 at the end (to fill the expected length) and to ensure that it does not use an old API.
1 parent b663126 commit 19e6d80

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ assert_eq!(added, vec![[0.4], [-0.5], [-0.3]]);
7272

7373
// Scale the playback rate by `0.5`.
7474
let foo = [[0.0], [1.0], [0.0], [-1.0]];
75-
let frames: Vec<_> = foo.iter().cloned().scale_hz(0.5).collect();
76-
assert_eq!(&frames[..], &[[0.0], [0.5], [1.0], [0.5], [0.0], [-0.5], [-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();
78+
assert_eq!(&frames[..], &[[0.0], [0.5], [1.0], [0.5], [0.0], [-0.5], [-1.0], [-0.5]][..]);
7779
```
7880

7981
The **signal** module also provides a series of **Signal** source types,
@@ -120,9 +122,12 @@ of sample types. Traits include:
120122
- `FromFrameSliceMut`, `ToFrameSliceMut`, `DuplexFrameSliceMut`,
121123
- `DuplexSlice`, `DuplexSliceMut`,
122124

123-
The **rate** module provides a **Converter** type, for converting and
125+
The **interpolate** module provides a **Converter** type, for converting and
124126
interpolating the rate of **Signal**s. This can be useful for both sample rate
125-
conversion and playback rate multiplication.
127+
conversion and playback rate multiplication. **Converter**s can use a range of
128+
interpolation methods, with Floor, Linear, and Sinc interpolation provided in
129+
the library. (NB: Sinc interpolation currently requires heap allocation, as it
130+
uses VecDeque.)
126131

127132
Using in a `no_std` environment
128133
-------------------------------

tests/interpolate.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
extern crate sample;
44

55
use sample::interpolate::{Converter, Floor, Linear};
6+
use sample::Signal;
67

78
#[test]
89
fn test_floor_converter() {
@@ -42,3 +43,12 @@ fn test_linear_converter() {
4243
assert_eq!(conv.next(), None);
4344
}
4445

46+
#[test]
47+
fn test_scale_playback_rate() {
48+
// Scale the playback rate by `0.5`
49+
let foo = [[0.0], [1.0], [0.0], [-1.0]];
50+
let mut source = foo.iter().cloned();
51+
let interp = Linear::from_source(&mut source).unwrap();
52+
let frames: Vec<_> = source.scale_hz(interp, 0.5).collect();
53+
assert_eq!(&frames[..], &[[0.0], [0.5], [1.0], [0.5], [0.0], [-0.5], [-1.0], [-0.5]][..]);
54+
}

0 commit comments

Comments
 (0)