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
extern crate dsp;
use {Compressor, Detector, EvenGainFunction, PeakCompressor, RmsCompressor};
impl<F, D, EGF> Compressor<F, D, EGF>
where F: dsp::Frame,
D: Detector<F>,
EGF: EvenGainFunction,
{
#[inline]
pub fn compress_slice(&mut self, frames: &mut [F]) {
dsp::slice::map_in_place(frames, |f| self.next_frame(f));
}
}
impl<F, EGF> dsp::Node<F> for PeakCompressor<F, EGF>
where F: dsp::Frame,
EGF: EvenGainFunction,
{
fn audio_requested(&mut self, output: &mut [F], sample_hz: f64) {
self.update_attack_to_sample_hz(sample_hz);
self.update_release_to_sample_hz(sample_hz);
self.compress_slice(output);
}
}
impl<F, EGF> dsp::Node<F> for RmsCompressor<F, EGF>
where F: dsp::Frame,
EGF: EvenGainFunction,
{
fn audio_requested(&mut self, output: &mut [F], sample_hz: f64) {
self.update_attack_to_sample_hz(sample_hz);
self.update_release_to_sample_hz(sample_hz);
self.update_window_to_sample_hz(sample_hz);
self.compress_slice(output);
}
}