Skip to content

Commit 72b2a1e

Browse files
committed
Simplify WaveShaperNode message passing
1 parent 7d45b1c commit 72b2a1e

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/node/waveshaper.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl WaveShaperNode {
212212
panic!("InvalidStateError - cannot assign curve twice");
213213
}
214214

215-
self.registration.post_message(clone);
215+
self.registration.post_message(Some(clone));
216216
}
217217

218218
/// Returns the `oversample` faactor of this node
@@ -363,9 +363,7 @@ struct WaveShaperRenderer {
363363
/// oversample factor
364364
oversample: OverSampleType,
365365
/// distortion curve
366-
curve: Vec<f32>,
367-
/// whether the distortion curve has been set
368-
curve_set: bool,
366+
curve: Option<Vec<f32>>,
369367
/// Sample rate (equals to audio context sample rate)
370368
sample_rate: usize,
371369
/// Number of channels used to build the up/down sampler X2
@@ -401,9 +399,7 @@ impl AudioProcessor for WaveShaperRenderer {
401399

402400
*output = input.clone();
403401

404-
if self.curve_set {
405-
let curve = &self.curve;
406-
402+
if let Some(curve) = &self.curve {
407403
match self.oversample {
408404
OverSampleType::None => {
409405
output.modify_channels(|channel| {
@@ -496,10 +492,8 @@ impl AudioProcessor for WaveShaperRenderer {
496492
return;
497493
}
498494

499-
if let Some(curve) = msg.downcast_mut::<Vec<f32>>() {
495+
if let Some(curve) = msg.downcast_mut::<Option<Vec<f32>>>() {
500496
std::mem::swap(&mut self.curve, curve);
501-
self.curve_set = true;
502-
503497
return;
504498
}
505499

@@ -531,8 +525,7 @@ impl WaveShaperRenderer {
531525

532526
Self {
533527
oversample,
534-
curve: Vec::with_capacity(0),
535-
curve_set: false,
528+
curve: None,
536529
sample_rate,
537530
channels_x2,
538531
channels_x4,

0 commit comments

Comments
 (0)