Improve volume curve

This commit is contained in:
Jeremy Soller
2022-11-21 10:58:37 -07:00
parent 8ff9a0bed6
commit acd75dcb0d
+4 -2
View File
@@ -45,8 +45,10 @@ impl AudioScheme {
let mut i = 0;
while i < mix_buffer.len() {
if let Some(sample) = buffer.pop_front() {
let left = ((sample.0 as i32 * self.volume) / 100) as i16;
let right = ((sample.1 as i32 * self.volume) / 100) as i16;
// Multiply each sample by volume squared divided by 100 squared
// This feels better than just multiplying by volume divided by 100
let left = ((sample.0 as i32 * self.volume * self.volume) / 10000) as i16;
let right = ((sample.1 as i32 * self.volume * self.volume) / 10000) as i16;
mix_buffer[i].0 = mix_buffer[i].0.saturating_add(left);
mix_buffer[i].1 = mix_buffer[i].1.saturating_add(right);
} else {