Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamiPerttu committed Sep 19, 2024
1 parent 0677f4e commit 0df9e07
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 89 deletions.
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
## Changes

### Version 0.20 (Next Version)

- `Net::chain` is more robust now.
- Ring buffer component in the module `ring`.
- New method `Net::fade_in` for adding a node with a fade-in.
- `Net::pipe` is now `Net::pipe_all` and can no longer panic.
- `Net::pipe_op` is now `Net::pipe`, `Net::bus_op` is `Net::bus`, `Net::bin_op` is `Net::binary`,
`Net::stack_op` is `Net::stack`, `Net::branch_op` is `Net::branch`, and `Net::thru_op` is `Net::thru`.
- New methods `Net::can_pipe`, `Net::can_bus`, `Net::can_binary`, `Net::can_stack`, `Net::can_branch`, `Net::can_thru`,
`Net::can_sum` and `Net::can_product`.
- New methods `Net::sum` and `Net::product`.
- `Net::pipe_input` and `Net::pipe_output` can no longer panic.
- New method `Net::ids` for iterating over contained node IDs.

### Version 0.19.1

- Fixed `no_std` support.
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,13 @@ inner buffers needed for block processing.

| Operator Form | Function Form | Multiple Combination Forms |
| ------------- | --------------- | -------------------------- |
| `!A` | `thru(A)` | - |
| `A * B` | `product(A, B)` | - |
| `A + B` | `sum(A, B)` | `sumi, sumf` |
| `A >> B` | `pipe(A, B)` | `pipei, pipef` |
| `A & B` | `bus(A, B)` | `busi, busf` |
| `A ^ B` | `branch(A, B)` | `branchi, branchf` |
| `A \| B` | `stack(A, B)` | `stacki, stackf` |
| `!A` | `thru(A)` | - |
| `A * B` | `product(A, B)` | - |
| `A + B` | `sum(A, B)` | `sumi, sumf` |
| `A >> B` | `pipe(A, B)` | `pipei, pipef` |
| `A & B` | `bus(A, B)` | `busi, busf` |
| `A ^ B` | `branch(A, B)` | `branchi, branchf` |
| `A \| B` | `stack(A, B)` | `stacki, stackf` |

---

Expand Down Expand Up @@ -502,7 +502,7 @@ let mut net = Net::new(0, 1);
let dc_id = net.push(Box::new(dc(220.0)));
let sine_id = net.push(Box::new(sine()));
// Connect nodes.
net.pipe(dc_id, sine_id);
net.pipe_all(dc_id, sine_id);
net.pipe_output(sine_id);
```

Expand Down
4 changes: 2 additions & 2 deletions examples/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ where
let id_delay = net.push(Box::new(
pass() & feedback(delay(0.2) * db_amp(-3.0) >> pinkpass() >> highpole_hz(100.0)),
));
net.pipe(id_noise, id_delay);
net.pipe(id_delay, id_pan);
net.pipe_all(id_noise, id_delay);
net.pipe_all(id_delay, id_pan);
delay_added = true;
}

Expand Down
62 changes: 60 additions & 2 deletions src/audiounit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ use core::fmt::Write;
pub trait AudioUnit: Send + Sync + DynClone {
/// Reset the input state of the unit to an initial state where it has not processed any data.
/// In other words, reset time to zero.
fn reset(&mut self);
fn reset(&mut self) {
// The default implementation does nothing.
}

/// Set the sample rate of the unit.
/// The default sample rate is 44100 Hz.
/// The unit is allowed to reset itself here in response to sample rate changes.
/// If the sample rate stays unchanged, then the goal is to maintain current state.
fn set_sample_rate(&mut self, sample_rate: f64);
#[allow(unused_variables)]
fn set_sample_rate(&mut self, sample_rate: f64) {
// The default implementation does nothing.
}

/// Process one sample.
/// The length of `input` and `output` must be equal to `inputs` and `outputs`, respectively.
Expand Down Expand Up @@ -644,3 +649,56 @@ impl AudioUnit for BlockRateAdapter {
self.unit.allocate();
}
}

/// A dummy unit with zero output. It has an arbitrary number of inputs and outputs.
/// `Net` uses this unit.
#[derive(Clone)]
pub struct DummyUnit {
inputs: usize,
outputs: usize,
}

impl DummyUnit {
/// Create new dummy unit.
pub fn new(inputs: usize, outputs: usize) -> Self {
Self { inputs, outputs }
}
}

impl AudioUnit for DummyUnit {
#[inline]
fn tick(&mut self, _input: &[f32], output: &mut [f32]) {
for x in output.iter_mut() {
*x = 0.0;
}
}

fn process(&mut self, size: usize, _input: &BufferRef, output: &mut BufferMut) {
for channel in 0..self.outputs {
output.channel_f32_mut(channel)[0..simd_items(size)].fill(0.0);
}
}

fn inputs(&self) -> usize {
self.inputs
}

fn outputs(&self) -> usize {
self.outputs
}

fn route(&mut self, _input: &SignalFrame, _frequency: f64) -> SignalFrame {
let mut signal = SignalFrame::new(self.outputs);
signal.fill(Signal::Value(0.0));
signal
}

fn get_id(&self) -> u64 {
const ID: u64 = 93;
ID
}

fn footprint(&self) -> usize {
core::mem::size_of::<Self>()
}
}
4 changes: 3 additions & 1 deletion src/biquad_bank.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Bank of parallel biquad filters with SIMD acceleration.
use core::marker::PhantomData;
use core::ops::Neg;
use hacker::Parameter;
Expand Down Expand Up @@ -203,7 +205,7 @@ where
//}
}

/// 2nd order IIR filter-bank implemented in normalized Direct Form I and SIMD.
/// 2nd order IIR filter bank implemented in normalized Direct Form I and SIMD.
/// - Setting: coefficients as tuple Parameter::BiquadBank(a1, a2, b0, b1, b2).
/// - Input 0: input signal.
/// - Output 0: filtered signal.
Expand Down
1 change: 1 addition & 0 deletions src/hacker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub use super::resample::*;
pub use super::resynth::*;
pub use super::reverb::*;
pub use super::rez::*;
pub use super::ring::*;
pub use super::sequencer::*;
pub use super::setting::*;
pub use super::shape::*;
Expand Down
1 change: 1 addition & 0 deletions src/hacker32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub use super::resample::*;
pub use super::resynth::*;
pub use super::reverb::*;
pub use super::rez::*;
pub use super::ring::*;
pub use super::sequencer::*;
pub use super::setting::*;
pub use super::shape::*;
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ pub mod resample;
pub mod resynth;
pub mod reverb;
pub mod rez;
pub mod ring;
pub mod sequencer;
pub mod setting;
pub mod shape;
Expand Down
Loading

0 comments on commit 0df9e07

Please sign in to comment.