@@ -4,11 +4,31 @@ use crate::context::{AudioContextRegistration, BaseAudioContext};
4
4
use crate :: render:: {
5
5
AudioParamValues , AudioProcessor , AudioRenderQuantum , AudioWorkletGlobalScope ,
6
6
} ;
7
+ use crate :: MAX_CHANNELS ;
7
8
8
9
use super :: {
9
10
AudioNode , ChannelConfig , ChannelConfigOptions , ChannelCountMode , ChannelInterpretation ,
10
11
} ;
11
12
13
+ /// Assert that the given number of channels is valid for a ChannelMergerNode
14
+ ///
15
+ /// # Panics
16
+ ///
17
+ /// This function will panic if:
18
+ /// - the given number of channels is outside the [1, 32] range,
19
+ /// 32 being defined by the MAX_CHANNELS constant.
20
+ ///
21
+ #[ track_caller]
22
+ #[ inline( always) ]
23
+ pub ( crate ) fn assert_valid_number_of_channels ( number_of_channels : usize ) {
24
+ assert ! (
25
+ number_of_channels > 0 && number_of_channels <= MAX_CHANNELS ,
26
+ "IndexSizeError - Invalid number of channels: {:?} is outside range [1, {:?}]" ,
27
+ number_of_channels,
28
+ MAX_CHANNELS
29
+ ) ;
30
+ }
31
+
12
32
/// Assert that the channel count mode is valid for the ChannelSplitterNode
13
33
/// see <https://webaudio.github.io/web-audio-api/#audionode-channelcountmode-constraints>
14
34
///
@@ -112,7 +132,7 @@ impl AudioNode for ChannelSplitterNode {
112
132
impl ChannelSplitterNode {
113
133
pub fn new < C : BaseAudioContext > ( context : & C , mut options : ChannelSplitterOptions ) -> Self {
114
134
context. base ( ) . register ( move |registration| {
115
- crate :: assert_valid_number_of_channels ( options. number_of_outputs ) ;
135
+ assert_valid_number_of_channels ( options. number_of_outputs ) ;
116
136
options. channel_config . count = options. number_of_outputs ;
117
137
118
138
assert_valid_channel_count_mode ( options. channel_config . count_mode ) ;
0 commit comments