@@ -379,6 +379,9 @@ struct WaveShaperRenderer {
379
379
downsampler_x2 : Resampler ,
380
380
// down sampler configured to divide by 4 the upsampled signal
381
381
downsampler_x4 : Resampler ,
382
+ // check if silence can be propagated, i.e. if curve if None or if
383
+ // it's output value for zero signal is zero (i.e. < 1e-9)
384
+ can_propagate_silence : bool ,
382
385
}
383
386
384
387
impl AudioProcessor for WaveShaperRenderer {
@@ -393,7 +396,7 @@ impl AudioProcessor for WaveShaperRenderer {
393
396
let input = & inputs[ 0 ] ;
394
397
let output = & mut outputs[ 0 ] ;
395
398
396
- if input. is_silent ( ) {
399
+ if input. is_silent ( ) && self . can_propagate_silence {
397
400
output. make_silent ( ) ;
398
401
return false ;
399
402
}
@@ -495,6 +498,19 @@ impl AudioProcessor for WaveShaperRenderer {
495
498
496
499
if let Some ( curve) = msg. downcast_mut :: < Option < Vec < f32 > > > ( ) {
497
500
std:: mem:: swap ( & mut self . curve , curve) ;
501
+
502
+ self . can_propagate_silence = if let Some ( curve) = & self . curve {
503
+ if curve. len ( ) % 2 == 1 {
504
+ curve[ curve. len ( ) / 2 ] . abs ( ) < 1e-9
505
+ } else {
506
+ let a = curve[ curve. len ( ) / 2 - 1 ] ;
507
+ let b = curve[ curve. len ( ) / 2 ] ;
508
+ ( ( a + b) / 2. ) . abs ( ) < 1e-9
509
+ }
510
+ } else {
511
+ true
512
+ } ;
513
+
498
514
return ;
499
515
}
500
516
@@ -534,6 +550,7 @@ impl WaveShaperRenderer {
534
550
upsampler_x4,
535
551
downsampler_x2,
536
552
downsampler_x4,
553
+ can_propagate_silence : true ,
537
554
}
538
555
}
539
556
}
0 commit comments