Skip to content

Commit

Permalink
mirror
Browse files Browse the repository at this point in the history
this closes #152
  • Loading branch information
tomara-x committed Apr 25, 2024
1 parent a0db0b9 commit eb7e9ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ math
- `mod([float])` `rem([float])`
- `clip([float, float])` e.g. `clip()` takes 1 input and clips to [-1...1], `clip(-5, 5)` clips to [-5...5]
- `wrap(float, [float])` wrap between 2 numbers (or between 0 and x if only one number is given)
- `mirror(float, float)` mirror (wave fold) between two values
- `log([float])`
- `bitand([float])`
- `bitor([float])`
Expand Down
14 changes: 14 additions & 0 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,20 @@ pub fn str_to_net(op: &str) -> Net32 {
return Net32::wrap(Box::new(map(move |i: &Frame<f32, U1>| i[0] - x * (i[0] / x).floor())));
}
}
// thanks to csound's mirror opcode
"mirror" => {
if let Some(p) = p.get(0..2) {
let (p0, p1) = (min(p[0], p[1]), max(p[0], p[1]));
return Net32::wrap(Box::new(map(move |i: &Frame<f32, U1>| {
let mut n = i[0];
n = if n.is_normal() { n } else { 0. };
while n > p1 || n < p0 {
n = if n > p1 { p1+p1-n } else { p0+p0-n };
}
n
})));
}
}
_ => {}
}
Net32::wrap(Box::new(dc(0.)))
Expand Down

0 comments on commit eb7e9ac

Please sign in to comment.