# Dasp > [Source](../src/dasp/lib.rs.html#1-116) --- # dasp Documentation # Source: https://docs.rs/dasp/latest/dasp/ # Crate daspCopy item path [Source](../src/dasp/lib.rs.html#1-116) Expand description **dasp** (formerly known as _**sample**_) is a suite of crates providing the fundamentals for working with pulse-code modulation **digital audio signal processing**. In other words, **dasp** provides a suite of low-level, high- performance tools including types, traits and functions for working with digital audio signals. Each of the **dasp** crates are re-exported under their respective [modules](file:///home/mindtree/programming/rust/dasp/target/doc/dasp/index.html#modules). ### §Highlights The following are some of the more interesting items within the dasp collection: * Use the [**Sample** trait](./trait.Sample.html) to remain generic across bit-depth. * Use the [**Frame** trait](./frame/trait.Frame.html) to remain generic over channel layout. * Use the [**Signal** trait](./signal/trait.Signal.html) for working with **Iterators** that yield **Frames**. * See the [**signal** module](./signal/index.html) for a collection of interesting signal constructors (e.g. `sine`, `noise`, `from_iter`, etc). * Use the [**slice** module](./slice/index.html) for working with slices of **Samples** and **Frames**. * See the [**sample::types** module](./sample/types/index.html) for provided custom sample types. * 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. ### §Optional Features By default, only the **sample** and **frame** modules and their respective traits are included within this crate. You may pick and choose between the following features for additional functionality. * The **all** feature enables all of the following features. * The **std** feature enables the std library. This is enabled by default. * The **all-no-std** feature enables all of the following features (without std). The following features map to each of the sub-crates and their respective features. * The **envelope** feature enables the `dasp_envelope` crate via the [envelope](./envelope/index.html) module. * The **envelope-peak** feature enables peak envelope detection. * The **envelope-rms** feature enables RMS envelope detection. * The **interpolate** feature enables the `dasp_interpolate` crate via the [interpolate](./interpolate/index.html) module. * The **interpolate-floor** feature enables a floor interpolation implementation. * The **interpolate-linear** feature enables a linear interpolation implementation. * The **interpolate-sinc** feature enables a sinc interpolation implementation. * The **peak** feature enables the `dasp_peak` crate via the [peak](./peak/index.html) module. * The **ring_buffer** feature enables the `dasp_ring_buffer` crate via the [ring_buffer](./peak/index.html) module. * The **rms** feature enables the `dasp_rms` crate via the [rms](./rms/index.html) module. * The **signal** feature enables the `dasp_signal` crate via the [signal](./signal/index.html) module. * The **signal-boxed** feature enables an implementation of **Signal** for `Box`. * The **signal-bus** feature enables the [**SignalBus**](./signal/bus/trait.SignalBus.html) trait. * The **signal-envelope** feature enables the [**SignalEnvelope**](./signal/envelope/trait.SignalEnvelope.html) trait. * The **signal-rms** feature enables the [**SignalRms**](./signal/rms/trait.SignalRms.html) trait. * The **signal-window** feature enables the [**signal::window**](./signal/window/index.html) module. * The **signal-window-hanning** enables the [**signal::window::hanning**](./signal/window/fn.hanning.html) window constructor. * The **signal-window-rectangle** enables the [**signal::window::rectangle**](./signal/window/fn.rectangle.html) window constructor. * The **slice** feature enables the `dasp_slice` crate via the [slice](./slice/index.html) module. * The **slice-boxed** feature enables boxed slice conversion traits and functions. * The **window** feature enables the `dasp_window` crate via the [window](./window/index.html) module. * The **window-hanning** feature enables the [**Hanning**](./window/struct.Hanning.html) window implementation. * The **window-rectangle** feature enables the [**Rectangle**](./window/struct.Rectangle.html) window implementation. You can also enable all of the above features with the `--all-features` flag. #### §no_std If working in a `no_std` context, you can disable the default **std** feature with `--no-default-features`. To enable all of the above features in a `no_std` context, enable the **all- no-std** feature. ## Modules§ [envelope](envelope/index.html "mod dasp::envelope") An abstraction supporting different kinds of envelope detection. [frame](frame/index.html "mod dasp::frame") Use the [**Frame**](./trait.Frame.html) trait to remain generic over the number of channels at a single discrete moment in time. [interpolate](interpolate/index.html "mod dasp::interpolate") An abstraction for sample/frame rate interpolation. [peak](peak/index.html "mod dasp::peak") Peak envelope detection over a signal. [ring_buffer](ring_buffer/index.html "mod dasp::ring_buffer") Items related to the implementation of ring buffers. [rms](rms/index.html "mod dasp::rms") Root mean square calculation over a signal. [sample](sample/index.html "mod dasp::sample") Use the [**Sample**](./trait.Sample.html) trait to remain generic over sample types, easily access sample type conversions, apply basic audio operations and more. [signal](signal/index.html "mod dasp::signal") Use the [**Signal**](./trait.Signal.html) trait to abstract over infinite-iterator-like types that yield **Frame** s. The **Signal** trait provides methods for adding, scaling, offsetting, multiplying, clipping, generating frame iterators and more. [slice](slice/index.html "mod dasp::slice") For working with slices of PCM audio data. [window](window/index.html "mod dasp::window") Module for windowing over a batch of Frames. Includes default Hanning and Rectangle window types. ## Traits§ [Frame](trait.Frame.html "trait dasp::Frame") Represents one sample from each channel at a single discrete instance in time within a PCM signal. [Sample](trait.Sample.html "trait dasp::Sample") A trait for working generically across different **Sample** format types. [Signal](trait.Signal.html "trait dasp::Signal") Types that yield `Frame`s of a one-or-more-channel PCM signal. --- # dasp_envelope Documentation # Source: https://docs.rs/dasp_envelope/latest/dasp_envelope/ # Crate dasp_envelopeCopy item path [Source](../src/dasp_envelope/lib.rs.html#1-30) Expand description An abstraction supporting different kinds of envelope detection. * The [**Detect**](./trait.Detect.html) trait provides an abstraction for generalising over types of envelope detection. * The [**Detector**](./struct.Detector.html) type allows for applying a **Detect** implementation in order to detect the envelope of a signal. See the `dasp_signal` crate (or `dasp::signal` module) **SignalWindow** trait for a convenient way to detect envelopes over arbitrary signals. #### §Optional Features * The **peak** feature (or **envelope-peak** feature if using `dasp`) provides a peak envelope detection implementation. * The **rms** feature (or **envelope-rms** feature if using `dasp`) provides an RMS envelope detection implementation. #### §no_std If working in a `no_std` context, you can disable the default **std** feature with `--no-default-features`. To enable all of the above features in a `no_std` context, enable the **all- no-std** feature. ## Re-exports§ `pub use self::detect::[Detect](detect/trait.Detect.html "trait dasp_envelope::detect::Detect");` `pub use self::detect::[Detector](detect/struct.Detector.html "struct dasp_envelope::detect::Detector");` ## Modules§ [detect](detect/index.html "mod dasp_envelope::detect") --- # dasp_frame Documentation # Source: https://docs.rs/dasp_frame/latest/dasp_frame/ # Crate dasp_frameCopy item path [Source](../src/dasp_frame/lib.rs.html#1-579) Expand description Use the [**Frame**](./trait.Frame.html) trait to remain generic over the number of channels at a single discrete moment in time. Implementations are provided for all fixed-size arrays up to 32 elements in length. ## Structs§ [Channels](struct.Channels.html "struct dasp_frame::Channels") An iterator that yields the sample for each channel in the frame by value. [N1](struct.N1.html "struct dasp_frame::N1") A typified version of a number of channels. [N2](struct.N2.html "struct dasp_frame::N2") A typified version of a number of channels. [N3](struct.N3.html "struct dasp_frame::N3") A typified version of a number of channels. [N4](struct.N4.html "struct dasp_frame::N4") A typified version of a number of channels. [N5](struct.N5.html "struct dasp_frame::N5") A typified version of a number of channels. [N6](struct.N6.html "struct dasp_frame::N6") A typified version of a number of channels. [N7](struct.N7.html "struct dasp_frame::N7") A typified version of a number of channels. [N8](struct.N8.html "struct dasp_frame::N8") A typified version of a number of channels. [N9](struct.N9.html "struct dasp_frame::N9") A typified version of a number of channels. [N10](struct.N10.html "struct dasp_frame::N10") A typified version of a number of channels. [N11](struct.N11.html "struct dasp_frame::N11") A typified version of a number of channels. [N12](struct.N12.html "struct dasp_frame::N12") A typified version of a number of channels. [N13](struct.N13.html "struct dasp_frame::N13") A typified version of a number of channels. [N14](struct.N14.html "struct dasp_frame::N14") A typified version of a number of channels. [N15](struct.N15.html "struct dasp_frame::N15") A typified version of a number of channels. [N16](struct.N16.html "struct dasp_frame::N16") A typified version of a number of channels. [N17](struct.N17.html "struct dasp_frame::N17") A typified version of a number of channels. [N18](struct.N18.html "struct dasp_frame::N18") A typified version of a number of channels. [N19](struct.N19.html "struct dasp_frame::N19") A typified version of a number of channels. [N20](struct.N20.html "struct dasp_frame::N20") A typified version of a number of channels. [N21](struct.N21.html "struct dasp_frame::N21") A typified version of a number of channels. [N22](struct.N22.html "struct dasp_frame::N22") A typified version of a number of channels. [N23](struct.N23.html "struct dasp_frame::N23") A typified version of a number of channels. [N24](struct.N24.html "struct dasp_frame::N24") A typified version of a number of channels. [N25](struct.N25.html "struct dasp_frame::N25") A typified version of a number of channels. [N26](struct.N26.html "struct dasp_frame::N26") A typified version of a number of channels. [N27](struct.N27.html "struct dasp_frame::N27") A typified version of a number of channels. [N28](struct.N28.html "struct dasp_frame::N28") A typified version of a number of channels. [N29](struct.N29.html "struct dasp_frame::N29") A typified version of a number of channels. [N30](struct.N30.html "struct dasp_frame::N30") A typified version of a number of channels. [N31](struct.N31.html "struct dasp_frame::N31") A typified version of a number of channels. [N32](struct.N32.html "struct dasp_frame::N32") A typified version of a number of channels. ## Traits§ [Frame](trait.Frame.html "trait dasp_frame::Frame") Represents one sample from each channel at a single discrete instance in time within a PCM signal. [NumChannels](trait.NumChannels.html "trait dasp_frame::NumChannels") Restricts the types that may be used as the `Frame::NumChannels` associated type. ## Type Aliases§ [Mono](type.Mono.html "type dasp_frame::Mono") [Stereo](type.Stereo.html "type dasp_frame::Stereo") --- # dasp_graph Documentation # Source: https://docs.rs/dasp_graph/latest/dasp_graph/ # Crate dasp_graphCopy item path [Source](../src/dasp_graph/lib.rs.html#1-374) Expand description A crate for dynamically creating and editing audio graphs. `dasp_graph` is targeted towards users who require an efficient yet flexible and dynamically configurable audio graph. Use cases might include virtual mixers, digital audio workstations, game audio systems, virtual modular synthesizers and more. ## §Overview A `dasp` graph is composed of **nodes** and **edges**. Each node contains an instance of a type that implements the [`Node` trait](./node/trait.Node.html). This is normally an audio source (input), processor (effect) or sink (output). The `Node` trait is the core abstraction of `dasp_graph` and allows for trivial re-use of audio nodes between projects and libraries. By implementing `Node` for your audio instruments, effects, generators and processors, they can be easily composed together within a graph and shared with future projects or other `dasp` users. `dasp_graph` provides a suite of popular node implementations out of the box, each of which may be accessed by enabling [their associated features](./index.html#optional- features). The edges of a `dasp` graph are empty and simply describe the direction of audio flow through the graph. That is, the edge _a - > b_ describes that the audio output of node _a_ will be used as an input to node _b_. Once we have added our nodes and edges describing the flow of audio through our graph, we can repeatedly process and retrieve audio from it using the [`Processor`](./struct.Processor.html) type. ## §Comparison to `dasp_signal` While [`dasp_signal`](https://docs.rs/dasp_signal) and its [`Signal` trait](https://docs.rs/dasp_signal/latest/dasp_signal/trait.Signal.html) are already well suited towards composing audio graphs, there are certain use cases where they can cause friction. Use cases that require dynamically adding or removing nodes, mapping between dynamically changing channel layouts, or writing the output of one node to multiple others are all difficult to achieve in an elegant manner using `dasp_signal`. `dasp_graph` is designed in a manner that better handles these cases. The flat ownership model where the graph owns all nodes makes it trivial to add or remove nodes and edges at runtime. Nodes can specify the number of buffers that they support during construction, making it easy to handle different channel layouts. Adding multiple outputs to a node (including predecessors to enable cycles) is trivial due to `dasp_graph`’s requirement for a fixed sample rate across the whole graph. On the other hand, `dasp_graph`’s requirement for a fixed sample rate can also be a limitation. A `dasp_graph` cannot be composed of nodes with differing input sample rates meaning it is unsuitable for writing a streaming sample rate converter. `dasp_graph`’s fixed buffer size results in another limitation. It implies that when creating a cycle within the graph, a minimum delay of `Buffer::LEN` is incurred at the edge causing the cycle. This makes it tricky to compose per-sample feedback delays by using cycles in the graph. Feature| `dasp_graph`| `dasp_signal` ---|---|--- Easily dynamically add/remove nodes/edges| ✓| ✗ Easily write output of node to multiple others| ✓| ✗ Dynamic channel layout| ✓| ✗ Efficiently implement per-sample feedback| ✗| ✓ Support variable input sample rate per node| ✗| ✓ In general, `dasp_signal` tends to be better suited towards the composition of fixed or static graphs where the number of channels are known ahead of time. It is perfect for small, fixed, static graph structures like a simple standalone synthesizer/sampler or small processors/effects like sample-rate converters or pitch shifters. `dasp_graph` on the other hand is better suited at a higher level where flexibility is a priority, e.g. a virtual mixing console or, the underlying graph for a digital audio workstation or a virtual modular synthesizer. Generally, it is likely that `dasp_signal` will be more useful for writing `Node` implementations for audio sources and effects, while `dasp_graph` will be well suited to dynamically composing these nodes together in a flexible manner. ## §Graph types Rather than providing a fixed type of graph to work with, `dasp_graph` utilises the `petgraph` traits to expose a generic interface allowing users to select the graph type that bests suits their application or implement their own. **Graph** The [`petgraph::graph::Graph`](https://docs.rs/petgraph/latest/petgraph/graph/struct.Graph.html) type is a standard graph type exposed by `petgraph`. The type is simply an interface around two `Vec`s, one containing the nodes and one containing the edges. Adding nodes returns a unique identifier that can be used to index into the graph. As long as the graph is intialised with a sufficient capacity for both `Vec`s, adding nodes while avoiding dynamic allocation is simple. **StableGraph** One significant caveat with the `Graph` type is that removing a node invalidates any existing indices that refer to the following nodes stored within the graph’s node `Vec`. The [`petgraph::stable_graph::StableGraph`](https://docs.rs/petgraph/latest/petgraph/stable_graph/struct.StableGraph.html) type avoids this issue by storing each node in and enum. When a node is “removed”, the element simply switches to a variant that indicates its slot is available for use the next time `add_node` is called. In summary, if you require the ability to dynamically remove nodes from your graph you should prefer the `StableGraph` type. Otherwise, the `Graph` type is likely well suited. If neither of these graphs fit your use case, consider implementing the necessary petgraph traits for your own graph type. You can find the necessary traits by checking the trait bounds on the graph argument to the `dasp_graph` functions you intend to use. ## §Optional Features Each of the provided node implementations are available by default, however these may be disabled by disabling default features. You can then enable only the implementations you require with the following features: * The **node-boxed** feature provides a `Node` implementation for `Box`. This is particularly useful for working with a graph composed of many different node types. * The **node-graph** feature provides an implementation of `Node` for a type that encapsulates another `dasp` graph type. This allows for composing individual nodes from graphs of other nodes. * The **node-signal** feature provides an implementation of `Node` for `dyn Signal`. This is useful when designing nodes using `dasp_signal`. * The **node-delay** feature provides a simple multi-channel `Delay` node. * The **node-pass** feature provides a `Pass` node that simply passes audio from its inputs to its outputs. * The **node-sum** feature provides `Sum` and `SumBuffers` `Node` implementations. These are useful for mixing together multiple inputs, and for simple mappings between different channel layouts. #### §no_std *TODO: Adding support for `no_std` is pending the addition of support for `no_std` in petgraph. See https://github.com/petgraph/petgraph/pull/238. ## Re-exports§ `pub use node::[Input](node/struct.Input.html "struct dasp_graph::node::Input");` `pub use node::[Node](node/trait.Node.html "trait dasp_graph::node::Node");` `pub use node::[BoxedNode](node/struct.BoxedNode.html "struct dasp_graph::node::BoxedNode");` `pub use node::[BoxedNodeSend](node/struct.BoxedNodeSend.html "struct dasp_graph::node::BoxedNodeSend");` ## Modules§ [node](node/index.html "mod dasp_graph::node") ## Structs§ [Buffer](struct.Buffer.html "struct dasp_graph::Buffer") The fixed-size buffer used for processing the graph. [NodeData](struct.NodeData.html "struct dasp_graph::NodeData") For use as the node weight within a dasp graph. Contains the node and its buffers. [Processor](struct.Processor.html "struct dasp_graph::Processor") State related to the processing of an audio graph of type `G`. ## Functions§ [process](fn.process.html "fn dasp_graph::process") Process audio through the subgraph ending at the node with the given ID. [sinks](fn.sinks.html "fn dasp_graph::sinks") Produce an iterator yielding IDs for all **sink** nodes within the graph. [sources](fn.sources.html "fn dasp_graph::sources") Produce an iterator yielding IDs for all **source** nodes within the graph. --- # dasp_interpolate Documentation # Source: https://docs.rs/dasp_interpolate/latest/dasp_interpolate/ # Crate dasp_interpolateCopy item path [Source](../src/dasp_interpolate/lib.rs.html#1-51) Expand description An abstraction for sample/frame rate interpolation. The [**Interpolator**](./trait.Interpolator.html) trait provides an abstraction over different types of rate interpolation. See the `dasp_signal` crate (or `dasp::signal` module) **Converter** type for a convenient way to interpolate the rate of arbitrary signals. #### §Optional Features * The **floor** feature (or **interpolate-floor** feature if using `dasp`) provides a floor interpolator implementation. * The **linear** feature (or **interpolate-linear** feature if using `dasp`) provides a linear interpolator implementation. * The **sinc** feature (or **interpolate-sinc** feature if using `dasp`) provides a sinc interpolator implementation. #### §no_std If working in a `no_std` context, you can disable the default **std** feature with `--no-default-features`. To enable all of the above features in a `no_std` context, enable the **all- no-std** feature. ## Modules§ [floor](floor/index.html "mod dasp_interpolate::floor") A floor interpolator implementation. [linear](linear/index.html "mod dasp_interpolate::linear") A linear interpolator implementation. [sinc](sinc/index.html "mod dasp_interpolate::sinc") A sinc interpolator implementation. ## Traits§ [Interpolator](trait.Interpolator.html "trait dasp_interpolate::Interpolator") Types that can interpolate between two values. --- # dasp_peak Documentation # Source: https://docs.rs/dasp_peak/latest/dasp_peak/ # Crate dasp_peakCopy item path [Source](../src/dasp_peak/lib.rs.html#1-100) Expand description Peak envelope detection over a signal. ## Structs§ [FullWave](struct.FullWave.html "struct dasp_peak::FullWave") A signal rectifier that produces the absolute amplitude from samples. [NegativeHalfWave](struct.NegativeHalfWave.html "struct dasp_peak::NegativeHalfWave") A signal rectifier that produces only the negative samples. [PositiveHalfWave](struct.PositiveHalfWave.html "struct dasp_peak::PositiveHalfWave") A signal rectifier that produces only the positive samples. ## Traits§ [Rectifier](trait.Rectifier.html "trait dasp_peak::Rectifier") Types that may be used to rectify a signal of frames `F` for a `Peak` detector. ## Functions§ [full_wave](fn.full_wave.html "fn dasp_peak::full_wave") A signal rectifier that produces the absolute amplitude from samples. [negative_half_wave](fn.negative_half_wave.html "fn dasp_peak::negative_half_wave") A signal rectifier that produces only the negative samples. [positive_half_wave](fn.positive_half_wave.html "fn dasp_peak::positive_half_wave") A signal rectifier that produces only the positive samples. --- # dasp_ring_buffer Documentation # Source: https://docs.rs/dasp_ring_buffer/latest/dasp_ring_buffer/ # Crate dasp_ring_bufferCopy item path [Source](../src/dasp_ring_buffer/lib.rs.html#1-893) Expand description Items related to the implementation of ring buffers. The primary items of interest in this module include: * The [Slice](./trait.Slice.html) and [SliceMut](./trait.SliceMut.html) traits - implemented for types that may be used as the underlying buffer in `Fixed` and `Bounded` ring buffers. * The [Fixed](./struct.Fixed.html) ring buffer type. * The [Bounded](./struct.Bounded.html) ring buffer type. ## Structs§ [Bounded](struct.Bounded.html "struct dasp_ring_buffer::Bounded") A ring buffer with an upper bound on its length. [DrainBounded](struct.DrainBounded.html "struct dasp_ring_buffer::DrainBounded") An iterator that drains the ring buffer by `pop`ping each element one at a time. [Fixed](struct.Fixed.html "struct dasp_ring_buffer::Fixed") A ring buffer with a fixed length. ## Traits§ [FixedSizeArray](trait.FixedSizeArray.html "trait dasp_ring_buffer::FixedSizeArray") Types that may be used as a constant-length buffer underlying a `Bounded` ring buffer. [Slice](trait.Slice.html "trait dasp_ring_buffer::Slice") Types that may be used as a data slice for `Fixed` and `Bounded` ring buffers. [SliceMut](trait.SliceMut.html "trait dasp_ring_buffer::SliceMut") Types that may be used as a data slice for mutable `Fixed` and `Bounded` ring buffers. --- # dasp_rms Documentation # Source: https://docs.rs/dasp_rms/latest/dasp_rms/ # Crate dasp_rmsCopy item path [Source](../src/dasp_rms/lib.rs.html#1-210) Expand description Root mean square calculation over a signal. The primary type of interest in this module is the [**Rms**](./struct.Rms). ## Structs§ [Rms](struct.Rms.html "struct dasp_rms::Rms") Iteratively extracts the RMS (root mean square) envelope from a window over a signal of sample `Frame`s. --- # dasp_sample Documentation # Source: https://docs.rs/dasp_sample/latest/dasp_sample/ # Crate dasp_sampleCopy item path [Source](../src/dasp_sample/lib.rs.html#1-324) Expand description Use the [**Sample**](./trait.Sample.html) trait to remain generic over sample types, easily access sample type conversions, apply basic audio operations and more. The **Sample** trait is the core abstraction throughout dasp on which most other abstractions are based. ## Re-exports§ `pub use conv::[Duplex](conv/trait.Duplex.html "trait dasp_sample::conv::Duplex");` `pub use conv::[FromSample](conv/trait.FromSample.html "trait dasp_sample::conv::FromSample");` `pub use conv::[ToSample](conv/trait.ToSample.html "trait dasp_sample::conv::ToSample");` `pub use types::[I24](types/i24/struct.I24.html "struct dasp_sample::types::i24::I24");` `pub use types::[I48](types/i48/struct.I48.html "struct dasp_sample::types::i48::I48");` `pub use types::[U24](types/u24/struct.U24.html "struct dasp_sample::types::u24::U24");` `pub use types::[U48](types/u48/struct.U48.html "struct dasp_sample::types::u48::U48");` ## Modules§ [conv](conv/index.html "mod dasp_sample::conv") Pure functions and traits for converting between i8, i16, I24, i32, I48, i64, u8, u16, U24, u32, U48, u64, f32 and f64. [types](types/index.html "mod dasp_sample::types") A collection of custom, non-std **Sample** types. ## Traits§ [FloatSample](trait.FloatSample.html "trait dasp_sample::FloatSample") Sample format types represented as floating point numbers. [Sample](trait.Sample.html "trait dasp_sample::Sample") A trait for working generically across different **Sample** format types. [SignedSample](trait.SignedSample.html "trait dasp_sample::SignedSample") Integral and floating-point **Sample** format types whose equilibrium is at 0. --- # dasp_signal Documentation # Source: https://docs.rs/dasp_signal/latest/dasp_signal/ # Crate dasp_signalCopy item path [Source](../src/dasp_signal/lib.rs.html#1-2505) Expand description Use the [**Signal**](./trait.Signal.html) trait to abstract over infinite- iterator-like types that yield **Frame** s. The **Signal** trait provides methods for adding, scaling, offsetting, multiplying, clipping, generating frame iterators and more. You may also find a series of **Signal** source functions, including: * [equilibrium](./fn.equilibrium.html) for generating “silent” frames. * [phase](./fn.phase.html) for a stepping phase, useful for oscillators. * [sine](./fn.sine.html) for generating a sine waveform. * [saw](./fn.saw.html) for generating a sawtooth waveform. * [square](./fn.square.html) for generating a square waveform. * [noise](./fn.noise.html) for generating a noise waveform. * [noise_simplex](./fn.noise_simplex.html) for generating a 1D simplex noise waveform. * [gen](./fn.gen.html) for generating frames of type F from some `Fn() -> F`. * [gen_mut](./fn.gen_mut.html) for generating frames of type F from some `FnMut() -> F`. * [from_iter](./fn.from_iter.html) for converting an iterator yielding frames to a signal. * [from_interleaved_samples_iter](./fn.from_interleaved_samples_iter.html) for converting an iterator yielding interleaved samples to a signal. Working with **Signal** s allows for easy, readable creation of rich and complex DSP graphs with a simple and familiar API. #### §Optional Features * The **boxed** feature (or **signal-boxed** feature if using `dasp`) provides a **Signal** implementation for `Box`. * The **bus** feature (or **signal-bus** feature if using `dasp`) provides the [**SignalBus**](./bus/trait.SignalBus.html) trait. * The **envelope** feature (or **signal-envelope** feature if using `dasp`) provides the [**SignalEnvelope**](./envelope/trait.SignalEnvelope.html) trait. * The **rms** feature (or **signal-rms** feature if using `dasp`) provides the [**SignalRms**](./rms/trait.SignalRms.html) trait. * The **window** feature (or **signal-window** feature if using `dasp`) provides the [**window**](./window/index.html) module. #### §no_std If working in a `no_std` context, you can disable the default **std** feature with `--no-default-features`. To enable all of the above features in a `no_std` context, enable the **all- no-std** feature. ## Modules§ [bus](bus/index.html "mod dasp_signal::bus") An extension to the **Signal** trait that enables multiple signal outputs. [envelope](envelope/index.html "mod dasp_signal::envelope") An extension to the **Signal** trait that enables envelope detection. [interpolate](interpolate/index.html "mod dasp_signal::interpolate") The [**Converter**](./struct.Converter.html) type for interpolating the rate of a signal. [rms](rms/index.html "mod dasp_signal::rms") An extension to the **Signal** trait that monitors the RMS of a signal. [window](window/index.html "mod dasp_signal::window") Items to ease the application of windowing functions to signals. ## Structs§ [AddAmp](struct.AddAmp.html "struct dasp_signal::AddAmp") An iterator that yields the sum of the frames yielded by both `other` and `self` in lock-step. [BranchRcA](struct.BranchRcA.html "struct dasp_signal::BranchRcA") One of the two `Branch` signals returned by `Fork::by_rc`. [BranchRcB](struct.BranchRcB.html "struct dasp_signal::BranchRcB") One of the two `Branch` signals returned by `Fork::by_rc`. [BranchRefA](struct.BranchRefA.html "struct dasp_signal::BranchRefA") One of the two `Branch` signals returned by `Fork::by_ref`. [BranchRefB](struct.BranchRefB.html "struct dasp_signal::BranchRefB") One of the two `Branch` signals returned by `Fork::by_ref`. [Buffered](struct.Buffered.html "struct dasp_signal::Buffered") Buffers the signal using the given ring buffer. [BufferedFrames](struct.BufferedFrames.html "struct dasp_signal::BufferedFrames") An iterator that pops elements from the inner bounded ring buffer and yields them. [ClipAmp](struct.ClipAmp.html "struct dasp_signal::ClipAmp") Clips samples in each frame yielded by `signal` to the given threshhold amplitude. [ConstHz](struct.ConstHz.html "struct dasp_signal::ConstHz") A constant phase step size. [Delay](struct.Delay.html "struct dasp_signal::Delay") Delays the `signal` by the given number of frames. [Equilibrium](struct.Equilibrium.html "struct dasp_signal::Equilibrium") An iterator that endlessly yields `Frame`s of type `F` at equilibrium. [Fork](struct.Fork.html "struct dasp_signal::Fork") Represents a forked `Signal` that has not yet been split into its two branches. [FromInterleavedSamplesIterator](struct.FromInterleavedSamplesIterator.html "struct dasp_signal::FromInterleavedSamplesIterator") An iterator that converts an iterator of `Sample`s to an iterator of `Frame`s. [FromIterator](struct.FromIterator.html "struct dasp_signal::FromIterator") A type that wraps an Iterator and provides a `Signal` implementation for it. [Gen](struct.Gen.html "struct dasp_signal::Gen") A signal that generates frames using the given function. [GenMut](struct.GenMut.html "struct dasp_signal::GenMut") A signal that generates frames using the given function which may mutate some state. [Hz](struct.Hz.html "struct dasp_signal::Hz") An iterator that yields the step size for a phase. [Inspect](struct.Inspect.html "struct dasp_signal::Inspect") A signal that calls its enclosing function and returns the original value. The signal may mutate state. [IntoInterleavedSamples](struct.IntoInterleavedSamples.html "struct dasp_signal::IntoInterleavedSamples") Converts a `Signal` to a type that yields the individual interleaved samples. [IntoInterleavedSamplesIterator](struct.IntoInterleavedSamplesIterator.html "struct dasp_signal::IntoInterleavedSamplesIterator") Converts the `IntoInterleavedSamples` into an `Iterator` that always returns `Some`. [Map](struct.Map.html "struct dasp_signal::Map") A signal that maps from one signal to another [MulAmp](struct.MulAmp.html "struct dasp_signal::MulAmp") An iterator that yields the product of the frames yielded by both `other` and `self` in lock-step. [MulHz](struct.MulHz.html "struct dasp_signal::MulHz") Multiplies the rate at which frames of `self` are yielded by the given `signal`. [Noise](struct.Noise.html "struct dasp_signal::Noise") A noise signal generator. [NoiseSimplex](struct.NoiseSimplex.html "struct dasp_signal::NoiseSimplex") A 1D simplex-noise generator. [OffsetAmp](struct.OffsetAmp.html "struct dasp_signal::OffsetAmp") Provides an iterator that offsets the amplitude of every channel in each frame of the signal by some sample value and yields the resulting frames. [OffsetAmpPerChannel](struct.OffsetAmpPerChannel.html "struct dasp_signal::OffsetAmpPerChannel") An `Iterator` that scales the amplitude of every `Frame` in `self` by the respective amplitudes in each channel of the given `amp` `Frame`. [Phase](struct.Phase.html "struct dasp_signal::Phase") An iterator that yields a phase, useful for waveforms like Sine or Saw. [Rate](struct.Rate.html "struct dasp_signal::Rate") The rate at which phrase a **Signal** is sampled. [Saw](struct.Saw.html "struct dasp_signal::Saw") A saw wave signal generator. [ScaleAmp](struct.ScaleAmp.html "struct dasp_signal::ScaleAmp") An `Iterator` that scales the amplitude of the sample of each channel in every `Frame` yielded by `self` by the given amplitude. [ScaleAmpPerChannel](struct.ScaleAmpPerChannel.html "struct dasp_signal::ScaleAmpPerChannel") An `Iterator` that scales the amplitude of every `Frame` in `self` by the respective amplitudes in each channel of the given `amp` `Frame`. [Sine](struct.Sine.html "struct dasp_signal::Sine") A sine wave signal generator. [Square](struct.Square.html "struct dasp_signal::Square") A square wave signal generator. [Take](struct.Take.html "struct dasp_signal::Take") An iterator that yields `n` number of `Frame`s from the inner `signal`. [UntilExhausted](struct.UntilExhausted.html "struct dasp_signal::UntilExhausted") Yields frames from the signal until the `signal.is_exhausted()` returns `true`. [ZipMap](struct.ZipMap.html "struct dasp_signal::ZipMap") A signal that iterates two signals in parallel and combines them with a function. ## Traits§ [Signal](trait.Signal.html "trait dasp_signal::Signal") Types that yield `Frame`s of a one-or-more-channel PCM signal. [Step](trait.Step.html "trait dasp_signal::Step") Types that may be used to give a phase step size based on some `hz / sample rate`. ## Functions§ [equilibrium](fn.equilibrium.html "fn dasp_signal::equilibrium") Provides an iterator that endlessly yields `Frame`s of type `F` at equilibrium. [from_interleaved_samples_iter](fn.from_interleaved_samples_iter.html "fn dasp_signal::from_interleaved_samples_iter") Create a new `Signal` from the given `Frame`-yielding `Iterator`. [from_iter](fn.from_iter.html "fn dasp_signal::from_iter") Create a new `Signal` from the given `Frame`-yielding `Iterator`. [gen](fn.gen.html "fn dasp_signal::gen") A signal that generates frames using the given function. [gen_mut](fn.gen_mut.html "fn dasp_signal::gen_mut") A signal that generates frames using the given function which may mutate some state. [lift](fn.lift.html "fn dasp_signal::lift") Consumes the given `Iterator`, converts it to a `Signal`, applies the given function to the `Signal` and returns an `Iterator` that will become exhausted when the consumed `Iterator` does. [noise](fn.noise.html "fn dasp_signal::noise") Produces a `Signal` that yields random values between -1.0..1.0. [noise_simplex](fn.noise_simplex.html "fn dasp_signal::noise_simplex") Produces a 1-dimensional simplex noise `Signal`. [phase](fn.phase.html "fn dasp_signal::phase") Creates a `Phase` that continuously steps forward by the given `step` size yielder. [rate](fn.rate.html "fn dasp_signal::rate") Creates a frame `Rate` (aka sample rate) representing the rate at which a signal may be sampled. [saw](fn.saw.html "fn dasp_signal::saw") Produces a `Signal` that yields a saw wave oscillating at the given hz. [sine](fn.sine.html "fn dasp_signal::sine") Produces a `Signal` that yields a sine wave oscillating at the given hz. [square](fn.square.html "fn dasp_signal::square") Produces a `Signal` that yields a square wave oscillating at the given hz. --- # dasp_slice Documentation # Source: https://docs.rs/dasp_slice/latest/dasp_slice/ # Crate dasp_sliceCopy item path [Source](../src/dasp_slice/lib.rs.html#1-361) Expand description For working with slices of PCM audio data. Items related to conversion between slices of frames and slices of samples, particularly useful for working with interleaved data. #### §Optional Features * The **boxed** feature (or **slice-boxed** feature if using `dasp`) provides a suite of boxed slice conversion traits and functions under the [**boxed**](./boxed/index.html) module. #### §no_std If working in a `no_std` context, you can disable the default **std** feature with `--no-default-features`. ## Re-exports§ `pub use boxed::[from_boxed_frame_slice](boxed/fn.from_boxed_frame_slice.html "fn dasp_slice::boxed::from_boxed_frame_slice");` `pub use boxed::[from_boxed_sample_slice](boxed/fn.from_boxed_sample_slice.html "fn dasp_slice::boxed::from_boxed_sample_slice");` `pub use boxed::[to_boxed_frame_slice](boxed/fn.to_boxed_frame_slice.html "fn dasp_slice::boxed::to_boxed_frame_slice");` `pub use boxed::[to_boxed_sample_slice](boxed/fn.to_boxed_sample_slice.html "fn dasp_slice::boxed::to_boxed_sample_slice");` `pub use boxed::[DuplexBoxedFrameSlice](boxed/trait.DuplexBoxedFrameSlice.html "trait dasp_slice::boxed::DuplexBoxedFrameSlice");` `pub use boxed::[DuplexBoxedSampleSlice](boxed/trait.DuplexBoxedSampleSlice.html "trait dasp_slice::boxed::DuplexBoxedSampleSlice");` `pub use boxed::[DuplexBoxedSlice](boxed/trait.DuplexBoxedSlice.html "trait dasp_slice::boxed::DuplexBoxedSlice");` `pub use boxed::[FromBoxedFrameSlice](boxed/trait.FromBoxedFrameSlice.html "trait dasp_slice::boxed::FromBoxedFrameSlice");` `pub use boxed::[FromBoxedSampleSlice](boxed/trait.FromBoxedSampleSlice.html "trait dasp_slice::boxed::FromBoxedSampleSlice");` `pub use boxed::[ToBoxedFrameSlice](boxed/trait.ToBoxedFrameSlice.html "trait dasp_slice::boxed::ToBoxedFrameSlice");` `pub use boxed::[ToBoxedSampleSlice](boxed/trait.ToBoxedSampleSlice.html "trait dasp_slice::boxed::ToBoxedSampleSlice");` ## Modules§ [boxed](boxed/index.html "mod dasp_slice::boxed") Items related to boxed-slice conversions. ## Traits§ [DuplexFrameSlice](trait.DuplexFrameSlice.html "trait dasp_slice::DuplexFrameSlice") For converting to and from a slice of `Frame`s. [DuplexFrameSliceMut](trait.DuplexFrameSliceMut.html "trait dasp_slice::DuplexFrameSliceMut") For converting to and from a mutable slice of `Frame`s. [DuplexSampleSlice](trait.DuplexSampleSlice.html "trait dasp_slice::DuplexSampleSlice") For converting to and from a slice of `Sample`s. [DuplexSampleSliceMut](trait.DuplexSampleSliceMut.html "trait dasp_slice::DuplexSampleSliceMut") For converting to and from a mutable slice of `Sample`s. [DuplexSlice](trait.DuplexSlice.html "trait dasp_slice::DuplexSlice") For converting to and from a slice of `Sample`s of type `S` and a slice of `Frame`s of type `F`. [DuplexSliceMut](trait.DuplexSliceMut.html "trait dasp_slice::DuplexSliceMut") For converting to and from a mutable slice of `Sample`s of type `S` and a slice of `Frame`s of type `F`. [FromFrameSlice](trait.FromFrameSlice.html "trait dasp_slice::FromFrameSlice") For converting from a slice of `Frame`s to a slice of `Sample`s. [FromFrameSliceMut](trait.FromFrameSliceMut.html "trait dasp_slice::FromFrameSliceMut") For converting from a slice of `Frame`s to a slice of `Sample`s. [FromSampleSlice](trait.FromSampleSlice.html "trait dasp_slice::FromSampleSlice") For converting from a slice of `Sample`s to a slice of `Frame`s. [FromSampleSliceMut](trait.FromSampleSliceMut.html "trait dasp_slice::FromSampleSliceMut") For converting from a mutable slice of `Sample`s to a mutable slice of `Frame`s. [ToFrameSlice](trait.ToFrameSlice.html "trait dasp_slice::ToFrameSlice") For converting from a slice of `Sample`s to a slice of `Frame`s. [ToFrameSliceMut](trait.ToFrameSliceMut.html "trait dasp_slice::ToFrameSliceMut") For converting from a mutable slice of `Sample`s to a mutable slice of `Frame`s. [ToSampleSlice](trait.ToSampleSlice.html "trait dasp_slice::ToSampleSlice") For converting from a slice of `Frame`s to a slice of `Sample`s. [ToSampleSliceMut](trait.ToSampleSliceMut.html "trait dasp_slice::ToSampleSliceMut") For converting from a mutable slice of `Frame`s to a mutable slice of `Sample`s. ## Functions§ [add_in_place](fn.add_in_place.html "fn dasp_slice::add_in_place") Adds every sample in slice `b` to every sample in slice `a` respectively. [add_in_place_with_amp_per_channel](fn.add_in_place_with_amp_per_channel.html "fn dasp_slice::add_in_place_with_amp_per_channel") Scale the amplitude of each frame in `b` by `amp_per_channel` before summing it onto `a`. [equilibrium](fn.equilibrium.html "fn dasp_slice::equilibrium") Sets the slice of frames at the associated `Sample`’s equilibrium value. [from_frame_slice](fn.from_frame_slice.html "fn dasp_slice::from_frame_slice") Converts the given slice of `Frame`s into some slice `T`. [from_frame_slice_mut](fn.from_frame_slice_mut.html "fn dasp_slice::from_frame_slice_mut") Converts the given slice of mutable `Frame`s into some mutable slice `T`. [from_sample_slice](fn.from_sample_slice.html "fn dasp_slice::from_sample_slice") Converts the given slice of `Sample`s into some slice `T`. [from_sample_slice_mut](fn.from_sample_slice_mut.html "fn dasp_slice::from_sample_slice_mut") Converts the given mutable slice of `Sample`s into some mutable slice `T`. [map_in_place](fn.map_in_place.html "fn dasp_slice::map_in_place") Mutate every element in the slice with the given function. [to_frame_slice](fn.to_frame_slice.html "fn dasp_slice::to_frame_slice") Converts the given slice into a slice of `Frame`s. [to_frame_slice_mut](fn.to_frame_slice_mut.html "fn dasp_slice::to_frame_slice_mut") Converts the given mutable slice into a mutable slice of `Frame`s. [to_sample_slice](fn.to_sample_slice.html "fn dasp_slice::to_sample_slice") Converts the given slice into a slice of `Sample`s. [to_sample_slice_mut](fn.to_sample_slice_mut.html "fn dasp_slice::to_sample_slice_mut") Converts the given mutable slice of `Frame`s into a mutable slice of `Sample`s. [write](fn.write.html "fn dasp_slice::write") Writes every sample in slice `b` to slice `a`. [zip_map_in_place](fn.zip_map_in_place.html "fn dasp_slice::zip_map_in_place") Mutate every frame in slice `a` while reading from each frame in slice `b` in lock-step using the given function. --- # dasp_window Documentation # Source: https://docs.rs/dasp_window/latest/dasp_window/ # Crate dasp_window Copy item path [Source](../src/dasp_window/lib.rs.html#1-40) Expand description Module for windowing over a batch of Frames. Includes default Hanning and Rectangle window types. #### §Optional Features * The **hanning** feature (or **window-hanning** feature if using `dasp`) provides the [**Hanning**](./struct.Hanning.html) window function implementation. * The **rectangle** feature (or **window-rectangle** feature if using `dasp`) provides the [**Rectangle**](./struct.Rectangle.html) window function implementation. #### §no_std If working in a `no_std` context, you can disable the default **std** feature with `--no-default-features`. To enable all of the above features in a `no_std` context, enable the **all- no-std** feature. ## Structs§ [Hanning](struct.Hanning.html "struct dasp_window::Hanning") A type of window function, also known as the “raised cosine window”. [Rectangle](struct.Rectangle.html "struct dasp_window::Rectangle") The simplest window type, equivalent to replacing all but _N_ values of data sequence by zeroes, making it appear as though the waveform suddenly turns on and off. ## Traits§ [Window](trait.Window.html "trait dasp_window::Window") An abstraction supporting different types of `Window` functions. --- # dasp README # Source: https://raw.githubusercontent.com/RustAudio/dasp/master/README.md # dasp [![Actions Status][dasp-actions-svg]][dasp-actions] [![docs.rs][dasp-docs-rs-svg]][dasp-docs-rs] **Digital Audio Signal Processing in Rust.** *Formerly the [`sample` crate](https://crates.io/crates/sample).* A suite of crates providing the fundamentals for working with PCM (pulse-code modulation) DSP (digital signal processing). In other words, `dasp` provides a suite of low-level, high-performance tools including types, traits and functions for working with digital audio signals. The `dasp` libraries require **no dynamic allocations**1 and have **no dependencies**. The goal is to design a library akin to the **std, but for audio DSP**; keeping the focus on portable and fast fundamentals. 1: Besides the feature-gated `SignalBus` trait, which is occasionally useful when converting a `Signal` tree into a directed acyclic graph. Find the [API documentation here][dasp-docs-rs]. ## Crates **dasp** is a modular collection of crates, allowing users to select the precise set of tools required for their project. The following crates are included within this repository: | **Library** | **Links** | **Description** | | --- | --- | --- | | [**`dasp`**][dasp] | [![Crates.io][dasp-crates-io-svg]][dasp-crates-io] [![docs.rs][dasp-docs-rs-svg]][dasp-docs-rs] | Top-level API with features for all crates. | | [**`dasp_sample`**][dasp_sample] | [![Crates.io][dasp_sample-crates-io-svg]][dasp_sample-crates-io] [![docs.rs][dasp_sample-docs-rs-svg]][dasp_sample-docs-rs] | Sample trait, types, conversions and operations. | | [**`dasp_frame`**][dasp_frame] | [![Crates.io][dasp_frame-crates-io-svg]][dasp_frame-crates-io] [![docs.rs][dasp_frame-docs-rs-svg]][dasp_frame-docs-rs] | Frame trait, types, conversions and operations. | | [**`dasp_slice`**][dasp_slice] | [![Crates.io][dasp_slice-crates-io-svg]][dasp_slice-crates-io] [![docs.rs][dasp_slice-docs-rs-svg]][dasp_slice-docs-rs] | Conversions and ops for slices of samples/frames. | | [**`dasp_ring_buffer`**][dasp_ring_buffer] | [![Crates.io][dasp_ring_buffer-crates-io-svg]][dasp_ring_buffer-crates-io] [![docs.rs][dasp_ring_buffer-docs-rs-svg]][dasp_ring_buffer-docs-rs] | Simple fixed and bounded ring buffers. | | [**`dasp_peak`**][dasp_peak] | [![Crates.io][dasp_peak-crates-io-svg]][dasp_peak-crates-io] [![docs.rs][dasp_peak-docs-rs-svg]][dasp_peak-docs-rs] | Peak detection with half/full pos/neg wave rectifiers. | | [**`dasp_rms`**][dasp_rms] | [![Crates.io][dasp_rms-crates-io-svg]][dasp_rms-crates-io] [![docs.rs][dasp_rms-docs-rs-svg]][dasp_rms-docs-rs] | RMS detection with configurable window. | | [**`dasp_envelope`**][dasp_envelope] | [![Crates.io][dasp_envelope-crates-io-svg]][dasp_envelope-crates-io] [![docs.rs][dasp_envelope-docs-rs-svg]][dasp_envelope-docs-rs] | Envelope detection with peak and RMS impls. | | [**`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 (hann, 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] *Red dotted lines indicate optional dependencies, while black lines indicate required dependencies.* ## Features Use the **Sample** trait to convert between and remain generic over any bit-depth in an optimal, performance-sensitive manner. Implementations are provided for all signed integer, unsigned integer and floating point primitive types along with some custom types including 11, 20, 24 and 48-bit signed and unsigned unpacked integers. For example: ```rust assert_eq!((-1.0).to_sample::(), 0); assert_eq!(0.0.to_sample::(), 128); assert_eq!(0i32.to_sample::(), 2_147_483_648); assert_eq!(I24::new(0).unwrap(), Sample::from_sample(0.0)); assert_eq!(0.0, Sample::EQUILIBRIUM); ``` Use the **Frame** trait to remain generic over the number of channels at a discrete moment in time. Implementations are provided for all fixed-size arrays up to 32 elements in length. ```rust let foo = [0.1, 0.2, -0.1, -0.2]; let bar = foo.scale_amp(2.0); assert_eq!(bar, [0.2, 0.4, -0.2, -0.4]); assert_eq!(Mono::::EQUILIBRIUM, [0.0]); assert_eq!(Stereo::::EQUILIBRIUM, [0.0, 0.0]); assert_eq!(<[f32; 3]>::EQUILIBRIUM, [0.0, 0.0, 0.0]); let foo = [0i16, 0]; let bar: [u8; 2] = foo.map(Sample::to_sample); assert_eq!(bar, [128u8, 128]); ``` Use the **Signal** trait (enabled by the "signal" feature) for working with infinite-iterator-like types that yield `Frame`s. **Signal** provides methods for adding, scaling, offsetting, multiplying, clipping, generating, monitoring and buffering streams of `Frame`s. Working with **Signal**s allows for easy, readable creation of rich and complex DSP graphs with a simple and familiar API. ```rust // Clip to an amplitude of 0.9. let frames = [[1.2, 0.8], [-0.7, -1.4]]; let clipped: Vec<_> = signal::from_iter(frames.iter().cloned()).clip_amp(0.9).take(2).collect(); assert_eq!(clipped, vec![[0.9, 0.8], [-0.7, -0.9]]); // Add `a` with `b` and yield the result. let a = [0.2, -0.6, 0.5]; let b = [0.2, 0.1, -0.8]; let a_signal = signal::from_iter(a.iter().cloned()); let b_signal = signal::from_iter(b.iter().cloned()); let added: Vec = a_signal.add_amp(b_signal).take(3).collect(); 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 mut source = signal::from_iter(foo.iter().cloned()); let a = source.next(); let b = source.next(); let interp = Linear::new(a, b); let frames: Vec<_> = source.scale_hz(interp, 0.5).take(8).collect(); assert_eq!(&frames[..], &[0.0, 0.5, 1.0, 0.5, 0.0, -0.5, -1.0, -0.5][..]); // Convert a signal to its RMS. let signal = signal::rate(44_100.0).const_hz(440.0).sine();; let ring_buffer = ring_buffer::Fixed::from([0.0; WINDOW_SIZE]); let mut rms_signal = signal.rms(ring_buffer); ``` The **signal** module also provides a series of **Signal** source types, including: - `FromIterator` - `FromInterleavedSamplesIterator` - `Equilibrium` (silent signal) - `Phase` - `Sine` - `Saw` - `Square` - `Noise` - `NoiseSimplex` - `Gen` (generate frames from a Fn() -> F) - `GenMut` (generate frames from a FnMut() -> F) Use the **slice** module functions (enabled via the "slice" feature) for processing chunks of `Frame`s. Conversion functions are provided for safely converting between slices of interleaved `Sample`s and slices of `Frame`s without requiring any allocation. For example: ```rust let frames = &[[0.0, 0.5], [0.0, -0.5]][..]; let samples = slice::to_sample_slice(frames); assert_eq!(samples, &[0.0, 0.5, 0.0, -0.5][..]); let samples = &[0.0, 0.5, 0.0, -0.5][..]; let frames = slice::to_frame_slice(samples); assert_eq!(frames, Some(&[[0.0, 0.5], [0.0, -0.5]][..])); let samples = &[0.0, 0.5, 0.0][..]; let frames = slice::to_frame_slice(samples); assert_eq!(frames, None::<&[[f32; 2]]>); ``` The **signal::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. **Converter**s can use a range of interpolation methods, with Floor, Linear, and Sinc interpolation provided in the library. The **ring_buffer** module provides generic **Fixed** and **Bounded** ring buffer types, both of which may be used with owned, borrowed, stack and allocated buffers. The **peak** module can be used for monitoring the peak of a signal. Provided peak rectifiers include `full_wave`, `positive_half_wave` and `negative_half_wave`. The **rms** module provides a flexible **Rms** type that can be used for RMS (root mean square) detection. Any **Fixed** ring buffer can be used as the window for the RMS detection. The **envelope** module provides a **Detector** type (also known as a *Follower*) that allows for detecting the envelope of a signal. **Detector** is generic over the type of **Detect**ion - **Rms** and **Peak** detection are provided. For example: ```rust let signal = signal::rate(4.0).const_hz(1.0).sine(); let attack = 1.0; let release = 1.0; let detector = envelope::Detector::peak(attack, release); let mut envelope = signal.detect_envelope(detector); assert_eq!( envelope.take(4).collect::>(), vec![0.0, 0.6321205496788025, 0.23254416035257117, 0.7176687675647109] ); ``` ## `no_std` All crates may be compiled with and without the std library. The std library is enabled by default, however it may be disabled via `--no-default-features`. To enable all of a crate's features *without* the std library, you may use `--no-default-features --features "all-no-std"`. Please note that some of the crates require the `core_intrinsics` feature in order to be able to perform operations like `sin`, `cos` and `powf32` in a `no_std` context. This means that these crates require the nightly toolchain in order to build in a `no_std` context. ## Contributing If **dasp** is missing types, conversions or other fundamental functionality that you wish it had, feel free to open an issue or pull request! The more hands on deck, the merrier :) ## License Licensed under either of * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. **Contributions** Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. [dasp-actions]: https://github.com/rustaudio/dasp/actions [dasp-actions-svg]: https://github.com/rustaudio/dasp/workflows/dasp/badge.svg [deps-graph]: ./assets/deps-graph.png [dasp]: ./dasp [dasp-crates-io]: https://crates.io/crates/dasp [dasp-crates-io-svg]: https://img.shields.io/crates/v/dasp.svg [dasp-docs-rs]: https://docs.rs/dasp/ [dasp-docs-rs-svg]: https://docs.rs/dasp/badge.svg [dasp_envelope]: ./dasp_envelope [dasp_envelope-crates-io]: https://crates.io/crates/dasp_envelope [dasp_envelope-crates-io-svg]: https://img.shields.io/crates/v/dasp_envelope.svg [dasp_envelope-docs-rs]: https://docs.rs/dasp_envelope/ [dasp_envelope-docs-rs-svg]: https://docs.rs/dasp_envelope/badge.svg [dasp_frame]: ./dasp_frame [dasp_frame-crates-io]: https://crates.io/crates/dasp_frame [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 [dasp_interpolate-docs-rs]: https://docs.rs/dasp_interpolate/ [dasp_interpolate-docs-rs-svg]: https://docs.rs/dasp_interpolate/badge.svg [dasp_peak]: ./dasp_peak [dasp_peak-crates-io]: https://crates.io/crates/dasp_peak [dasp_peak-crates-io-svg]: https://img.shields.io/crates/v/dasp_peak.svg [dasp_peak-docs-rs]: https://docs.rs/dasp_peak/ [dasp_peak-docs-rs-svg]: https://docs.rs/dasp_peak/badge.svg [dasp_ring_buffer]: ./dasp_ring_buffer [dasp_ring_buffer-crates-io]: https://crates.io/crates/dasp_ring_buffer [dasp_ring_buffer-crates-io-svg]: https://img.shields.io/crates/v/dasp_ring_buffer.svg [dasp_ring_buffer-docs-rs]: https://docs.rs/dasp_ring_buffer/ [dasp_ring_buffer-docs-rs-svg]: https://docs.rs/dasp_ring_buffer/badge.svg [dasp_rms]: ./dasp_rms [dasp_rms-crates-io]: https://crates.io/crates/dasp_rms [dasp_rms-crates-io-svg]: https://img.shields.io/crates/v/dasp_rms.svg [dasp_rms-docs-rs]: https://docs.rs/dasp_rms/ [dasp_rms-docs-rs-svg]: https://docs.rs/dasp_rms/badge.svg [dasp_sample]: ./dasp_sample [dasp_sample-crates-io]: https://crates.io/crates/dasp_sample [dasp_sample-crates-io-svg]: https://img.shields.io/crates/v/dasp_sample.svg [dasp_sample-docs-rs]: https://docs.rs/dasp_sample/ [dasp_sample-docs-rs-svg]: https://docs.rs/dasp_sample/badge.svg [dasp_signal]: ./dasp_signal [dasp_signal-crates-io]: https://crates.io/crates/dasp_signal [dasp_signal-crates-io-svg]: https://img.shields.io/crates/v/dasp_signal.svg [dasp_signal-docs-rs]: https://docs.rs/dasp_signal/ [dasp_signal-docs-rs-svg]: https://docs.rs/dasp_signal/badge.svg [dasp_slice]: ./dasp_slice [dasp_slice-crates-io]: https://crates.io/crates/dasp_slice [dasp_slice-crates-io-svg]: https://img.shields.io/crates/v/dasp_slice.svg [dasp_slice-docs-rs]: https://docs.rs/dasp_slice/ [dasp_slice-docs-rs-svg]: https://docs.rs/dasp_slice/badge.svg [dasp_window]: ./dasp_window [dasp_window-crates-io]: https://crates.io/crates/dasp_window [dasp_window-crates-io-svg]: https://img.shields.io/crates/v/dasp_window.svg [dasp_window-docs-rs]: https://docs.rs/dasp_window/ [dasp_window-docs-rs-svg]: https://docs.rs/dasp_window/badge.svg