Macro rustradio::map_block_macro_v2

source ·
macro_rules! map_block_macro_v2 {
    ($name:path, $($tr:path), *) => { ... };
}
Expand description

Macro to make it easier to write one-for-one blocks.

Output type must be the same as the input type.

The first argument is the block struct name. The second (and beyond) are traits that T must match.

process_one(&mut self, s: &T) -> T must be implemented by the block.

E.g.:

  • Add or multiply by some constant, or negate.
  • Delay, o[n] = o[n] - o[n-1], or IIR filter. These require state, but can process only one sample at a time.

§Example

use rustradio::block::Block;
use rustradio::stream::{Streamp, new_streamp};
struct Noop<T: Copy>{
  src: Streamp<T>,
  dst: Streamp<T>,
};
impl<T: Copy> Noop<T> {
  fn new(src: Streamp<T>) -> Self {
    Self {
      src,
      dst: new_streamp(),
    }
  }
  fn process_one(&self, a: &T) -> T { *a }
}
rustradio::map_block_macro_v2![Noop<T>, std::ops::Add<Output = T>];