Skip to content

Commit

Permalink
Merge pull request #523 from orottier/feature/rethrow-unit-test-proce…
Browse files Browse the repository at this point in the history
…ssor-panics

Rethrow panics in nodes during user tests
  • Loading branch information
orottier authored Sep 10, 2024
2 parents 04da9b6 + 6adf77e commit 8502dec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ impl EventLoop {
result = ControlFlow::Break(());
}

// In unit tests, we rethrow panics to avoid missing critical node exceptions
// https://github.com/orottier/web-audio-api-rs/issues/522
#[cfg(test)]
if let EventPayload::ProcessorError(e) = event.payload {
panic!("Rethrowing exception during tests: {:?}", e);
}

let mut event_handler_lock = self.event_handlers.lock().unwrap();
let callback_option = event_handler_lock.remove(&event.type_);
drop(event_handler_lock); // release Mutex while running callback
Expand Down
11 changes: 6 additions & 5 deletions src/node/waveshaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ struct ResamplerConfig {

impl ResamplerConfig {
fn upsample_x2(channels: usize, sample_rate: usize) -> Self {
let chunk_size_in = RENDER_QUANTUM_SIZE * 2;
let chunk_size_in = RENDER_QUANTUM_SIZE;
let sample_rate_in = sample_rate;
let sample_rate_out = sample_rate * 2;
Self {
Expand All @@ -255,7 +255,7 @@ impl ResamplerConfig {
}

fn upsample_x4(channels: usize, sample_rate: usize) -> Self {
let chunk_size_in = RENDER_QUANTUM_SIZE * 4;
let chunk_size_in = RENDER_QUANTUM_SIZE;
let sample_rate_in = sample_rate;
let sample_rate_out = sample_rate * 4;
Self {
Expand All @@ -267,7 +267,7 @@ impl ResamplerConfig {
}

fn downsample_x2(channels: usize, sample_rate: usize) -> Self {
let chunk_size_in = RENDER_QUANTUM_SIZE;
let chunk_size_in = RENDER_QUANTUM_SIZE * 2;
let sample_rate_in = sample_rate * 2;
let sample_rate_out = sample_rate;
Self {
Expand All @@ -279,7 +279,7 @@ impl ResamplerConfig {
}

fn downsample_x4(channels: usize, sample_rate: usize) -> Self {
let chunk_size_in = RENDER_QUANTUM_SIZE;
let chunk_size_in = RENDER_QUANTUM_SIZE * 4;
let sample_rate_in = sample_rate * 4;
let sample_rate_out = sample_rate;
Self {
Expand Down Expand Up @@ -375,7 +375,7 @@ struct WaveShaperRenderer {
upsampler_x2: Resampler,
// up sampler configured to multiply by 4 the input signal
upsampler_x4: Resampler,
// down sampler configured to divide by 4 the upsampled signal
// down sampler configured to divide by 2 the upsampled signal
downsampler_x2: Resampler,
// down sampler configured to divide by 4 the upsampled signal
downsampler_x4: Resampler,
Expand Down Expand Up @@ -499,6 +499,7 @@ impl AudioProcessor for WaveShaperRenderer {
if let Some(curve) = msg.downcast_mut::<Option<Vec<f32>>>() {
std::mem::swap(&mut self.curve, curve);

// We can propagate silent input only if the center of the curve is zero
self.can_propagate_silence = if let Some(curve) = &self.curve {
if curve.len() % 2 == 1 {
curve[curve.len() / 2].abs() < 1e-9
Expand Down

0 comments on commit 8502dec

Please sign in to comment.