Skip to content

Commit

Permalink
Merge pull request #52 from andrewcsmith/fix-49-readme-doc-with-no-ra…
Browse files Browse the repository at this point in the history
…te-module

Fix 49: readme doc with no rate module
  • Loading branch information
mitchmindtree authored Jun 27, 2017
2 parents 2a0a0de + 19e6d80 commit 9c4e954
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ assert_eq!(added, vec![[0.4], [-0.5], [-0.3]]);

// Scale the playback rate by `0.5`.
let foo = [[0.0], [1.0], [0.0], [-1.0]];
let frames: Vec<_> = foo.iter().cloned().scale_hz(0.5).collect();
assert_eq!(&frames[..], &[[0.0], [0.5], [1.0], [0.5], [0.0], [-0.5], [-1.0]][..]);
let mut source = foo.iter().cloned();
let interp = Linear::from_source(&mut source).unwrap();
let frames: Vec<_> = source.scale_hz(interp, 0.5).collect();
assert_eq!(&frames[..], &[[0.0], [0.5], [1.0], [0.5], [0.0], [-0.5], [-1.0], [-0.5]][..]);
```

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

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

Using in a `no_std` environment
-------------------------------
Expand Down
10 changes: 10 additions & 0 deletions tests/interpolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
extern crate sample;

use sample::interpolate::{Converter, Floor, Linear};
use sample::Signal;

#[test]
fn test_floor_converter() {
Expand Down Expand Up @@ -42,3 +43,12 @@ fn test_linear_converter() {
assert_eq!(conv.next(), None);
}

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

0 comments on commit 9c4e954

Please sign in to comment.