@@ -7,6 +7,38 @@ use super::{
7
7
AudioNode , ChannelConfig , ChannelConfigOptions , ChannelCountMode , ChannelInterpretation ,
8
8
} ;
9
9
10
+ /// Assert that the channel count mode is valid for the ChannelSplitterNode
11
+ /// see <https://webaudio.github.io/web-audio-api/#audionode-channelcountmode-constraints>
12
+ ///
13
+ /// # Panics
14
+ ///
15
+ /// This function panics if the mode is not equal to Explicit
16
+ ///
17
+ #[ track_caller]
18
+ #[ inline( always) ]
19
+ fn assert_valid_channel_count_mode ( mode : ChannelCountMode ) {
20
+ assert ! (
21
+ mode == ChannelCountMode :: Explicit ,
22
+ "InvalidStateError - channel count of ChannelSplitterNode must be set to Explicit"
23
+ ) ;
24
+ }
25
+
26
+ /// Assert that the channel interpretation is valid for the ChannelSplitterNode
27
+ /// see <https://webaudio.github.io/web-audio-api/#audionode-channelinterpretation-constraints>
28
+ ///
29
+ /// # Panics
30
+ ///
31
+ /// This function panics if the mode is not equal to Explicit
32
+ ///
33
+ #[ track_caller]
34
+ #[ inline( always) ]
35
+ fn assert_valid_channel_interpretation ( interpretation : ChannelInterpretation ) {
36
+ assert ! (
37
+ interpretation == ChannelInterpretation :: Discrete ,
38
+ "InvalidStateError - channel interpretation of ChannelSplitterNode must be set to Discrete"
39
+ ) ;
40
+ }
41
+
10
42
/// Options for constructing a [`ChannelSplitterNode`]
11
43
// dictionary ChannelSplitterOptions : AudioNodeOptions {
12
44
// unsigned long numberOfOutputs = 6;
@@ -45,16 +77,22 @@ impl AudioNode for ChannelSplitterNode {
45
77
& self . channel_config
46
78
}
47
79
48
- fn set_channel_count ( & self , _v : usize ) {
49
- panic ! ( "InvalidStateError - Cannot edit channel count of ChannelSplitterNode" )
80
+ fn set_channel_count ( & self , count : usize ) {
81
+ assert_eq ! (
82
+ count,
83
+ self . channel_count( ) ,
84
+ "InvalidStateError - Cannot edit channel count of ChannelSplitterNode"
85
+ ) ;
50
86
}
51
87
52
- fn set_channel_count_mode ( & self , _v : ChannelCountMode ) {
53
- panic ! ( "InvalidStateError - Cannot edit channel count mode of ChannelSplitterNode" )
88
+ fn set_channel_count_mode ( & self , mode : ChannelCountMode ) {
89
+ assert_valid_channel_count_mode ( mode) ;
90
+ self . channel_config . set_count_mode ( mode) ;
54
91
}
55
92
56
- fn set_channel_interpretation ( & self , _v : ChannelInterpretation ) {
57
- panic ! ( "InvalidStateError - Cannot edit channel interpretation of ChannelSplitterNode" )
93
+ fn set_channel_interpretation ( & self , interpretation : ChannelInterpretation ) {
94
+ assert_valid_channel_interpretation ( interpretation) ;
95
+ self . channel_config . set_interpretation ( interpretation) ;
58
96
}
59
97
60
98
fn number_of_inputs ( & self ) -> usize {
@@ -72,6 +110,9 @@ impl ChannelSplitterNode {
72
110
crate :: assert_valid_number_of_channels ( options. number_of_outputs ) ;
73
111
options. channel_config . count = options. number_of_outputs ;
74
112
113
+ assert_valid_channel_count_mode ( options. channel_config . count_mode ) ;
114
+ assert_valid_channel_interpretation ( options. channel_config . interpretation ) ;
115
+
75
116
let node = ChannelSplitterNode {
76
117
registration,
77
118
channel_config : options. channel_config . into ( ) ,
0 commit comments