2
2
use std:: any:: Any ;
3
3
use std:: slice:: { Iter , IterMut } ;
4
4
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
5
- use std:: sync:: Arc ;
5
+ use std:: sync:: { Arc , OnceLock } ;
6
+
7
+ use arrayvec:: ArrayVec ;
6
8
7
9
use crate :: context:: AudioContextRegistration ;
8
10
use crate :: node:: {
@@ -11,8 +13,6 @@ use crate::node::{
11
13
use crate :: render:: { AudioParamValues , AudioProcessor , AudioRenderQuantum , RenderScope } ;
12
14
use crate :: { AtomicF32 , RENDER_QUANTUM_SIZE } ;
13
15
14
- use std:: sync:: OnceLock ;
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.
@@ -620,7 +620,7 @@ pub(crate) struct AudioParamProcessor {
620
620
shared_parts : Arc < AudioParamShared > ,
621
621
event_timeline : AudioParamEventTimeline ,
622
622
last_event : Option < AudioParamEvent > ,
623
- buffer : Vec < f32 > ,
623
+ buffer : ArrayVec < f32 , RENDER_QUANTUM_SIZE > ,
624
624
}
625
625
626
626
impl AudioProcessor for AudioParamProcessor {
@@ -670,11 +670,11 @@ impl AudioProcessor for AudioParamProcessor {
670
670
}
671
671
672
672
impl AudioParamProcessor {
673
- // warning: tick in called directly in the unit tests so everything important
674
- // for the tests should be done here
673
+ // Warning: compute_intrinsic_values in called directly in the unit tests so
674
+ // everything important for the tests should be done here
675
+ // The returned value is only used in tests
675
676
fn compute_intrinsic_values ( & mut self , block_time : f64 , dt : f64 , count : usize ) -> & [ f32 ] {
676
677
self . compute_buffer ( block_time, dt, count) ;
677
-
678
678
self . buffer . as_slice ( )
679
679
}
680
680
@@ -1088,7 +1088,14 @@ impl AudioParamProcessor {
1088
1088
match some_event {
1089
1089
None => {
1090
1090
if is_a_rate {
1091
- self . buffer . resize ( count, self . intrinsic_value ) ;
1091
+ // @note - we use `count` rather then `buffer.remaining_capacity`
1092
+ // to correctly unit tests where `count` is lower than RENDER_QUANTUM_SIZE
1093
+ //
1094
+ // @todo(perf) - consider using try_extend_from_slice
1095
+ // which internally uses ptr::copy_nonoverlapping
1096
+ for _ in self . buffer . len ( ) ..count {
1097
+ self . buffer . push ( self . intrinsic_value ) ;
1098
+ }
1092
1099
}
1093
1100
break ;
1094
1101
}
@@ -1614,7 +1621,7 @@ pub(crate) fn audio_param_pair(
1614
1621
shared_parts,
1615
1622
event_timeline : AudioParamEventTimeline :: new ( ) ,
1616
1623
last_event : None ,
1617
- buffer : Vec :: with_capacity ( RENDER_QUANTUM_SIZE ) ,
1624
+ buffer : ArrayVec :: new ( ) ,
1618
1625
} ;
1619
1626
1620
1627
( param, processor)
0 commit comments