mirror of
https://github.com/robbert-vdh/nih-plug.git
synced 2026-07-01 02:36:54 +00:00
Don't normalize empty buffers in Buffr Glitch
This commit is contained in:
@@ -128,12 +128,17 @@ impl RingBuffer {
|
||||
match normalization_mode {
|
||||
NormalizationMode::None => (),
|
||||
NormalizationMode::Auto => {
|
||||
let normalization_factor =
|
||||
calculate_rms(&self.recording_buffers) / calculate_rms(&self.playback_buffers);
|
||||
// Prevent this from causing divisions by zero or making very loud clicks when audio
|
||||
// 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 sample in buffer.iter_mut() {
|
||||
*sample *= normalization_factor;
|
||||
for buffer in self.playback_buffers.iter_mut() {
|
||||
for sample in buffer.iter_mut() {
|
||||
*sample *= normalization_factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user