Skip to content

Commit 582704a

Browse files
committed
AudioParam test if clones are kept in sync
1 parent 73d6a15 commit 582704a

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

src/param.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ pub struct AudioParam {
271271
// helper struct to attach / detach to context (for borrow reasons)
272272
#[derive(Clone)]
273273
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
280280
}
281281

282282
impl AudioNode for AudioParam {
@@ -1674,7 +1674,6 @@ mod tests {
16741674
fn test_automation_rate_synchronicity_on_control_thread() {
16751675
let context = OfflineAudioContext::new(1, 0, 48000.);
16761676

1677-
// zero target
16781677
let opts = AudioParamDescriptor {
16791678
name: String::new(),
16801679
automation_rate: AutomationRate::A,
@@ -1688,6 +1687,35 @@ mod tests {
16881687
assert_eq!(param.automation_rate(), AutomationRate::K);
16891688
}
16901689

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+
16911719
#[test]
16921720
fn test_set_value() {
16931721
{

0 commit comments

Comments
 (0)