Skip to content

Commit 3d874d9

Browse files
committed
PannerNode: do not iterate the constant values of audio params
It makes the code simpler and more performant
1 parent ce31288 commit 3d874d9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/node/panner.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -841,26 +841,28 @@ impl AudioProcessor for PannerRenderer {
841841
&& listener_up_z.len() == 1;
842842

843843
if single_valued {
844+
let param_value = a_rate_params.next().unwrap();
844845
match input.number_of_channels() {
845846
1 => {
846847
*output = input.clone();
847848
output.mix(2, ChannelInterpretation::Speakers);
848849
let [left, right] = output.stereo_mut();
849-
std::iter::repeat(a_rate_params.next().unwrap())
850-
.zip(&mut left[..])
850+
left.iter_mut()
851851
.zip(&mut right[..])
852-
.for_each(|((p, l), r)| apply_mono_to_stereo_gain(p, l, r));
852+
.for_each(|(l, r)| apply_mono_to_stereo_gain(param_value, l, r));
853853
}
854854
2 => {
855855
output.set_number_of_channels(2);
856856
let [left, right] = output.stereo_mut();
857-
std::iter::repeat(a_rate_params.next().unwrap())
858-
.zip(input.channel_data(0).iter().copied())
857+
input
858+
.channel_data(0)
859+
.iter()
860+
.copied()
859861
.zip(input.channel_data(1).iter().copied())
860862
.zip(&mut left[..])
861863
.zip(&mut right[..])
862-
.for_each(|((((p, il), ir), ol), or)| {
863-
apply_stereo_to_stereo_gain(p, il, ir, ol, or)
864+
.for_each(|(((il, ir), ol), or)| {
865+
apply_stereo_to_stereo_gain(param_value, il, ir, ol, or)
864866
});
865867
}
866868
_ => unreachable!(),

0 commit comments

Comments
 (0)