@@ -5,6 +5,16 @@ use crate::{
55 assert_valid_channel_number, assert_valid_number_of_channels, assert_valid_sample_rate,
66} ;
77
8+ #[ track_caller]
9+ #[ inline( always) ]
10+ pub ( crate ) fn assert_valid_length ( length : usize ) {
11+ assert ! (
12+ length > 0 ,
13+ "NotSupportedError - Invalid length: {:?} is less than or equal to minimum bound (0)" ,
14+ length,
15+ ) ;
16+ }
17+
818/// Options for constructing an [`AudioBuffer`]
919// dictionary AudioBufferOptions {
1020// unsigned long numberOfChannels = 1;
@@ -81,6 +91,7 @@ impl AudioBuffer {
8191 /// 32 being defined by the MAX_CHANNELS constant.
8292 pub fn new ( options : AudioBufferOptions ) -> Self {
8393 assert_valid_sample_rate ( options. sample_rate ) ;
94+ assert_valid_length ( options. length ) ;
8495 assert_valid_number_of_channels ( options. number_of_channels ) ;
8596
8697 let silence = ChannelData :: new ( options. length ) ;
@@ -475,6 +486,19 @@ mod tests {
475486 AudioBuffer :: from ( samples, sample_rate) ; // should panic
476487 }
477488
489+
490+ #[ test]
491+ #[ should_panic]
492+ fn test_invalid_length ( ) {
493+ let options = AudioBufferOptions {
494+ number_of_channels : 1 ,
495+ length : 0 ,
496+ sample_rate : 48000. ,
497+ } ;
498+
499+ AudioBuffer :: new ( options) ; // should panic
500+ }
501+
478502 #[ test]
479503 fn test_channel_data_get_set ( ) {
480504 let options = AudioBufferOptions {
0 commit comments