Skip to content

Commit e114103

Browse files
b-maorottier
authored andcommitted
refactor: remove AudioParamShared as it contains only one field left
1 parent 2eade7e commit e114103

File tree

1 file changed

+10
-35
lines changed

1 file changed

+10
-35
lines changed

src/param.rs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! AudioParam interface
22
use std::any::Any;
33
use std::slice::{Iter, IterMut};
4-
use std::sync::atomic::{AtomicBool, Ordering};
4+
use std::sync::atomic::{Ordering};
55
use std::sync::{Arc, OnceLock};
66

77
use arrayvec::ArrayVec;
@@ -276,8 +276,9 @@ pub(crate) struct AudioParamRaw {
276276
max_value: f32, // immutable
277277
automation_rate: AutomationRate,
278278
automation_rate_constrained: bool,
279+
current_value: Arc<AtomicF32>,
279280
// TODO Use `Weak` instead of `Arc`. The `AudioParamProcessor` is the owner.
280-
shared_parts: Arc<AudioParamShared>,
281+
// shared_parts: Arc<AudioParamShared>,
281282
}
282283

283284
impl AudioNode for AudioParam {
@@ -364,7 +365,7 @@ impl AudioParam {
364365
// test_exponential_ramp_a_rate_multiple_blocks
365366
// test_exponential_ramp_k_rate_multiple_blocks
366367
pub fn value(&self) -> f32 {
367-
self.raw_parts.shared_parts.load_current_value()
368+
self.raw_parts.current_value.load(Ordering::Acquire)
368369
}
369370

370371
/// Set the value of the `AudioParam`.
@@ -386,7 +387,7 @@ impl AudioParam {
386387
assert_is_finite(value);
387388
// current_value should always be clamped
388389
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);
390391

391392
// this event is meant to update param intrinsic value before any calculation
392393
// is done, will behave as SetValueAtTime with `time == block_timestamp`
@@ -637,32 +638,6 @@ impl AudioParam {
637638
}
638639
}
639640

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-
666641
struct BlockInfos {
667642
block_time: f64,
668643
dt: f64,
@@ -678,7 +653,7 @@ pub(crate) struct AudioParamProcessor {
678653
max_value: f32, // immutable
679654
intrinsic_value: f32,
680655
automation_rate: AutomationRate,
681-
shared_parts: Arc<AudioParamShared>,
656+
current_value: Arc<AtomicF32>,
682657
event_timeline: AudioParamEventTimeline,
683658
last_event: Option<AudioParamEvent>,
684659
buffer: ArrayVec<f32, RENDER_QUANTUM_SIZE>,
@@ -1495,7 +1470,7 @@ impl AudioParamProcessor {
14951470
// Set [[current value]] to the value of paramIntrinsicValue at the
14961471
// beginning of this render quantum.
14971472
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);
14991474

15001475
// clear the buffer for this block
15011476
self.buffer.clear();
@@ -1600,7 +1575,7 @@ pub(crate) fn audio_param_pair(
16001575
..
16011576
} = descriptor;
16021577

1603-
let shared_parts = Arc::new(AudioParamShared::new(default_value));
1578+
let current_value = Arc::new(AtomicF32::new(default_value));
16041579

16051580
let param = AudioParam {
16061581
registration: registration.into(),
@@ -1610,17 +1585,17 @@ pub(crate) fn audio_param_pair(
16101585
min_value,
16111586
automation_rate,
16121587
automation_rate_constrained: false,
1613-
shared_parts: Arc::clone(&shared_parts),
1588+
current_value: Arc::clone(&current_value),
16141589
},
16151590
};
16161591

16171592
let processor = AudioParamProcessor {
16181593
intrinsic_value: default_value,
1594+
current_value,
16191595
default_value,
16201596
min_value,
16211597
max_value,
16221598
automation_rate,
1623-
shared_parts,
16241599
event_timeline: AudioParamEventTimeline::new(),
16251600
last_event: None,
16261601
buffer: ArrayVec::new(),

0 commit comments

Comments
 (0)