@@ -11,26 +11,26 @@ use crate::node::{
11
11
AudioNode , ChannelConfig , ChannelConfigOptions , ChannelCountMode , ChannelInterpretation ,
12
12
} ;
13
13
use crate :: render:: { AudioParamValues , AudioProcessor , AudioRenderQuantum , RenderScope } ;
14
- use crate :: { AtomicF32 , RENDER_QUANTUM_SIZE } ;
14
+ use crate :: { assert_valid_time_value , AtomicF32 , RENDER_QUANTUM_SIZE } ;
15
15
16
16
/// For SetTargetAtTime event, that theoretically cannot end, if the diff between
17
17
/// the current value and the target is below this threshold, the value is set
18
18
/// to target value and the event is considered ended.
19
19
const SNAP_TO_TARGET : f32 = 1e-10 ;
20
20
21
- // arguments sanity check functions for automation methods
22
21
#[ track_caller]
23
- fn assert_non_negative ( value : f64 ) {
24
- if value < 0. {
25
- panic ! (
26
- "RangeError - timing value ({:?}) should not be negative" ,
27
- value
28
- ) ;
22
+ fn assert_is_finite ( value : f32 ) {
23
+ if !value. is_finite ( ) {
24
+ panic ! ( "TypeError - The provided value is non-finite." ) ;
29
25
}
30
26
}
31
27
32
28
#[ track_caller]
33
29
fn assert_strictly_positive ( value : f64 ) {
30
+ if !value. is_finite ( ) {
31
+ panic ! ( "TypeError - The provided value is non-finite." ) ;
32
+ }
33
+
34
34
if value <= 0. {
35
35
panic ! (
36
36
"RangeError - duration ({:?}) should be strictly positive" ,
@@ -41,6 +41,8 @@ fn assert_strictly_positive(value: f64) {
41
41
42
42
#[ track_caller]
43
43
fn assert_not_zero ( value : f32 ) {
44
+ assert_is_finite ( value) ;
45
+
44
46
if value == 0. {
45
47
panic ! (
46
48
"RangeError - value ({:?}) should not be equal to zero" ,
@@ -379,6 +381,7 @@ impl AudioParam {
379
381
}
380
382
381
383
fn set_value_raw ( & self , value : f32 ) -> AudioParamEvent {
384
+ assert_is_finite ( value) ;
382
385
// current_value should always be clamped
383
386
let clamped = value. clamp ( self . raw_parts . min_value , self . raw_parts . max_value ) ;
384
387
self . raw_parts . shared_parts . store_current_value ( clamped) ;
@@ -406,7 +409,8 @@ impl AudioParam {
406
409
}
407
410
408
411
fn set_value_at_time_raw ( & self , value : f32 , start_time : f64 ) -> AudioParamEvent {
409
- assert_non_negative ( start_time) ;
412
+ assert_is_finite ( value) ;
413
+ assert_valid_time_value ( start_time) ;
410
414
411
415
AudioParamEvent {
412
416
event_type : AudioParamEventType :: SetValueAtTime ,
@@ -430,7 +434,8 @@ impl AudioParam {
430
434
}
431
435
432
436
fn linear_ramp_to_value_at_time_raw ( & self , value : f32 , end_time : f64 ) -> AudioParamEvent {
433
- assert_non_negative ( end_time) ;
437
+ assert_is_finite ( value) ;
438
+ assert_valid_time_value ( end_time) ;
434
439
435
440
AudioParamEvent {
436
441
event_type : AudioParamEventType :: LinearRampToValueAtTime ,
@@ -457,7 +462,7 @@ impl AudioParam {
457
462
458
463
fn exponential_ramp_to_value_at_time_raw ( & self , value : f32 , end_time : f64 ) -> AudioParamEvent {
459
464
assert_not_zero ( value) ;
460
- assert_non_negative ( end_time) ;
465
+ assert_valid_time_value ( end_time) ;
461
466
462
467
AudioParamEvent {
463
468
event_type : AudioParamEventType :: ExponentialRampToValueAtTime ,
@@ -488,8 +493,9 @@ impl AudioParam {
488
493
start_time : f64 ,
489
494
time_constant : f64 ,
490
495
) -> AudioParamEvent {
491
- assert_non_negative ( start_time) ;
492
- assert_non_negative ( time_constant) ;
496
+ assert_is_finite ( value) ;
497
+ assert_valid_time_value ( start_time) ;
498
+ assert_valid_time_value ( time_constant) ;
493
499
494
500
// [spec] If timeConstant is zero, the output value jumps immediately to the final value.
495
501
if time_constant == 0. {
@@ -526,7 +532,7 @@ impl AudioParam {
526
532
}
527
533
528
534
fn cancel_scheduled_values_raw ( & self , cancel_time : f64 ) -> AudioParamEvent {
529
- assert_non_negative ( cancel_time) ;
535
+ assert_valid_time_value ( cancel_time) ;
530
536
531
537
AudioParamEvent {
532
538
event_type : AudioParamEventType :: CancelScheduledValues ,
@@ -551,7 +557,7 @@ impl AudioParam {
551
557
}
552
558
553
559
fn cancel_and_hold_at_time_raw ( & self , cancel_time : f64 ) -> AudioParamEvent {
554
- assert_non_negative ( cancel_time) ;
560
+ assert_valid_time_value ( cancel_time) ;
555
561
556
562
AudioParamEvent {
557
563
event_type : AudioParamEventType :: CancelAndHoldAtTime ,
@@ -584,7 +590,7 @@ impl AudioParam {
584
590
duration : f64 ,
585
591
) -> AudioParamEvent {
586
592
assert_sequence_length ( values) ;
587
- assert_non_negative ( start_time) ;
593
+ assert_valid_time_value ( start_time) ;
588
594
assert_strictly_positive ( duration) ;
589
595
590
596
// When this method is called, an internal copy of the curve is
@@ -1645,17 +1651,6 @@ mod tests {
1645
1651
1646
1652
use super :: * ;
1647
1653
1648
- #[ test]
1649
- #[ should_panic]
1650
- fn test_assert_non_negative_fail ( ) {
1651
- assert_non_negative ( -1. ) ;
1652
- }
1653
-
1654
- #[ test]
1655
- fn test_assert_non_negative ( ) {
1656
- assert_non_negative ( 0. ) ;
1657
- }
1658
-
1659
1654
#[ test]
1660
1655
#[ should_panic]
1661
1656
fn test_assert_strictly_positive_fail ( ) {
0 commit comments