Skip to content

Commit 8502dec

Browse files
authored
Merge pull request #523 from orottier/feature/rethrow-unit-test-processor-panics
Rethrow panics in nodes during user tests
2 parents 04da9b6 + 6adf77e commit 8502dec

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/events.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ impl EventLoop {
191191
result = ControlFlow::Break(());
192192
}
193193

194+
// In unit tests, we rethrow panics to avoid missing critical node exceptions
195+
// https://github.com/orottier/web-audio-api-rs/issues/522
196+
#[cfg(test)]
197+
if let EventPayload::ProcessorError(e) = event.payload {
198+
panic!("Rethrowing exception during tests: {:?}", e);
199+
}
200+
194201
let mut event_handler_lock = self.event_handlers.lock().unwrap();
195202
let callback_option = event_handler_lock.remove(&event.type_);
196203
drop(event_handler_lock); // release Mutex while running callback

src/node/waveshaper.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ struct ResamplerConfig {
243243

244244
impl ResamplerConfig {
245245
fn upsample_x2(channels: usize, sample_rate: usize) -> Self {
246-
let chunk_size_in = RENDER_QUANTUM_SIZE * 2;
246+
let chunk_size_in = RENDER_QUANTUM_SIZE;
247247
let sample_rate_in = sample_rate;
248248
let sample_rate_out = sample_rate * 2;
249249
Self {
@@ -255,7 +255,7 @@ impl ResamplerConfig {
255255
}
256256

257257
fn upsample_x4(channels: usize, sample_rate: usize) -> Self {
258-
let chunk_size_in = RENDER_QUANTUM_SIZE * 4;
258+
let chunk_size_in = RENDER_QUANTUM_SIZE;
259259
let sample_rate_in = sample_rate;
260260
let sample_rate_out = sample_rate * 4;
261261
Self {
@@ -267,7 +267,7 @@ impl ResamplerConfig {
267267
}
268268

269269
fn downsample_x2(channels: usize, sample_rate: usize) -> Self {
270-
let chunk_size_in = RENDER_QUANTUM_SIZE;
270+
let chunk_size_in = RENDER_QUANTUM_SIZE * 2;
271271
let sample_rate_in = sample_rate * 2;
272272
let sample_rate_out = sample_rate;
273273
Self {
@@ -279,7 +279,7 @@ impl ResamplerConfig {
279279
}
280280

281281
fn downsample_x4(channels: usize, sample_rate: usize) -> Self {
282-
let chunk_size_in = RENDER_QUANTUM_SIZE;
282+
let chunk_size_in = RENDER_QUANTUM_SIZE * 4;
283283
let sample_rate_in = sample_rate * 4;
284284
let sample_rate_out = sample_rate;
285285
Self {
@@ -375,7 +375,7 @@ struct WaveShaperRenderer {
375375
upsampler_x2: Resampler,
376376
// up sampler configured to multiply by 4 the input signal
377377
upsampler_x4: Resampler,
378-
// down sampler configured to divide by 4 the upsampled signal
378+
// down sampler configured to divide by 2 the upsampled signal
379379
downsampler_x2: Resampler,
380380
// down sampler configured to divide by 4 the upsampled signal
381381
downsampler_x4: Resampler,
@@ -499,6 +499,7 @@ impl AudioProcessor for WaveShaperRenderer {
499499
if let Some(curve) = msg.downcast_mut::<Option<Vec<f32>>>() {
500500
std::mem::swap(&mut self.curve, curve);
501501

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

0 commit comments

Comments
 (0)