Skip to content

Commit 2eade7e

Browse files
b-maorottier
authored andcommitted
fix: store automation rate on control side then send event
1 parent f1b9688 commit 2eade7e

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/param.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,12 @@ impl AudioParam {
327327
/// # Panics
328328
///
329329
/// 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) {
331331
if self.raw_parts.automation_rate_constrained && value != self.automation_rate() {
332332
panic!("InvalidStateError: automation rate cannot be changed for this param");
333333
}
334334

335-
self.automation_rate = value;
335+
self.raw_parts.automation_rate = value;
336336
self.registration().post_message(value);
337337
}
338338

@@ -645,14 +645,12 @@ impl AudioParam {
645645
#[derive(Debug)]
646646
pub(crate) struct AudioParamShared {
647647
current_value: AtomicF32,
648-
is_a_rate: AtomicBool,
649648
}
650649

651650
impl AudioParamShared {
652-
pub(crate) fn new(current_value: f32, automation_rate: AutomationRate) -> Self {
651+
pub(crate) fn new(current_value: f32) -> Self {
653652
Self {
654653
current_value: AtomicF32::new(current_value),
655-
is_a_rate: AtomicBool::new(automation_rate.is_a_rate()),
656654
}
657655
}
658656

@@ -663,19 +661,6 @@ impl AudioParamShared {
663661
pub(crate) fn store_current_value(&self, value: f32) {
664662
self.current_value.store(value, Ordering::Release);
665663
}
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-
}
679664
}
680665

681666
struct BlockInfos {
@@ -721,7 +706,6 @@ impl AudioProcessor for AudioParamProcessor {
721706
fn onmessage(&mut self, msg: &mut dyn Any) {
722707
if let Some(automation_rate) = msg.downcast_ref::<AutomationRate>() {
723708
self.automation_rate = *automation_rate;
724-
self.shared_parts.store_automation_rate(*automation_rate);
725709
return;
726710
}
727711

@@ -1616,14 +1600,15 @@ pub(crate) fn audio_param_pair(
16161600
..
16171601
} = descriptor;
16181602

1619-
let shared_parts = Arc::new(AudioParamShared::new(default_value, automation_rate));
1603+
let shared_parts = Arc::new(AudioParamShared::new(default_value));
16201604

16211605
let param = AudioParam {
16221606
registration: registration.into(),
16231607
raw_parts: AudioParamRaw {
16241608
default_value,
16251609
max_value,
16261610
min_value,
1611+
automation_rate,
16271612
automation_rate_constrained: false,
16281613
shared_parts: Arc::clone(&shared_parts),
16291614
},
@@ -1707,6 +1692,24 @@ mod tests {
17071692
assert_float_eq!(param.value(), 0., abs_all <= 0.);
17081693
}
17091694

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+
17101713
#[test]
17111714
fn test_set_value() {
17121715
{

0 commit comments

Comments
 (0)