@@ -327,12 +327,12 @@ impl AudioParam {
327
327
/// # Panics
328
328
///
329
329
/// Some nodes have automation rate constraints and may panic when updating the value.
330
- pub fn set_automation_rate ( & self , value : AutomationRate ) {
330
+ pub fn set_automation_rate ( & mut self , value : AutomationRate ) {
331
331
if self . raw_parts . automation_rate_constrained && value != self . automation_rate ( ) {
332
332
panic ! ( "InvalidStateError: automation rate cannot be changed for this param" ) ;
333
333
}
334
334
335
- self . automation_rate = value;
335
+ self . raw_parts . automation_rate = value;
336
336
self . registration ( ) . post_message ( value) ;
337
337
}
338
338
@@ -645,14 +645,12 @@ impl AudioParam {
645
645
#[ derive( Debug ) ]
646
646
pub ( crate ) struct AudioParamShared {
647
647
current_value : AtomicF32 ,
648
- is_a_rate : AtomicBool ,
649
648
}
650
649
651
650
impl AudioParamShared {
652
- pub ( crate ) fn new ( current_value : f32 , automation_rate : AutomationRate ) -> Self {
651
+ pub ( crate ) fn new ( current_value : f32 ) -> Self {
653
652
Self {
654
653
current_value : AtomicF32 :: new ( current_value) ,
655
- is_a_rate : AtomicBool :: new ( automation_rate. is_a_rate ( ) ) ,
656
654
}
657
655
}
658
656
@@ -663,19 +661,6 @@ impl AudioParamShared {
663
661
pub ( crate ) fn store_current_value ( & self , value : f32 ) {
664
662
self . current_value . store ( value, Ordering :: Release ) ;
665
663
}
666
-
667
- pub ( crate ) fn load_automation_rate ( & self ) -> AutomationRate {
668
- if self . is_a_rate . load ( Ordering :: Acquire ) {
669
- AutomationRate :: A
670
- } else {
671
- AutomationRate :: K
672
- }
673
- }
674
-
675
- pub ( crate ) fn store_automation_rate ( & self , automation_rate : AutomationRate ) {
676
- self . is_a_rate
677
- . store ( automation_rate. is_a_rate ( ) , Ordering :: Release ) ;
678
- }
679
664
}
680
665
681
666
struct BlockInfos {
@@ -721,7 +706,6 @@ impl AudioProcessor for AudioParamProcessor {
721
706
fn onmessage ( & mut self , msg : & mut dyn Any ) {
722
707
if let Some ( automation_rate) = msg. downcast_ref :: < AutomationRate > ( ) {
723
708
self . automation_rate = * automation_rate;
724
- self . shared_parts . store_automation_rate ( * automation_rate) ;
725
709
return ;
726
710
}
727
711
@@ -1616,14 +1600,15 @@ pub(crate) fn audio_param_pair(
1616
1600
..
1617
1601
} = descriptor;
1618
1602
1619
- let shared_parts = Arc :: new ( AudioParamShared :: new ( default_value, automation_rate ) ) ;
1603
+ let shared_parts = Arc :: new ( AudioParamShared :: new ( default_value) ) ;
1620
1604
1621
1605
let param = AudioParam {
1622
1606
registration : registration. into ( ) ,
1623
1607
raw_parts : AudioParamRaw {
1624
1608
default_value,
1625
1609
max_value,
1626
1610
min_value,
1611
+ automation_rate,
1627
1612
automation_rate_constrained : false ,
1628
1613
shared_parts : Arc :: clone ( & shared_parts) ,
1629
1614
} ,
@@ -1707,6 +1692,24 @@ mod tests {
1707
1692
assert_float_eq ! ( param. value( ) , 0. , abs_all <= 0. ) ;
1708
1693
}
1709
1694
1695
+ #[ test]
1696
+ fn test_automation_rate_synchronicity_on_control_thread ( ) {
1697
+ let context = OfflineAudioContext :: new ( 1 , 0 , 48000. ) ;
1698
+
1699
+ // zero target
1700
+ let opts = AudioParamDescriptor {
1701
+ name : String :: new ( ) ,
1702
+ automation_rate : AutomationRate :: A ,
1703
+ default_value : 0. ,
1704
+ min_value : 0. ,
1705
+ max_value : 1. ,
1706
+ } ;
1707
+ let ( mut param, _render) = audio_param_pair ( opts, context. mock_registration ( ) ) ;
1708
+
1709
+ param. set_automation_rate ( AutomationRate :: K ) ;
1710
+ assert_eq ! ( param. automation_rate( ) , AutomationRate :: K ) ;
1711
+ }
1712
+
1710
1713
#[ test]
1711
1714
fn test_set_value ( ) {
1712
1715
{
0 commit comments