Skip to content

Commit c47dcd9

Browse files
committed
Fix: do not upmix inputs to the AudioNode channelCount beforehand
The upmixing will happen when the inputs are mixed together, and only when needed. This prevent unnecessary upmixes to stereo for many nodes with channelCountMode Max and ClampedMax.
1 parent 81144bf commit c47dcd9

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

src/node/biquad_filter.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,11 @@ impl AudioProcessor for BiquadFilterRenderer {
649649
};
650650

651651
for (channel_number, output_channel) in output.channels_mut().iter_mut().enumerate() {
652-
let input_channel = input.channel_data(channel_number);
652+
let input_channel = if input.is_silent() {
653+
input.channel_data(0)
654+
} else {
655+
input.channel_data(channel_number)
656+
};
653657
// retrieve state from previous block
654658
let mut x1 = self.x1[channel_number];
655659
let mut x2 = self.x2[channel_number];

src/node/panner.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,6 @@ mod tests {
11421142
let panner = PannerNode::new(&context, options);
11431143
assert_eq!(panner.panning_model(), PanningModelType::EqualPower);
11441144
panner.position_y().set_value(1.); // sound comes from above
1145-
panner.set_channel_count(1);
11461145

11471146
src.connect(&panner);
11481147
panner.connect(&context.destination());
@@ -1181,8 +1180,11 @@ mod tests {
11811180
listener.up_y().set_value(0.);
11821181
listener.up_z().set_value(1.);
11831182

1184-
// 128 input samples of value 1.
1185-
let input = AudioBuffer::from(vec![vec![1.; RENDER_QUANTUM_SIZE]], sample_rate);
1183+
// 128 input samples of value 1, stereo
1184+
let input = AudioBuffer::from(
1185+
vec![vec![1.; RENDER_QUANTUM_SIZE], vec![1.; RENDER_QUANTUM_SIZE]],
1186+
sample_rate,
1187+
);
11861188
let mut src = AudioBufferSourceNode::new(&context, AudioBufferSourceOptions::default());
11871189
src.set_buffer(input);
11881190
src.start();

src/render/graph.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,6 @@ impl Graph {
417417
// acquire a mutable borrow of the current processing node
418418
let mut node = nodes[*index].borrow_mut();
419419

420-
// make sure all input buffers have the correct number of channels, this might not be
421-
// the case if the node has no inputs connected or the channel count has just changed
422-
let interpretation = node.channel_config.interpretation();
423-
let count = node.channel_config.count();
424-
node.inputs
425-
.iter_mut()
426-
.for_each(|i| i.mix(count, interpretation));
427-
428420
// let the current node process (catch any panics that may occur)
429421
let params = AudioParamValues::from(nodes);
430422
scope.node_id.set(*index);

tests/mixing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn test_stereo_to_discrete_stereo() {
9393

9494
assert_eq!(output.number_of_channels(), 2);
9595
assert_float_eq!(output.get_channel_data(0), ONES, abs_all <= 0.);
96-
assert_float_eq!(output.get_channel_data(1), ONES, abs_all <= 0.);
96+
assert_float_eq!(output.get_channel_data(1), ZEROES, abs_all <= 0.);
9797
}
9898

9999
#[test]

0 commit comments

Comments
 (0)