Tweak DSP optimization.

This commit is contained in:
Jonathan Moore Liles 2013-09-08 13:51:05 -07:00
parent fc5c59c61d
commit 00ed29d6c2
8 changed files with 259 additions and 246 deletions

View File

@ -108,7 +108,15 @@ AUX_Module::handle_sample_rate_change ( nframes_t n )
void void
AUX_Module::process ( nframes_t nframes ) AUX_Module::process ( nframes_t nframes )
{ {
if ( !bypass() ) if ( unlikely( bypass() ) )
{
for ( unsigned int i = 0; i < audio_input.size(); ++i )
{
if ( audio_input[i].connected() )
buffer_fill_with_silence( (sample_t*)aux_audio_output[i].jack_port()->buffer(nframes), nframes );
}
}
else
{ {
float gt = DB_CO( control_input[0].control_value() ); float gt = DB_CO( control_input[0].control_value() );
@ -116,9 +124,8 @@ AUX_Module::process ( nframes_t nframes )
bool use_gainbuf = smoothing.apply( gainbuf, nframes, gt ); bool use_gainbuf = smoothing.apply( gainbuf, nframes, gt );
if ( use_gainbuf ) if ( unlikely( use_gainbuf ) )
{ {
for ( unsigned int i = 0; i < audio_input.size(); ++i ) for ( unsigned int i = 0; i < audio_input.size(); ++i )
{ {
if ( audio_input[i].connected() ) if ( audio_input[i].connected() )
@ -135,14 +142,6 @@ AUX_Module::process ( nframes_t nframes )
} }
} }
} }
else
{
for ( unsigned int i = 0; i < audio_input.size(); ++i )
{
if ( audio_input[i].connected() )
buffer_fill_with_silence( (sample_t*)aux_audio_output[i].jack_port()->buffer(nframes), nframes );
}
}
} }
void void

View File

@ -105,13 +105,20 @@ Gain_Module::handle_sample_rate_change ( nframes_t n )
void void
Gain_Module::process ( nframes_t nframes ) Gain_Module::process ( nframes_t nframes )
{ {
if ( unlikely( bypass() ) )
{
/* nothing to do */
}
else
{
const float gt = DB_CO( control_input[1].control_value() ? -90.f : control_input[0].control_value() ); const float gt = DB_CO( control_input[1].control_value() ? -90.f : control_input[0].control_value() );
sample_t gainbuf[nframes]; sample_t gainbuf[nframes];
bool use_gainbuf = smoothing.apply( gainbuf, nframes, gt ); bool use_gainbuf = smoothing.apply( gainbuf, nframes, gt );
if ( use_gainbuf ) if ( unlikely( use_gainbuf ) )
{ {
for ( int i = audio_input.size(); i--; ) for ( int i = audio_input.size(); i--; )
{ {
@ -131,4 +138,5 @@ Gain_Module::process ( nframes_t nframes )
buffer_apply_gain( (sample_t*)audio_input[i].buffer(), nframes, gt ); buffer_apply_gain( (sample_t*)audio_input[i].buffer(), nframes, gt );
} }
} }
}
} }

View File

@ -174,8 +174,6 @@ Meter_Module::process ( nframes_t nframes )
{ {
for ( unsigned int i = 0; i < audio_input.size(); ++i ) for ( unsigned int i = 0; i < audio_input.size(); ++i )
{ {
if ( audio_input[i].connected() )
{
// float dB = 20 * log10( get_peak_sample( (float*)audio_input[i].buffer(), nframes ) / 2.0f ); // 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 ) ); float dB = 20 * log10( buffer_get_peak( (sample_t*) audio_input[i].buffer(), nframes ) );
@ -183,5 +181,4 @@ Meter_Module::process ( nframes_t nframes )
if (dB > control_value[i]) if (dB > control_value[i])
control_value[i] = dB; control_value[i] = dB;
} }
}
} }

View File

@ -80,12 +80,7 @@ Mono_Pan_Module::configure_inputs ( int )
void void
Mono_Pan_Module::process ( nframes_t nframes ) Mono_Pan_Module::process ( nframes_t nframes )
{ {
if ( unlikely( bypass() ) )
if ( audio_input[0].connected() &&
audio_output[0].connected() &&
audio_output[1].connected() )
{
if ( bypass() )
{ {
buffer_copy( (sample_t*)audio_output[1].buffer(), (sample_t*)audio_input[0].buffer(), nframes ); buffer_copy( (sample_t*)audio_output[1].buffer(), (sample_t*)audio_input[0].buffer(), nframes );
} }
@ -93,12 +88,11 @@ Mono_Pan_Module::process ( nframes_t nframes )
{ {
const float gt = (control_input[0].control_value() + 1.0f) * 0.5f; const float gt = (control_input[0].control_value() + 1.0f) * 0.5f;
if ( ! smoothing.target_reached( gt ) )
{
sample_t gainbuf[nframes]; sample_t gainbuf[nframes];
bool use_gainbuf = smoothing.apply( gainbuf, nframes, gt );
smoothing.apply( gainbuf, nframes, gt ); if ( unlikely( use_gainbuf ) )
{
/* right channel */ /* right channel */
buffer_copy_and_apply_gain_buffer( (sample_t*)audio_output[1].buffer(), buffer_copy_and_apply_gain_buffer( (sample_t*)audio_output[1].buffer(),
@ -124,5 +118,4 @@ Mono_Pan_Module::process ( nframes_t nframes )
buffer_apply_gain( (sample_t*)audio_output[0].buffer(), nframes, 1.0f - gt); buffer_apply_gain( (sample_t*)audio_output[0].buffer(), nframes, 1.0f - gt);
} }
} }
}
} }

View File

@ -795,12 +795,7 @@ Plugin_Module::process ( nframes_t nframes )
{ {
handle_port_connection_change(); handle_port_connection_change();
if ( !bypass() ) if ( unlikely( bypass() ) )
{
for ( unsigned int i = 0; i < _idata->handle.size(); ++i )
_idata->descriptor->run( _idata->handle[i], nframes );
}
else
{ {
/* If this is a mono to stereo plugin, then duplicate the input channel... */ /* If this is a mono to stereo plugin, then duplicate the input channel... */
/* There's not much we can do to automatically support other configurations. */ /* There's not much we can do to automatically support other configurations. */
@ -808,9 +803,16 @@ Plugin_Module::process ( nframes_t nframes )
{ {
buffer_copy( (sample_t*)audio_output[1].buffer(), (sample_t*)audio_input[0].buffer(), nframes ); buffer_copy( (sample_t*)audio_output[1].buffer(), (sample_t*)audio_input[0].buffer(), nframes );
} }
_latency = 0;
} }
else
{
for ( unsigned int i = 0; i < _idata->handle.size(); ++i )
_idata->descriptor->run( _idata->handle[i], nframes );
_latency = get_plugin_latency(); _latency = get_plugin_latency();
}
} }

View File

@ -595,8 +595,6 @@ Spatializer_Module::draw ( void )
void void
Spatializer_Module::process ( nframes_t nframes ) Spatializer_Module::process ( nframes_t nframes )
{ {
if ( !bypass() )
{
float azimuth = control_input[0].control_value(); float azimuth = control_input[0].control_value();
float elevation = control_input[1].control_value(); float elevation = control_input[1].control_value();
float radius = control_input[2].control_value(); float radius = control_input[2].control_value();
@ -651,7 +649,7 @@ Spatializer_Module::process ( nframes_t nframes )
use_gainbuf = late_gain_smoothing.apply( gainbuf, nframes, late_gain ); use_gainbuf = late_gain_smoothing.apply( gainbuf, nframes, late_gain );
/* gain effects */ /* gain effects */
if ( use_gainbuf ) if ( unlikely( use_gainbuf ) )
buffer_apply_gain_buffer( (sample_t*)aux_audio_output[0].jack_port()->buffer(nframes), gainbuf, nframes ); buffer_apply_gain_buffer( (sample_t*)aux_audio_output[0].jack_port()->buffer(nframes), gainbuf, nframes );
else else
buffer_apply_gain( (sample_t*)aux_audio_output[0].jack_port()->buffer(nframes), nframes, late_gain ); buffer_apply_gain( (sample_t*)aux_audio_output[0].jack_port()->buffer(nframes), nframes, late_gain );
@ -695,7 +693,7 @@ Spatializer_Module::process ( nframes_t nframes )
for ( int i = 1; i < 5; i++ ) for ( int i = 1; i < 5; i++ )
{ {
/* gain effects */ /* gain effects */
if ( use_gainbuf ) if ( unlikely( use_gainbuf ) )
buffer_apply_gain_buffer( (sample_t*)aux_audio_output[i].jack_port()->buffer(nframes), gainbuf, nframes ); buffer_apply_gain_buffer( (sample_t*)aux_audio_output[i].jack_port()->buffer(nframes), gainbuf, nframes );
else else
buffer_apply_gain( (sample_t*)aux_audio_output[i].jack_port()->buffer(nframes), nframes, early_gain ); buffer_apply_gain( (sample_t*)aux_audio_output[i].jack_port()->buffer(nframes), nframes, early_gain );
@ -714,7 +712,7 @@ Spatializer_Module::process ( nframes_t nframes )
for ( unsigned int i = 0; i < audio_input.size(); i++ ) for ( unsigned int i = 0; i < audio_input.size(); i++ )
{ {
/* gain effects */ /* gain effects */
if ( use_gainbuf ) if ( unlikely( use_gainbuf ) )
buffer_apply_gain_buffer( (sample_t*)audio_input[i].buffer(), gainbuf, nframes ); buffer_apply_gain_buffer( (sample_t*)audio_input[i].buffer(), gainbuf, nframes );
else else
buffer_apply_gain( (sample_t*)audio_input[i].buffer(), nframes, gain ); buffer_apply_gain( (sample_t*)audio_input[i].buffer(), nframes, gain );
@ -723,9 +721,9 @@ Spatializer_Module::process ( nframes_t nframes )
_lowpass[i]->run_lowpass( (sample_t*)audio_input[i].buffer(), cutoff_frequency, nframes ); _lowpass[i]->run_lowpass( (sample_t*)audio_input[i].buffer(), cutoff_frequency, nframes );
/* delay effects */ /* delay effects */
if ( speed_of_sound ) if ( likely( speed_of_sound ) )
{ {
if ( use_delaybuf ) if ( unlikely( use_delaybuf ) )
_delay[i]->run( (sample_t*)audio_input[i].buffer(), delaybuf, 0, nframes ); _delay[i]->run( (sample_t*)audio_input[i].buffer(), delaybuf, 0, nframes );
else else
_delay[i]->run( (sample_t*)audio_input[i].buffer(), 0, delay_seconds, nframes ); _delay[i]->run( (sample_t*)audio_input[i].buffer(), 0, delay_seconds, nframes );
@ -757,7 +755,6 @@ Spatializer_Module::process ( nframes_t nframes )
width, width,
nframes ); nframes );
} }
}
} }
void void

View File

@ -46,17 +46,21 @@ buffer_apply_gain ( sample_t * __restrict__ buf, nframes_t nframes, float g )
{ {
sample_t * buf_ = (sample_t*) assume_aligned(buf); sample_t * buf_ = (sample_t*) assume_aligned(buf);
if ( g != 1.0f ) if ( g == 1.0f )
while ( nframes-- ) return;
*(buf_++) *= g;
for ( nframes_t i = 0; i < nframes; i++ )
buf_[i] *= g;
} }
void void
buffer_apply_gain_unaligned ( sample_t * __restrict__ buf, nframes_t nframes, float g ) buffer_apply_gain_unaligned ( sample_t * __restrict__ buf, nframes_t nframes, float g )
{ {
if ( g != 1.0f ) if ( g == 1.0f )
while ( nframes-- ) return;
*(buf++) *= g;
for ( nframes_t i = 0; i < nframes; i++ )
buf[i] *= g;
} }
void void
@ -65,8 +69,8 @@ buffer_apply_gain_buffer ( sample_t * __restrict__ buf, const sample_t * __restr
sample_t * buf_ = (sample_t*) assume_aligned(buf); sample_t * buf_ = (sample_t*) assume_aligned(buf);
const sample_t * gainbuf_ = (const sample_t*) assume_aligned(gainbuf); const sample_t * gainbuf_ = (const sample_t*) assume_aligned(gainbuf);
while ( nframes-- ) for ( nframes_t i = 0; i < nframes; i++ )
*(buf_++) *= *(gainbuf_++); buf_[i] *= gainbuf_[i];
} }
void void
@ -76,8 +80,8 @@ buffer_copy_and_apply_gain_buffer ( sample_t * __restrict__ dst, const sample_t
const sample_t * src_ = (const sample_t*) assume_aligned(src); const sample_t * src_ = (const sample_t*) assume_aligned(src);
const sample_t * gainbuf_ = (const sample_t*) assume_aligned(gainbuf); const sample_t * gainbuf_ = (const sample_t*) assume_aligned(gainbuf);
while ( nframes-- ) for ( nframes_t i = 0; i < nframes; i++ )
*(dst_++) = *(src_++) * *(gainbuf_++); dst_[i] = src_[i] * gainbuf_[i];
} }
void void
@ -86,8 +90,8 @@ buffer_mix ( sample_t * __restrict__ dst, const sample_t * __restrict__ src, nfr
sample_t * dst_ = (sample_t*) assume_aligned(dst); sample_t * dst_ = (sample_t*) assume_aligned(dst);
const sample_t * src_ = (const sample_t*) assume_aligned(src); const sample_t * src_ = (const sample_t*) assume_aligned(src);
while ( nframes-- ) for ( nframes_t i = 0; i < nframes; i++ )
*(dst_++) += *(src_++); dst_[i] += src_[i];
} }
void void
@ -96,8 +100,8 @@ buffer_mix_with_gain ( sample_t * __restrict__ dst, const sample_t * __restrict_
sample_t * dst_ = (sample_t*) assume_aligned(dst); sample_t * dst_ = (sample_t*) assume_aligned(dst);
const sample_t * src_ = (const sample_t*) assume_aligned(src); const sample_t * src_ = (const sample_t*) assume_aligned(src);
while ( nframes-- ) for ( nframes_t i = 0; i < nframes; i++ )
*(dst_++) += *(src_++) * g; dst_[i] += src_[i] * g;
} }
void void
@ -181,7 +185,9 @@ buffer_is_digital_black ( sample_t *buf, nframes_t nframes )
{ {
while ( nframes-- ) while ( nframes-- )
{ {
if ( 0 != buf[nframes] ) if (! *(buf++) )
continue;
return false; return false;
} }
@ -193,15 +199,19 @@ buffer_get_peak ( const sample_t * __restrict__ buf, nframes_t nframes )
{ {
const sample_t * buf_ = (const sample_t*) assume_aligned(buf); const sample_t * buf_ = (const sample_t*) assume_aligned(buf);
float p = 0.0f; float pmax = 0.0f;
float pmin = 0.0f;
while ( nframes-- ) for ( nframes_t i = 0; i < nframes; i++ )
{ {
const float s = fabs(*(buf_++)); pmax = buf_[i] > pmax ? buf_[i] : pmax;
p = s > p ? s : p; pmin = buf_[i] < pmin ? buf_[i] : pmin;
} }
return p; pmax = fabsf(pmax);
pmin = fabsf(pmin);
return pmax > pmin ? pmax : pmin;
} }
void void

View File

@ -79,3 +79,10 @@ static inline float interpolate_cubic ( const float fr, const float inm1, const
#define DEG2RAD 0.01745329251f #define DEG2RAD 0.01745329251f
#define ONEOVERSQRT2 0.70710678118f #define ONEOVERSQRT2 0.70710678118f
#ifndef likely
#define likely(x) __builtin_expect(x,1)
#endif
#ifndef unlikely
#define unlikely(x) __builtin_expect(x,0)
#endif