Skip to content
This repository was archived by the owner on Jun 17, 2020. It is now read-only.

Commit 6a069ba

Browse files
author
Shantanu
authored
Update dsp.rs
1 parent b996461 commit 6a069ba

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/dsp.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ pub mod DSPInfo {
3131
* https://en.wikipedia.org/wiki/Root_mean_square
3232
*/
3333
pub fn normalize_samples
34-
(samples: &mut Vec<f32>, target_gain: f32) -> DSPInfo::NormalizationInfo {
34+
(samples: &mut Vec<f32>, target_gain: f32) -> (f32, f32) {
3535
let signal_rms = f32::sqrt(samples.iter()
3636
.fold(0.0,|_s, s| _s + s.powf(2.0))
3737
/ samples.len() as f32
3838
);
3939

40-
/* Multiplier of samples to bring the average amplitude of
41-
them to a target gain. */
40+
// Gain factor to reach the target RMS based on the
41+
// RMS of the signal, more samples = more flat amplitude.
4242
let target_gain = target_gain / signal_rms;
4343

4444
/* Replace the samples with the samples
@@ -48,8 +48,5 @@ pub fn normalize_samples
4848
.map(|sample| sample * target_gain)
4949
.collect();
5050

51-
DSPInfo::NormalizationInfo {
52-
rms: signal_rms,
53-
gain: target_gain
54-
}
55-
}
51+
(rms, gain)
52+
}

0 commit comments

Comments
 (0)