Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a dasp_graph crate. #130

Merged
merged 3 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"dasp",
"dasp_envelope",
"dasp_frame",
"dasp_graph",
"dasp_interpolate",
"dasp_peak",
"dasp_ring_buffer",
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ within this repository:
| [**`dasp_interpolate`**][dasp_interpolate] | [![Crates.io][dasp_interpolate-crates-io-svg]][dasp_interpolate-crates-io] [![docs.rs][dasp_interpolate-docs-rs-svg]][dasp_interpolate-docs-rs] | Inter-frame rate interpolation (linear, sinc, etc). |
| [**`dasp_window`**][dasp_window] | [![Crates.io][dasp_window-crates-io-svg]][dasp_window-crates-io] [![docs.rs][dasp_window-docs-rs-svg]][dasp_window-docs-rs] | Windowing function abstraction (hanning, rectangle). |
| [**`dasp_signal`**][dasp_signal] | [![Crates.io][dasp_signal-crates-io-svg]][dasp_signal-crates-io] [![docs.rs][dasp_signal-docs-rs-svg]][dasp_signal-docs-rs] | Iterator-like API for streams of audio frames. |
| [**`dasp_graph`**][dasp_graph] | [![Crates.io][dasp_graph-crates-io-svg]][dasp_graph-crates-io] [![docs.rs][dasp_graph-docs-rs-svg]][dasp_graph-docs-rs] | For working with modular, dynamic audio graphs. |

[![deps-graph][deps-graph]][deps-graph]

Expand Down Expand Up @@ -239,6 +240,11 @@ dual licensed as above, without any additional terms or conditions.
[dasp_frame-crates-io-svg]: https://img.shields.io/crates/v/dasp_frame.svg
[dasp_frame-docs-rs]: https://docs.rs/dasp_frame/
[dasp_frame-docs-rs-svg]: https://docs.rs/dasp_frame/badge.svg
[dasp_graph]: ./dasp_graph
[dasp_graph-crates-io]: https://crates.io/crates/dasp_graph
[dasp_graph-crates-io-svg]: https://img.shields.io/crates/v/dasp_graph.svg
[dasp_graph-docs-rs]: https://docs.rs/dasp_graph/
[dasp_graph-docs-rs-svg]: https://docs.rs/dasp_graph/badge.svg
[dasp_interpolate]: ./dasp_interpolate
[dasp_interpolate-crates-io]: https://crates.io/crates/dasp_interpolate
[dasp_interpolate-crates-io-svg]: https://img.shields.io/crates/v/dasp_interpolate.svg
Expand Down
16 changes: 15 additions & 1 deletion dasp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edition = "2018"
[dependencies]
dasp_envelope = { version = "0.11", path = "../dasp_envelope", default-features = false, optional = true }
dasp_frame = { version = "0.11", path = "../dasp_frame", default-features = false }
dasp_graph = { version = "0.11", path = "../dasp_graph", default-features = false, optional = true }
dasp_interpolate = { version = "0.11", path = "../dasp_interpolate", default-features = false, optional = true }
dasp_peak = { version = "0.11", path = "../dasp_peak", default-features = false, optional = true }
dasp_ring_buffer = { version = "0.11", path = "../dasp_ring_buffer", default-features = false, optional = true }
Expand All @@ -24,7 +25,13 @@ dasp_window = { version = "0.11", path = "../dasp_window", default-features = fa

[features]
default = ["std"]
all = ["std", "all-no-std"]
all = [
"std",
"all-no-std",
# TODO: Move these into `all-no-std` once `dasp_graph` gains `no_std` support.
"graph",
"graph-all-nodes",
]
all-no-std = [
"envelope",
"envelope-peak",
Expand Down Expand Up @@ -65,6 +72,13 @@ std = [
envelope = ["dasp_envelope"]
envelope-peak = ["dasp_envelope/peak"]
envelope-rms = ["dasp_envelope/rms"]
graph = ["dasp_graph"]
graph-all-nodes = ["dasp_graph/all-nodes"]
graph-node-boxed = ["dasp_graph/node-boxed"]
graph-node-delay = ["dasp_graph/node-delay"]
graph-node-graph = ["dasp_graph/node-graph"]
graph-node-pass = ["dasp_graph/node-pass"]
graph-node-sum = ["dasp_graph/node-sum"]
interpolate = ["dasp_interpolate"]
interpolate-floor = ["dasp_interpolate/floor"]
interpolate-linear = ["dasp_interpolate/linear"]
Expand Down
19 changes: 19 additions & 0 deletions dasp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//! - See the [**Converter** type](./signal/interpolate/struct.Converter.html) for sample rate
//! conversion and scaling.
//! - See the [**ring_buffer** module](./ring_buffer/index.html) for fast FIFO queue options.
//! - See the [**graph** module](./graph/index.html) for working with dynamic audio graphs.
//!
//! ## Optional Features
//!
Expand All @@ -40,6 +41,16 @@
//! [envelope](./envelope/index.html) module.
//! - The **envelope-peak** feature enables peak envelope detection.
//! - The **envelope-rms** feature enables RMS envelope detection.
//! - The **graph** feature enables the `dasp_graph` crate via the [graph](./graph/index.html)
//! module.
//! - The **node-boxed** feature provides a `Node` implementation for `Box<dyn Node>`.
//! - The **node-delay** feature provides a simple multi-channel `Delay` node.
//! - The **node-graph** feature provides an implementation of `Node` for a type that encapsulates
//! another `dasp` graph type.
//! - The **node-pass** feature provides a `Pass` node that simply passes audio from its
//! inputs to its outputs.
//! - The **node-signal** feature provides an implementation of `Node` for `dyn Signal`.
//! - The **node-sum** feature provides `Sum` and `SumBuffers` `Node` implementations.
//! - The **interpolate** feature enables the `dasp_interpolate` crate via the
//! [interpolate](./interpolate/index.html) module.
//! - The **interpolate-floor** feature enables a floor interpolation implementation.
Expand Down Expand Up @@ -83,6 +94,10 @@
//! `--no-default-features`.
//!
//! To enable all of the above features in a `no_std` context, enable the **all-no-std** feature.
//!
//! *Note: The **graph** module is currently only available with the **std** feature enabled.
//! Adding support for `no_std` is pending the addition of support for `no_std` in petgraph. See
//! [this PR](https://github.com/petgraph/petgraph/pull/238).

#![cfg_attr(not(feature = "std"), no_std)]

Expand All @@ -91,6 +106,10 @@
pub use dasp_envelope as envelope;
#[doc(inline)]
pub use dasp_frame::{self as frame, Frame};
// TODO: Remove `std` requirement once `dasp_graph` gains `no_std` support.
#[cfg(all(feature = "graph", feature = "std"))]
#[doc(inline)]
pub use dasp_graph as graph;
#[cfg(feature = "interpolate")]
#[doc(inline)]
pub use dasp_interpolate as interpolate;
Expand Down
31 changes: 31 additions & 0 deletions dasp_graph/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "dasp_graph"
description = "A digital audio signal processing graph."
version = "0.11.0"
authors = ["mitchmindtree <[email protected]>"]
readme = "../README.md"
keywords = ["dsp", "audio", "graph", "pcm", "audio"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/rustaudio/dasp.git"
homepage = "https://github.com/rustaudio/dasp"
edition = "2018"

[features]
default = ["all-nodes"]
all-nodes = ["node-boxed", "node-delay", "node-graph", "node-pass", "node-signal", "node-sum"]
node-boxed = []
node-delay = ["dasp_ring_buffer"]
node-graph = []
node-pass = []
node-signal = ["dasp_frame", "dasp_signal"]
node-sum = ["dasp_slice"]

[dependencies]
dasp_frame = { version = "0.11", default-features = false, features = ["std"], optional = true }
dasp_ring_buffer = { version = "0.11", default-features = false, features = ["std"], optional = true }
dasp_signal = { version = "0.11", default-features = false, features = ["std"], optional = true }
dasp_slice = { version = "0.11", default-features = false, features = ["std"], optional = true }
petgraph = { version = "0.5", default-features = false }

[dev-dependencies]
petgraph = { version = "0.5", features = ["stable_graph"] }
59 changes: 59 additions & 0 deletions dasp_graph/src/buffer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use core::fmt;
use core::ops::{Deref, DerefMut};

/// The fixed-size buffer used for processing the graph.
#[derive(Clone)]
pub struct Buffer {
data: [f32; Self::LEN],
}

impl Buffer {
/// The fixed length of the **Buffer** type.
pub const LEN: usize = 64;
/// A silent **Buffer**.
pub const SILENT: Self = Buffer {
data: [0.0; Self::LEN],
};

/// Short-hand for writing silence to the whole buffer.
pub fn silence(&mut self) {
self.data.copy_from_slice(&Self::SILENT)
}
}

impl Default for Buffer {
fn default() -> Self {
Self::SILENT
}
}

impl From<[f32; Self::LEN]> for Buffer {
fn from(data: [f32; Self::LEN]) -> Self {
Buffer { data }
}
}

impl fmt::Debug for Buffer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.data[..], f)
}
}

impl PartialEq for Buffer {
fn eq(&self, other: &Self) -> bool {
&self[..] == &other[..]
}
}

impl Deref for Buffer {
type Target = [f32];
fn deref(&self) -> &Self::Target {
&self.data[..]
}
}

impl DerefMut for Buffer {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.data[..]
}
}
Loading