Skip to content

Commit f5e6931

Browse files
committed
fix: simply add output channels back to 2 when ir has 4 channels (wpt checked)
1 parent 075e3e5 commit f5e6931

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

src/node/convolver.rs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,23 @@ impl AudioProcessor for ConvolverRenderer {
422422
let o_3 = &mut output.channel_data_mut(3)[..];
423423
let _ = convolvers[3].process(i_right, o_3);
424424

425-
// downmix output back to stereo
426-
output.mix(2, ChannelInterpretation::Speakers);
425+
// mix output back to stereo
426+
let o_2 = output.channel_data(2).clone();
427+
let o_3 = output.channel_data(3).clone();
428+
429+
output
430+
.channel_data_mut(0)
431+
.iter_mut()
432+
.zip(o_2.iter())
433+
.for_each(|(l, sl)| *l += *sl);
434+
435+
output
436+
.channel_data_mut(1)
437+
.iter_mut()
438+
.zip(o_3.iter())
439+
.for_each(|(r, sr)| *r += *sr);
440+
441+
output.set_number_of_channels(2);
427442
}
428443
(1, 4) => {
429444
output.set_number_of_channels(4);
@@ -439,8 +454,23 @@ impl AudioProcessor for ConvolverRenderer {
439454
let o_3 = &mut output.channel_data_mut(3)[..];
440455
let _ = convolvers[3].process(i, o_3);
441456

442-
// downmix output back to stereo
443-
output.mix(2, ChannelInterpretation::Speakers);
457+
// mix output back to stereo
458+
let o_2 = output.channel_data(2).clone();
459+
let o_3 = output.channel_data(3).clone();
460+
461+
output
462+
.channel_data_mut(0)
463+
.iter_mut()
464+
.zip(o_2.iter())
465+
.for_each(|(l, sl)| *l += *sl);
466+
467+
output
468+
.channel_data_mut(1)
469+
.iter_mut()
470+
.zip(o_3.iter())
471+
.for_each(|(r, sr)| *r += *sr);
472+
473+
output.set_number_of_channels(2);
444474
}
445475
_ => unreachable!(),
446476
}
@@ -875,12 +905,12 @@ mod tests {
875905
let result = context.start_rendering_sync();
876906

877907
let mut expected_left = [0.; 128];
878-
expected_left[1] = 0.5;
879-
expected_left[4] = 0.5;
908+
expected_left[1] = 1.;
909+
expected_left[4] = 1.;
880910

881911
let mut expected_right = [0.; 128];
882-
expected_right[2] = 0.5;
883-
expected_right[5] = 0.5;
912+
expected_right[2] = 1.;
913+
expected_right[5] = 1.;
884914

885915
assert_eq!(result.number_of_channels(), 2);
886916
assert_float_eq!(
@@ -937,12 +967,12 @@ mod tests {
937967
let result = context.start_rendering_sync();
938968

939969
let mut expected_left = [0.; 128];
940-
expected_left[1] = 0.5;
941-
expected_left[3] = 0.5;
970+
expected_left[1] = 1.;
971+
expected_left[3] = 1.;
942972

943973
let mut expected_right = [0.; 128];
944-
expected_right[2] = 0.5;
945-
expected_right[4] = 0.5;
974+
expected_right[2] = 1.;
975+
expected_right[4] = 1.;
946976

947977
assert_eq!(result.number_of_channels(), 2);
948978
assert_float_eq!(

0 commit comments

Comments
 (0)