summaryrefslogtreecommitdiff
path: root/src/synth/math.rs
diff options
context:
space:
mode:
authorGraham Northup <grissess@nexusg.org>2017-09-20 01:49:04 -0400
committerGraham Northup <grissess@nexusg.org>2017-09-20 01:49:04 -0400
commitdcfc4e82386f41bd36c3b102512bd225fc5331b6 (patch)
treeb0b4e8ee6bf95be9970cfad37ef087cce472393b /src/synth/math.rs
parent9866c0f34c268a09ecaaa9a4361c1c267799358e (diff)
more of the same for the night :)
Diffstat (limited to 'src/synth/math.rs')
-rw-r--r--src/synth/math.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/synth/math.rs b/src/synth/math.rs
index 91e58e3..8adad4b 100644
--- a/src/synth/math.rs
+++ b/src/synth/math.rs
@@ -48,3 +48,55 @@ impl Generator for Mul {
mem::replace(&mut self.buf, buf)
}
}
+
+#[derive(Debug)]
+pub struct Negate {
+ pub value: GenBox,
+ pub buf: SampleBuffer,
+}
+
+impl Generator for Negate {
+ fn eval<'a>(&'a mut self, params: &Parameters) -> &'a SampleBuffer {
+ self.buf.update_from(self.value.eval(params));
+ match self.buf.rate {
+ Rate::Sample => {
+ for v in self.buf.iter_mut() {
+ *v *= -1.0;
+ }
+ },
+ Rate::Control => {
+ self.buf[0] *= -1.0;
+ },
+ }
+ &self.buf
+ }
+ fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
+ mem::replace(&mut self.buf, buf)
+ }
+}
+
+#[derive(Debug)]
+pub struct Reciprocate {
+ pub value: GenBox,
+ pub buf: SampleBuffer,
+}
+
+impl Generator for Reciprocate {
+ fn eval<'a>(&'a mut self, params: &Parameters) -> &'a SampleBuffer {
+ self.buf.update_from(self.value.eval(params));
+ match self.buf.rate {
+ Rate::Sample => {
+ for v in self.buf.iter_mut() {
+ *v = v.powf(-1.0);
+ }
+ },
+ Rate::Control => {
+ self.buf[0] = self.buf[0].powf(-1.0);
+ },
+ }
+ &self.buf
+ }
+ fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer {
+ mem::replace(&mut self.buf, buf)
+ }
+}