2023-03-28 14:52:51 +00:00
# pragma once
2025-04-23 14:26:33 +00:00
# include <JuceHeader.h>
2023-03-28 14:52:51 +00:00
2025-04-23 14:26:33 +00:00
class SmoothEffect : public osci : : EffectApplication {
2023-03-28 14:52:51 +00:00
public :
2025-08-10 19:45:06 +00:00
SmoothEffect ( ) = default ;
explicit SmoothEffect ( juce : : String prefix , float defaultValue = 0.75f ) : idPrefix ( prefix ) , smoothingDefault ( defaultValue ) { }
2025-04-24 09:47:03 +00:00
osci : : Point apply ( int index , osci : : Point input , const std : : vector < std : : atomic < double > > & values , double sampleRate ) override {
double weight = juce : : jmax ( values [ 0 ] . load ( ) , 0.00001 ) ;
weight * = 0.95 ;
double strength = 10 ;
weight = std : : log ( strength * weight + 1 ) / std : : log ( strength + 1 ) ;
2025-08-13 07:41:13 +00:00
weight = std : : pow ( weight , 48000 / sampleRate ) ;
2025-04-24 09:47:03 +00:00
avg = weight * avg + ( 1 - weight ) * input ;
return avg ;
}
2025-08-10 19:45:06 +00:00
std : : shared_ptr < osci : : Effect > build ( ) const override {
auto id = idPrefix . isEmpty ( ) ? juce : : String ( " smoothing " ) : ( idPrefix + " Smoothing " ) ;
auto eff = std : : make_shared < osci : : Effect > (
std : : make_shared < SmoothEffect > ( id ) ,
new osci : : EffectParameter ( " Smoothing " , " This works as a low-pass frequency filter that removes high frequencies, making the image look smoother, and audio sound less harsh. " , id , VERSION_HINT , smoothingDefault , 0.0 , 1.0 )
) ;
eff - > setIcon ( BinaryData : : smoothing_svg ) ;
return eff ;
}
2023-03-28 14:52:51 +00:00
private :
2025-04-23 14:26:33 +00:00
osci : : Point avg ;
2025-08-10 19:45:06 +00:00
juce : : String idPrefix ;
2025-08-16 19:03:08 +00:00
float smoothingDefault = 0.5f ;
2024-08-26 17:09:29 +00:00
} ;