@@ -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,7 +396,7 @@ impl AudioProcessor for WaveShaperRenderer {
393396 let input = & inputs[ 0 ] ;
394397 let output = & mut outputs[ 0 ] ;
395398
396- if input. is_silent ( ) {
399+ if input. is_silent ( ) && self . can_propagate_silence {
397400 output. make_silent ( ) ;
398401 return false ;
399402 }
@@ -495,6 +498,19 @@ impl AudioProcessor for WaveShaperRenderer {
495498
496499 if let Some ( curve) = msg. downcast_mut :: < Option < Vec < f32 > > > ( ) {
497500 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+
498514 return ;
499515 }
500516
@@ -534,6 +550,7 @@ impl WaveShaperRenderer {
534550 upsampler_x4,
535551 downsampler_x2,
536552 downsampler_x4,
553+ can_propagate_silence : true ,
537554 }
538555 }
539556}
0 commit comments