Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethrow panics in nodes during user tests #523

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading