1
0
Fork 0

Prefer releasing voices in voice stealing

This commit is contained in:
Robbert van der Helm 2023-01-17 02:44:59 +01:00
parent 98e2e11d25
commit 821f4aac21

View file

@ -352,15 +352,34 @@ impl BuffrGlitch {
} }
} }
let mut quietest_voice_id = 0; // Prefer stealing releasing voices if possible
let mut quiested_voice_amplitude = f32::MAX; if let Some((quietest_voice_id, _)) = self
for (voice_id, voice) in self.voices.iter().enumerate() { .voices
if voice.amp_envelope.current() < quiested_voice_amplitude { .iter()
quietest_voice_id = voice_id; .enumerate()
quiested_voice_amplitude = voice.amp_envelope.current(); .filter(|(_, voice)| voice.amp_envelope.is_releasing())
} .min_by(|(_, voice_a), (_, voice_b)| {
f32::total_cmp(
&voice_a.amp_envelope.current(),
&voice_b.amp_envelope.current(),
)
})
{
return quietest_voice_id;
} }
let (quietest_voice_id, _) = self
.voices
.iter()
.enumerate()
.min_by(|(_, voice_a), (_, voice_b)| {
f32::total_cmp(
&voice_a.amp_envelope.current(),
&voice_b.amp_envelope.current(),
)
})
.unwrap();
quietest_voice_id quietest_voice_id
} }
} }