@@ -271,12 +271,12 @@ pub struct AudioParam {
271
271
// helper struct to attach / detach to context (for borrow reasons)
272
272
#[ derive( Clone ) ]
273
273
pub ( crate ) struct AudioParamRaw {
274
- default_value : f32 , // immutable
275
- min_value : f32 , // immutable
276
- max_value : f32 , // immutable
277
- automation_rate_constrained : bool ,
278
- automation_rate : Arc < Mutex < AutomationRate > > ,
279
- current_value : Arc < AtomicF32 > ,
274
+ default_value : f32 , // immutable
275
+ min_value : f32 , // immutable
276
+ max_value : f32 , // immutable
277
+ automation_rate_constrained : bool , // effectively immutable
278
+ automation_rate : Arc < Mutex < AutomationRate > > , // shared with clones
279
+ current_value : Arc < AtomicF32 > , // shared with clones and with render thread
280
280
}
281
281
282
282
impl AudioNode for AudioParam {
@@ -1674,7 +1674,6 @@ mod tests {
1674
1674
fn test_automation_rate_synchronicity_on_control_thread ( ) {
1675
1675
let context = OfflineAudioContext :: new ( 1 , 0 , 48000. ) ;
1676
1676
1677
- // zero target
1678
1677
let opts = AudioParamDescriptor {
1679
1678
name : String :: new ( ) ,
1680
1679
automation_rate : AutomationRate :: A ,
@@ -1688,6 +1687,35 @@ mod tests {
1688
1687
assert_eq ! ( param. automation_rate( ) , AutomationRate :: K ) ;
1689
1688
}
1690
1689
1690
+ #[ test]
1691
+ fn test_audioparam_clones_in_sync ( ) {
1692
+ let context = OfflineAudioContext :: new ( 1 , 0 , 48000. ) ;
1693
+
1694
+ let opts = AudioParamDescriptor {
1695
+ name : String :: new ( ) ,
1696
+ automation_rate : AutomationRate :: A ,
1697
+ default_value : 0. ,
1698
+ min_value : -10. ,
1699
+ max_value : 10. ,
1700
+ } ;
1701
+ let ( param1, mut render) = audio_param_pair ( opts, context. mock_registration ( ) ) ;
1702
+ let param2 = param1. clone ( ) ;
1703
+
1704
+ // changing automation rate on param1 should reflect in param2
1705
+ param1. set_automation_rate ( AutomationRate :: K ) ;
1706
+ assert_eq ! ( param2. automation_rate( ) , AutomationRate :: K ) ;
1707
+
1708
+ // setting value on param1 should reflect in param2
1709
+ render. handle_incoming_event ( param1. set_value_raw ( 2. ) ) ;
1710
+ assert_float_eq ! ( param1. value( ) , 2. , abs_all <= 0. ) ;
1711
+ assert_float_eq ! ( param2. value( ) , 2. , abs_all <= 0. ) ;
1712
+
1713
+ // setting value on param2 should reflect in param1
1714
+ render. handle_incoming_event ( param2. set_value_raw ( 3. ) ) ;
1715
+ assert_float_eq ! ( param1. value( ) , 3. , abs_all <= 0. ) ;
1716
+ assert_float_eq ! ( param2. value( ) , 3. , abs_all <= 0. ) ;
1717
+ }
1718
+
1691
1719
#[ test]
1692
1720
fn test_set_value ( ) {
1693
1721
{
0 commit comments