File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments