1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use {Compressor, Detector};
use envelope_detector::{Sample, Frame};
pub trait EvenGainFunction: Sized {
fn next_gain<F, D>(&mut Compressor<F, D, Self>, frame: F) -> <F::Sample as Sample>::Float
where F: Frame,
D: Detector<F>;
}
#[derive(Copy, Clone, Debug)]
pub enum Average {}
impl EvenGainFunction for Average {
#[inline]
fn next_gain<F, D>(compressor: &mut Compressor<F, D, Self>, frame: F) -> <F::Sample as Sample>::Float
where F: Frame,
D: Detector<F>,
{
let next_frame = compressor.next_gain_per_channel(frame);
let sum: <F::Sample as Sample>::Float =
next_frame.channels().fold(Sample::equilibrium(), |s, ch_gain| s + ch_gain);
sum / (F::n_channels() as f32).to_sample()
}
}
#[derive(Copy, Clone, Debug)]
pub enum Minimum {}
impl EvenGainFunction for Minimum {
#[inline]
fn next_gain<F, D>(compressor: &mut Compressor<F, D, Self>, frame: F) -> <F::Sample as Sample>::Float
where F: Frame,
D: Detector<F>,
{
let next_frame = compressor.next_gain_per_channel(frame);
let one = <F::Sample as Sample>::identity();
next_frame.channels().fold(one, |min, ch_gain| if ch_gain < min { ch_gain } else { min })
}
}