Skip to content

Commit 7ebbe65

Browse files
committed
Merge pull request #122 from mitchmindtree/dag
Switch from using petgraph directly to the daggy crate. Massively improve API. Add documentation link.
2 parents d9448cd + 10df76f commit 7ebbe65

File tree

7 files changed

+633
-372
lines changed

7 files changed

+633
-372
lines changed

.travis.yml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
language: rust
22
rust:
3-
- nightly
4-
- stable
3+
- nightly
4+
- stable
55
notifications:
6-
email:
7-
6+
email:
7+
88
os:
9-
- linux
10-
- osx
9+
- linux
1110
env:
12-
- LD_LIBRARY_PATH: /usr/local/lib
11+
matrix:
12+
- LD_LIBRARY_PATH: /usr/local/lib
13+
global:
14+
secure: H/FCcjwpQQNeWGRM6zrDojNwRJud/FsAu5N6iGz2kxog0v7FFSuFreYeklNfwX+4Mf+BtYYpblZ8xHF24tOmJHeOMKwGPBoopyjXzJx+QVd3mlj30dmvm1/jcy/7pzH0Q2GhVhSbBtV+BCQvjUXZ/PNk9/wiMSxnNtTchyAOpHQ=
1315
install:
14-
- curl -O http://www.portaudio.com/archives/pa_stable_v19_20140130.tgz
15-
- tar xfz pa_stable_v19_20140130.tgz
16-
- (cd portaudio/ && ./configure && make && sudo make install)
16+
- curl -O http://www.portaudio.com/archives/pa_stable_v19_20140130.tgz
17+
- tar xfz pa_stable_v19_20140130.tgz
18+
- (cd portaudio/ && ./configure && make && sudo make install)
1719
before_script:
18-
- rustc --version
19-
- cargo --version
20+
- rustc --version
21+
- cargo --version
2022
script:
21-
- cargo build --verbose
22-
- cargo test --verbose
23-
- cargo doc --verbose
23+
- cargo build --verbose
24+
- cargo test --verbose
25+
- cargo doc --verbose

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "dsp-chain"
4-
version = "0.6.0"
4+
version = "0.7.0"
55
authors = [
66
"mitchmindtree <[email protected]>",
77
"bvssvni <[email protected]>",
@@ -21,6 +21,6 @@ name = "dsp"
2121
path = "./src/lib.rs"
2222

2323
[dependencies]
24+
daggy = "0.1.3"
2425
num = { version = "0.1.27", default-features = false }
25-
petgraph = "0.1.11"
2626
sound_stream = "0.4.4"

README.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# dsp-chain [![Build Status](https://travis-ci.org/RustAudio/dsp-chain.svg?branch=master)](https://travis-ci.org/RustAudio/dsp-chain)
1+
# dsp-chain [![Build Status](https://travis-ci.org/RustAudio/dsp-chain.svg?branch=master)](https://travis-ci.org/RustAudio/dsp-chain) [![Crates.io](https://img.shields.io/crates/v/dsp-chain.svg)](https://crates.io/crates/dsp-chain) [![Crates.io](https://img.shields.io/crates/l/dsp-chain.svg)](https://github.com/RustAudio/dsp-chain/blob/master/LICENSE)
22

3-
A simple library for chaining together multiple audio dsp processors/generators, written in Rust!
3+
4+
A library for chaining together multiple audio dsp processors/generators, written in Rust!
45

56
Use cases for dsp-chain include:
67
- Designing effects.
@@ -10,31 +11,35 @@ Use cases for dsp-chain include:
1011
- Any kind of modular audio synthesis/processing.
1112

1213

14+
Documenation
15+
------------
16+
17+
[API documentation here!](http://RustAudio.github.io/dsp-chain/dsp)
18+
19+
1320
Usage
1421
-----
1522

1623
Here's what it looks like:
1724

1825
```Rust
1926
// Construct our dsp graph.
20-
let mut dsp_graph = Graph::new();
27+
let mut graph = Graph::new();
2128

2229
// Construct our fancy Synth and add it to the graph!
23-
let synth = dsp_graph.add_node(DspNode::Synth);
30+
let synth = graph.add_node(DspNode::Synth);
2431

25-
// Construct a few oscillators, add them to the graph and connect them to the synth.
26-
let oscillator_a = dsp_graph.add_node(DspNode::Oscillator(0.0, A5_HZ, 0.2));
27-
let oscillator_b = dsp_graph.add_node(DspNode::Oscillator(0.0, D5_HZ, 0.1));
28-
let oscillator_c = dsp_graph.add_node(DspNode::Oscillator(0.0, F5_HZ, 0.15));
29-
dsp_graph.add_input(oscillator_a, synth).unwrap();
30-
dsp_graph.add_input(oscillator_b, synth).unwrap();
31-
dsp_graph.add_input(oscillator_c, synth).unwrap();
32+
// Add a few oscillators as inputs to the synth.
33+
graph.add_input(DspNode::Oscillator(0.0, A5_HZ, 0.2), synth);
34+
graph.add_input(DspNode::Oscillator(0.0, D5_HZ, 0.1), synth);
35+
graph.add_input(DspNode::Oscillator(0.0, F5_HZ, 0.15), synth);
3236

3337
// Set the synth as the master node for the graph.
34-
dsp_graph.set_master(Some(synth));
38+
// This can be inferred by the graph so calling this is optional, but it's nice to be explicit.
39+
graph.set_master(Some(synth));
3540

3641
// Request audio from our Graph.
37-
dsp_graph.audio_requested(&mut buffer, settings);
42+
graph.audio_requested(&mut buffer, settings);
3843
```
3944

4045
Here are [two working examples](https://github.com/PistonDevelopers/dsp-chain/blob/master/examples) of using dsp-chain to create a very basic synth and an oscillating volume.
@@ -50,7 +55,7 @@ dsp-chain = "*"
5055
PortAudio
5156
---------
5257

53-
dsp-chain uses [PortAudio](http://www.portaudio.com) as a cross-platform audio backend. The [rust-portaudio](https://github.com/jeremyletang/rust-portaudio) dependency will first try to find an already installed version on your system before trying to download it and build PortAudio itself.
58+
The dsp-chain examples uses [PortAudio](http://www.portaudio.com) as a cross-platform audio backend. The [rust-portaudio](https://github.com/jeremyletang/rust-portaudio) dependency will first try to find an already installed version on your system before trying to download it and build PortAudio itself.
5459

5560

5661
License

examples/synth.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,42 @@ const F5_HZ: Frequency = 698.46;
2323
fn main() {
2424

2525
// Construct our dsp graph.
26-
let mut dsp_graph = Graph::new();
26+
let mut graph = Graph::new();
2727

2828
// Construct our fancy Synth and add it to the graph!
29-
let synth = dsp_graph.add_node(DspNode::Synth);
29+
let synth = graph.add_node(DspNode::Synth);
3030

31-
// Construct a few oscillators, add them to the graph and connect them to the synth.
32-
let oscillator_a = dsp_graph.add_node(DspNode::Oscillator(0.0, A5_HZ, 0.2));
33-
let oscillator_b = dsp_graph.add_node(DspNode::Oscillator(0.0, D5_HZ, 0.1));
34-
let oscillator_c = dsp_graph.add_node(DspNode::Oscillator(0.0, F5_HZ, 0.15));
35-
dsp_graph.add_input(oscillator_a, synth).unwrap();
36-
dsp_graph.add_input(oscillator_b, synth).unwrap();
37-
dsp_graph.add_input(oscillator_c, synth).unwrap();
31+
// Connect a few oscillators to the synth.
32+
let (_, oscillator_a) = graph.add_input(DspNode::Oscillator(0.0, A5_HZ, 0.2), synth);
33+
graph.add_input(DspNode::Oscillator(0.0, D5_HZ, 0.1), synth);
34+
graph.add_input(DspNode::Oscillator(0.0, F5_HZ, 0.15), synth);
3835

3936
// If adding a connection between two nodes would create a cycle, Graph will return an Err.
40-
if let Err(err) = dsp_graph.add_input(synth, oscillator_a) {
41-
println!("Test for graph cycle error: {:?}", ::std::error::Error::description(&err));
37+
if let Err(err) = graph.add_connection(synth, oscillator_a) {
38+
println!("Testing for cycle error: {:?}", ::std::error::Error::description(&err));
4239
}
4340

4441
// Set the synth as the master node for the graph.
45-
dsp_graph.set_master(Some(synth));
42+
graph.set_master(Some(synth));
4643

4744
// We'll use this to count down from three seconds and then break from the loop.
4845
let mut timer: f64 = 3.0;
4946

5047
// The callback we'll use to pass to the Stream. It will request audio from our dsp_graph.
5148
let callback = Box::new(move |output: &mut[Output], settings: Settings, dt: f64, _: CallbackFlags| {
5249
Sample::zero_buffer(output);
53-
dsp_graph.audio_requested(output, settings);
50+
graph.audio_requested(output, settings);
5451
timer -= dt;
55-
for input in dsp_graph.inputs_mut(synth) {
56-
if let DspNode::Oscillator(_, ref mut pitch, _) = *input {
52+
53+
// Traverse inputs or outputs of a node with the following pattern.
54+
let mut inputs = graph.walk_inputs(synth);
55+
while let Some(input_idx) = inputs.next_node(&mut graph) {
56+
if let DspNode::Oscillator(_, ref mut pitch, _) = graph[input_idx] {
57+
// Pitch down our oscillators for fun.
5758
*pitch -= 0.1;
5859
}
5960
}
61+
6062
if timer >= 0.0 { CallbackResult::Continue } else { CallbackResult::Complete }
6163
});
6264

examples/volume.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,31 @@ use dsp::{CallbackFlags, CallbackResult, Graph, Node, Sample,
88
fn main() {
99

1010
// Construct our dsp graph.
11-
let mut dsp_graph = Graph::new();
11+
let mut graph = Graph::new();
1212

1313
// Construct our fancy Synth and add it to the graph!
14-
let synth = dsp_graph.add_node(DspNode::Synth(0.0));
14+
let synth = graph.add_node(DspNode::Synth(0.0));
1515

16-
// Construct our volume node.
17-
let volume = dsp_graph.add_node(DspNode::Volume(1.0));
18-
19-
// Plug the synth into our Volume node.
20-
dsp_graph.add_input(synth, volume).unwrap();
16+
// Output our synth to a marvellous volume node.
17+
let (_, volume) = graph.add_output(synth, DspNode::Volume(1.0));
2118

2219
// Set the synth as the master node for the graph.
23-
dsp_graph.set_master(Some(volume));
20+
graph.set_master(Some(volume));
2421

2522
// We'll use this to count down from three seconds and then break from the loop.
2623
let mut timer: f64 = 0.0;
2724

28-
// The callback we'll use to pass to the Stream. It will request audio from our dsp_graph.
25+
// The callback we'll use to pass to the Stream. It will request audio from our graph.
2926
let callback = Box::new(move |output: &mut[f32], settings: Settings, dt: f64, _: CallbackFlags| {
3027

3128
// Zero the sample buffer.
3229
Sample::zero_buffer(output);
3330

3431
// Request audio from the graph.
35-
dsp_graph.audio_requested(output, settings);
32+
graph.audio_requested(output, settings);
3633

3734
// Oscillate the volume.
38-
if let &mut DspNode::Volume(ref mut vol) = &mut dsp_graph[volume] {
35+
if let &mut DspNode::Volume(ref mut vol) = &mut graph[volume] {
3936
*vol = (4.0 * timer as f32).sin();
4037
}
4138

0 commit comments

Comments
 (0)