Skip to content

Commit 11fc2e4

Browse files
committed
Merge branch 'master' of github.com:RustAudio/rodio
2 parents b28312b + bc5c4eb commit 11fc2e4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/source/channel_volume.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ where
3434
I::Item: Sample,
3535
{
3636
let mut sample = None;
37-
for _ in 0..input.channels() {
37+
let num_channels = input.channels();
38+
39+
for _ in 0..num_channels {
3840
if let Some(s) = input.next() {
3941
sample = Some(
4042
sample
4143
.get_or_insert_with(I::Item::zero_value)
42-
.saturating_add(s),
44+
.saturating_add(s.amplify(1.0 / num_channels as f32)),
4345
);
4446
}
4547
}
@@ -92,12 +94,15 @@ where
9294
if self.current_channel >= self.channel_volumes.len() {
9395
self.current_channel = 0;
9496
self.current_sample = None;
95-
for _ in 0..self.input.channels() {
97+
98+
let num_channels = self.input.channels();
99+
100+
for _ in 0..num_channels {
96101
if let Some(s) = self.input.next() {
97102
self.current_sample = Some(
98103
self.current_sample
99104
.get_or_insert_with(I::Item::zero_value)
100-
.saturating_add(s),
105+
.saturating_add(s.amplify(1.0 / num_channels as f32)),
101106
);
102107
}
103108
}

0 commit comments

Comments
 (0)