Skip to content

Commit c33a8e0

Browse files
committed
Add some helper functions
1 parent 4dae122 commit c33a8e0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

core/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,15 @@ where
4646
self.as_ref().with_channel(|channel, s| s.set(f(channel)));
4747
}
4848
}
49+
50+
impl Stereo<SV<f32>, SV<f32>> {
51+
pub fn with_volume<V>(self, volume: V) -> Self
52+
where
53+
V: SigT<Item = f32> + Sync + Send + 'static,
54+
{
55+
let out = StereoPair::new_fn(|| sv(0.));
56+
let volume = sig_shared(volume);
57+
self.set_channel(|channel| out.get(channel).clone() * volume.clone());
58+
out
59+
}
60+
}

core/src/stereo.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Buf, SigCtx, SigSampleIntoBufT, SigT};
1+
use crate::{Buf, Sig, SigCtx, SigSampleIntoBufT, SigT, sig_ops::sig_add};
22

33
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44
pub enum Channel {
@@ -114,6 +114,16 @@ where
114114
}
115115
}
116116

117+
impl<L, R> Stereo<L, R>
118+
where
119+
L: SigT<Item = f32>,
120+
R: SigT<Item = f32>,
121+
{
122+
pub fn sum(self) -> Sig<sig_add::OpSigSig<L, R>> {
123+
Sig(self.left) + Sig(self.right)
124+
}
125+
}
126+
117127
impl<L, R> Stereo<L, R>
118128
where
119129
L: SigSampleIntoBufT,

0 commit comments

Comments
 (0)