mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
device: add RMSMeter
This commit is contained in:
parent
4127c141cc
commit
2ef9628ab8
2 changed files with 18 additions and 1 deletions
|
|
@ -19,8 +19,9 @@ winit = { workspace = true, optional = true }
|
||||||
default = [ "clock", "editor", "sequencer", "sampler", "lv2" ]
|
default = [ "clock", "editor", "sequencer", "sampler", "lv2" ]
|
||||||
clock = []
|
clock = []
|
||||||
editor = []
|
editor = []
|
||||||
|
meter = []
|
||||||
sequencer = [ "clock", "uuid" ]
|
sequencer = [ "clock", "uuid" ]
|
||||||
sampler = [ "symphonia", "wavers" ]
|
sampler = [ "meter", "symphonia", "wavers" ]
|
||||||
lv2 = [ "livi", "winit" ]
|
lv2 = [ "livi", "winit" ]
|
||||||
vst2 = []
|
vst2 = []
|
||||||
vst3 = []
|
vst3 = []
|
||||||
|
|
|
||||||
16
crates/device/src/meter.rs
Normal file
16
crates/device/src/meter.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
use crate::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Clone)]
|
||||||
|
pub struct RMSMeter(f32);
|
||||||
|
|
||||||
|
impl RMSMeter {
|
||||||
|
pub fn set (&mut self, samples: &[u32]) {
|
||||||
|
let sum: usize = samples.iter().map(|s|*s as usize).reduce(|sum, sample|sum + sample)
|
||||||
|
.unwrap_or(0);
|
||||||
|
self.0 = (sum as f32 / samples.len() as f32).sqrt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render!(TuiOut: |self: RMSMeter, to| {
|
||||||
|
let [x, y, w, h] = to.area();
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue