Don't normalize empty buffers in Buffr Glitch
This commit is contained in:
parent
cea84edceb
commit
a3056713c8
|
@ -128,12 +128,17 @@ impl RingBuffer {
|
||||||
match normalization_mode {
|
match normalization_mode {
|
||||||
NormalizationMode::None => (),
|
NormalizationMode::None => (),
|
||||||
NormalizationMode::Auto => {
|
NormalizationMode::Auto => {
|
||||||
let normalization_factor =
|
// Prevent this from causing divisions by zero or making very loud clicks when audio
|
||||||
calculate_rms(&self.recording_buffers) / calculate_rms(&self.playback_buffers);
|
// playback has just started
|
||||||
|
let playback_rms = calculate_rms(&self.playback_buffers);
|
||||||
|
if playback_rms > 0.001 {
|
||||||
|
let recording_rms = calculate_rms(&self.recording_buffers);
|
||||||
|
let normalization_factor = recording_rms / playback_rms;
|
||||||
|
|
||||||
for buffer in self.playback_buffers.iter_mut() {
|
for buffer in self.playback_buffers.iter_mut() {
|
||||||
for sample in buffer.iter_mut() {
|
for sample in buffer.iter_mut() {
|
||||||
*sample *= normalization_factor;
|
*sample *= normalization_factor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue