@@ -379,6 +379,9 @@ struct WaveShaperRenderer {
379379 downsampler_x2 : Resampler ,
380380 // down sampler configured to divide by 4 the upsampled signal
381381 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 ,
382385}
383386
384387impl AudioProcessor for WaveShaperRenderer {
@@ -393,6 +396,11 @@ impl AudioProcessor for WaveShaperRenderer {
393396 let input = & inputs[ 0 ] ;
394397 let output = & mut outputs[ 0 ] ;
395398
399+ if input. is_silent ( ) & self . can_propagate_silence {
400+ output. make_silent ( ) ;
401+ return false ;
402+ }
403+
396404 * output = input. clone ( ) ;
397405
398406 if let Some ( curve) = & self . curve {
@@ -490,6 +498,19 @@ impl AudioProcessor for WaveShaperRenderer {
490498
491499 if let Some ( curve) = msg. downcast_mut :: < Option < Vec < f32 > > > ( ) {
492500 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+
493514 return ;
494515 }
495516
@@ -529,6 +550,7 @@ impl WaveShaperRenderer {
529550 upsampler_x4,
530551 downsampler_x2,
531552 downsampler_x4,
553+ can_propagate_silence : true ,
532554 }
533555 }
534556}
0 commit comments