mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
groovebox: display input meters!
This commit is contained in:
parent
e5752ea4b0
commit
7690549bdc
12 changed files with 239 additions and 117 deletions
41
crates/device/src/mixer.rs
Normal file
41
crates/device/src/mixer.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#[derive(Debug, Default)]
|
||||
pub enum MixingMode {
|
||||
#[default]
|
||||
Summing,
|
||||
Average,
|
||||
}
|
||||
|
||||
pub fn mix_summing <const N: usize> (
|
||||
buffer: &mut [Vec<f32>], gain: f32, frames: usize, mut next: impl FnMut()->Option<[f32;N]>,
|
||||
) -> bool {
|
||||
let channels = buffer.len();
|
||||
for index in 0..frames {
|
||||
if let Some(frame) = next() {
|
||||
for (channel, sample) in frame.iter().enumerate() {
|
||||
let channel = channel % channels;
|
||||
buffer[channel][index] += sample * gain;
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn mix_average <const N: usize> (
|
||||
buffer: &mut [Vec<f32>], gain: f32, frames: usize, mut next: impl FnMut()->Option<[f32;N]>,
|
||||
) -> bool {
|
||||
let channels = buffer.len();
|
||||
for index in 0..frames {
|
||||
if let Some(frame) = next() {
|
||||
for (channel, sample) in frame.iter().enumerate() {
|
||||
let channel = channel % channels;
|
||||
let value = buffer[channel][index];
|
||||
buffer[channel][index] = (value + sample * gain) / 2.0;
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue