Don't normalize empty buffers in Buffr Glitch
This commit is contained in:
parent
cea84edceb
commit
a3056713c8
|
@ -128,8 +128,12 @@ 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() {
|
||||||
|
@ -138,6 +142,7 @@ impl RingBuffer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reading from the buffer should always start at the beginning
|
// Reading from the buffer should always start at the beginning
|
||||||
self.playback_buffer_pos = 0;
|
self.playback_buffer_pos = 0;
|
||||||
|
|
Loading…
Reference in a new issue