Mixer: Make meters more efficient.

pull/119/merge
Jonathan Moore Liles 2020-10-30 20:55:31 -07:00
parent 368492f1c0
commit da78618e5b
6 changed files with 31 additions and 36 deletions

View File

@ -43,7 +43,7 @@ DPM::DPM ( int X, int Y, int W, int H, const char *L ) :
_last_drawn_hi_segment = 0;
pixels_per_segment( 4 );
pixels_per_segment( 5 );
type( FL_VERTICAL );
@ -51,8 +51,11 @@ DPM::DPM ( int X, int Y, int W, int H, const char *L ) :
dim( 0.95f );
box( FL_NO_BOX );
color( fl_color_average( FL_BLACK, FL_BACKGROUND_COLOR, 0.66f ) );
box( FL_FLAT_BOX );
color(FL_BLACK);
/* color( fl_color_average( FL_BLACK, FL_BACKGROUND_COLOR, 0.25f ) ); */
/* initialize gradients */
if ( DPM::_gradient[ 0 ] == 0 )
@ -80,12 +83,11 @@ DPM::DPM ( int X, int Y, int W, int H, const char *L ) :
}
{
smoothing.cutoff(25);
smoothing.sample_rate(1500);
/* smoothing.cutoff(25); */
smoothing.cutoff(200);
smoothing.sample_rate(30000);
smoothing.reset(-70.0f);
/* clear initial hump */
sample_t t[1500];
smoothing.apply(t,1500,-70);
}
resize( X,Y,W,H);
@ -188,7 +190,7 @@ DPM::draw ( void )
{
draw_label();
draw_box( FL_FLAT_BOX, X, Y, W, H, FL_BACKGROUND_COLOR );
draw_box( box(), X, Y, W, H, color() );
}
fl_push_clip( X, Y, W, H );
@ -233,7 +235,7 @@ DPM::draw ( void )
else if ( p == pv )
c = div_color( p );
else
c = dim_div_color( p );
c = FL_DARK1; // fl_color_average( FL_BACKGROUND_COLOR, FL_BLACK, 0.50f );// FL_BACKGROUND_COLOR; //dim_div_color( p );
if ( ! active )
c = fl_inactive( c );
@ -244,26 +246,12 @@ DPM::draw ( void )
if ( type() == FL_HORIZONTAL )
{
xx = X + p * bw;
fl_rectf( xx, Y, bw, H, c );
fl_rectf( xx + 1, Y, bw - 1, H, c );
}
else
{
yy = Y + H - ((p+1) * bh);
fl_rectf( X, yy, W, bh, c );
}
if ( _pixels_per_segment >= 3 )
{
fl_color( FL_BLACK );
if ( type() == FL_HORIZONTAL )
{
fl_line( xx, Y, xx, Y + H - 1 );
}
else
{
fl_line( X, yy, X + W - 1, yy );
}
fl_rectf( X, yy + 1, W, bh - 1, c );
}
/* } */

View File

@ -74,7 +74,7 @@ public:
void value ( float v )
{
sample_t buf[100];
sample_t buf[1];
if ( smoothing.apply( buf, 1, v ) )
v = buf[0];

View File

@ -194,7 +194,7 @@ Meter_Module::process ( nframes_t nframes )
for ( unsigned int i = 0; i < audio_input.size(); ++i )
{
// float dB = 20 * log10( get_peak_sample( (float*)audio_input[i].buffer(), nframes ) / 2.0f );
float dB = 20 * log10( buffer_get_peak( (sample_t*) audio_input[i].buffer(), nframes ) );
const float dB = 20 * log10( buffer_get_peak( (sample_t*) audio_input[i].buffer(), nframes ) );
((float*)control_output[0].buffer())[i] = dB;
if (dB > control_value[i])

View File

@ -590,7 +590,7 @@ Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) :
resize( X,Y,W,H );
update_frequency( 15 );
update_frequency( 30 );
Fl::add_timeout( FEEDBACK_UPDATE_FREQ, send_feedback_cb, this );

View File

@ -201,11 +201,16 @@ buffer_get_peak ( const sample_t * __restrict__ buf, nframes_t nframes )
float pmax = 0.0f;
float pmin = 0.0f;
for ( nframes_t i = 0; i < nframes; i++ )
while (nframes--)
{
pmax = buf_[i] > pmax ? buf_[i] : pmax;
pmin = buf_[i] < pmin ? buf_[i] : pmin;
const float v = *buf_++;
if ( v > pmax )
pmax = v;
if ( v < pmin )
pmin = v;
}
pmax = fabsf(pmax);
@ -241,6 +246,9 @@ Value_Smoothing_Filter::sample_rate ( nframes_t n )
bool
Value_Smoothing_Filter::apply( sample_t * __restrict__ dst, nframes_t nframes, float gt )
{
if ( target_reached(gt) )
return false;
sample_t * dst_ = (sample_t*) assume_aligned(dst);
const float a = 0.07f;
@ -251,9 +259,6 @@ Value_Smoothing_Filter::apply( sample_t * __restrict__ dst, nframes_t nframes, f
float g1 = this->g1;
float g2 = this->g2;
if ( target_reached(gt) )
return false;
for (nframes_t i = 0; i < nframes; i++)
{
g1 += w * (gm - g1 - a * g2);

View File

@ -57,6 +57,8 @@ public:
void cutoff ( float v ) { _cutoff = v; }
void reset ( float v ) { g2 = g1 = v; }
void sample_rate ( nframes_t v );
inline bool target_reached ( float gt ) const { return gt == g2; }