1
1
//! AudioParam interface
2
2
use std:: any:: Any ;
3
3
use std:: slice:: { Iter , IterMut } ;
4
- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
4
+ use std:: sync:: atomic:: { Ordering } ;
5
5
use std:: sync:: { Arc , OnceLock } ;
6
6
7
7
use arrayvec:: ArrayVec ;
@@ -276,8 +276,9 @@ pub(crate) struct AudioParamRaw {
276
276
max_value : f32 , // immutable
277
277
automation_rate : AutomationRate ,
278
278
automation_rate_constrained : bool ,
279
+ current_value : Arc < AtomicF32 > ,
279
280
// TODO Use `Weak` instead of `Arc`. The `AudioParamProcessor` is the owner.
280
- shared_parts : Arc < AudioParamShared > ,
281
+ // shared_parts: Arc<AudioParamShared>,
281
282
}
282
283
283
284
impl AudioNode for AudioParam {
@@ -364,7 +365,7 @@ impl AudioParam {
364
365
// test_exponential_ramp_a_rate_multiple_blocks
365
366
// test_exponential_ramp_k_rate_multiple_blocks
366
367
pub fn value ( & self ) -> f32 {
367
- self . raw_parts . shared_parts . load_current_value ( )
368
+ self . raw_parts . current_value . load ( Ordering :: Acquire )
368
369
}
369
370
370
371
/// Set the value of the `AudioParam`.
@@ -386,7 +387,7 @@ impl AudioParam {
386
387
assert_is_finite ( value) ;
387
388
// current_value should always be clamped
388
389
let clamped = value. clamp ( self . raw_parts . min_value , self . raw_parts . max_value ) ;
389
- self . raw_parts . shared_parts . store_current_value ( clamped) ;
390
+ self . raw_parts . current_value . store ( clamped, Ordering :: Release ) ;
390
391
391
392
// this event is meant to update param intrinsic value before any calculation
392
393
// is done, will behave as SetValueAtTime with `time == block_timestamp`
@@ -637,32 +638,6 @@ impl AudioParam {
637
638
}
638
639
}
639
640
640
- // Atomic fields of `AudioParam` that could be safely shared between threads
641
- // when wrapped into an `Arc`.
642
- //
643
- // Uses the canonical ordering for handover of values, i.e. `Acquire` on load
644
- // and `Release` on store.
645
- #[ derive( Debug ) ]
646
- pub ( crate ) struct AudioParamShared {
647
- current_value : AtomicF32 ,
648
- }
649
-
650
- impl AudioParamShared {
651
- pub ( crate ) fn new ( current_value : f32 ) -> Self {
652
- Self {
653
- current_value : AtomicF32 :: new ( current_value) ,
654
- }
655
- }
656
-
657
- pub ( crate ) fn load_current_value ( & self ) -> f32 {
658
- self . current_value . load ( Ordering :: Acquire )
659
- }
660
-
661
- pub ( crate ) fn store_current_value ( & self , value : f32 ) {
662
- self . current_value . store ( value, Ordering :: Release ) ;
663
- }
664
- }
665
-
666
641
struct BlockInfos {
667
642
block_time : f64 ,
668
643
dt : f64 ,
@@ -678,7 +653,7 @@ pub(crate) struct AudioParamProcessor {
678
653
max_value : f32 , // immutable
679
654
intrinsic_value : f32 ,
680
655
automation_rate : AutomationRate ,
681
- shared_parts : Arc < AudioParamShared > ,
656
+ current_value : Arc < AtomicF32 > ,
682
657
event_timeline : AudioParamEventTimeline ,
683
658
last_event : Option < AudioParamEvent > ,
684
659
buffer : ArrayVec < f32 , RENDER_QUANTUM_SIZE > ,
@@ -1495,7 +1470,7 @@ impl AudioParamProcessor {
1495
1470
// Set [[current value]] to the value of paramIntrinsicValue at the
1496
1471
// beginning of this render quantum.
1497
1472
let clamped = self . intrinsic_value . clamp ( self . min_value , self . max_value ) ;
1498
- self . shared_parts . store_current_value ( clamped) ;
1473
+ self . current_value . store ( clamped, Ordering :: Release ) ;
1499
1474
1500
1475
// clear the buffer for this block
1501
1476
self . buffer . clear ( ) ;
@@ -1600,7 +1575,7 @@ pub(crate) fn audio_param_pair(
1600
1575
..
1601
1576
} = descriptor;
1602
1577
1603
- let shared_parts = Arc :: new ( AudioParamShared :: new ( default_value) ) ;
1578
+ let current_value = Arc :: new ( AtomicF32 :: new ( default_value) ) ;
1604
1579
1605
1580
let param = AudioParam {
1606
1581
registration : registration. into ( ) ,
@@ -1610,17 +1585,17 @@ pub(crate) fn audio_param_pair(
1610
1585
min_value,
1611
1586
automation_rate,
1612
1587
automation_rate_constrained : false ,
1613
- shared_parts : Arc :: clone ( & shared_parts ) ,
1588
+ current_value : Arc :: clone ( & current_value ) ,
1614
1589
} ,
1615
1590
} ;
1616
1591
1617
1592
let processor = AudioParamProcessor {
1618
1593
intrinsic_value : default_value,
1594
+ current_value,
1619
1595
default_value,
1620
1596
min_value,
1621
1597
max_value,
1622
1598
automation_rate,
1623
- shared_parts,
1624
1599
event_timeline : AudioParamEventTimeline :: new ( ) ,
1625
1600
last_event : None ,
1626
1601
buffer : ArrayVec :: new ( ) ,
0 commit comments