Skip to content

Commit

Permalink
Add computedNumberOfChannels helper, apply to IIRFilter (#423)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Adams <msub2official@gmail.com>
  • Loading branch information
msub2 authored Aug 11, 2024
1 parent 45756be commit adfb546
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion audio/iir_filter_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl IIRFilterNode {
let filter = IIRFilter::new(options.feedforward.clone(), options.feedback.clone());

Self {
filters: vec![filter; channel_info.count as usize],
filters: vec![filter; channel_info.computed_number_of_channels() as usize],
channel_info,
}
}
Expand Down
14 changes: 14 additions & 0 deletions audio/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use oscillator_node::{OscillatorNodeMessage, OscillatorNodeOptions};
use panner_node::{PannerNodeMessage, PannerNodeOptions};
use param::{Param, ParamRate, ParamType, UserAutomationEvent};
use servo_media_streams::{MediaSocket, MediaStreamId};
use std::cmp::min;
use std::sync::mpsc::Sender;
use stereo_panner::StereoPannerOptions;
use wave_shaper_node::{WaveShaperNodeMessage, WaveShaperNodeOptions};
Expand Down Expand Up @@ -100,6 +101,7 @@ pub struct ChannelInfo {
pub count: u8,
pub mode: ChannelCountMode,
pub interpretation: ChannelInterpretation,
pub context_channel_count: u8,
}

impl Default for ChannelInfo {
Expand All @@ -108,6 +110,18 @@ impl Default for ChannelInfo {
count: 2,
mode: ChannelCountMode::Max,
interpretation: ChannelInterpretation::Speakers,
context_channel_count: 2,
}
}
}

impl ChannelInfo {
/// <https://webaudio.github.io/web-audio-api/#computednumberofchannels>
pub fn computed_number_of_channels(&self) -> u8 {
match self.mode {
ChannelCountMode::Max => self.context_channel_count,
ChannelCountMode::ClampedMax => min(self.count, self.context_channel_count),
ChannelCountMode::Explicit => self.count,
}
}
}
Expand Down

0 comments on commit adfb546

Please sign in to comment.