1
0
Fork 0

Don't normalize empty buffers in Buffr Glitch

This commit is contained in:
Robbert van der Helm 2022-11-18 19:32:52 +01:00
parent cea84edceb
commit a3056713c8

View file

@ -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;
}
} }
} }
} }