Tweak DSP optimization.

pull/116/head
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
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() );
@ -116,9 +124,8 @@ AUX_Module::process ( nframes_t nframes )
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 )
{
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

View File

@ -105,13 +105,20 @@ Gain_Module::handle_sample_rate_change ( nframes_t n )
void
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() );
sample_t gainbuf[nframes];
bool use_gainbuf = smoothing.apply( gainbuf, nframes, gt );
if ( use_gainbuf )
if ( unlikely( use_gainbuf ) )
{
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 );
}
}
}
}

View File

@ -174,8 +174,6 @@ Meter_Module::process ( nframes_t nframes )
{
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( 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])
control_value[i] = dB;
}
}
}

View File

@ -80,12 +80,7 @@ Mono_Pan_Module::configure_inputs ( int )
void
Mono_Pan_Module::process ( nframes_t nframes )
{
if ( audio_input[0].connected() &&
audio_output[0].connected() &&
audio_output[1].connected() )
{
if ( bypass() )
if ( unlikely( bypass() ) )
{
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;
if ( ! smoothing.target_reached( gt ) )
{
sample_t gainbuf[nframes];
bool use_gainbuf = smoothing.apply( gainbuf, nframes, gt );
smoothing.apply( gainbuf, nframes, gt );
if ( unlikely( use_gainbuf ) )
{
/* right channel */
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);
}
}
}
}

View File

@ -795,12 +795,7 @@ Plugin_Module::process ( nframes_t nframes )
{
handle_port_connection_change();
if ( !bypass() )
{
for ( unsigned int i = 0; i < _idata->handle.size(); ++i )
_idata->descriptor->run( _idata->handle[i], nframes );
}
else
if ( unlikely( bypass() ) )
{
/* 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. */
@ -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 );
}
_latency = 0;
}
else
{
for ( unsigned int i = 0; i < _idata->handle.size(); ++i )
_idata->descriptor->run( _idata->handle[i], nframes );
_latency = get_plugin_latency();
}
}

View File

@ -595,8 +595,6 @@ Spatializer_Module::draw ( void )
void
Spatializer_Module::process ( nframes_t nframes )
{
if ( !bypass() )
{
float azimuth = control_input[0].control_value();
float elevation = control_input[1].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 );
/* 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 );
else
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++ )
{
/* 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 );
else
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++ )
{
/* gain effects */
if ( use_gainbuf )
if ( unlikely( use_gainbuf ) )
buffer_apply_gain_buffer( (sample_t*)audio_input[i].buffer(), gainbuf, nframes );
else
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 );
/* 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 );
else
_delay[i]->run( (sample_t*)audio_input[i].buffer(), 0, delay_seconds, nframes );
@ -757,7 +755,6 @@ Spatializer_Module::process ( nframes_t nframes )
width,
nframes );
}
}
}
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);
if ( g != 1.0f )
while ( nframes-- )
*(buf_++) *= g;
if ( g == 1.0f )
return;
for ( nframes_t i = 0; i < nframes; i++ )
buf_[i] *= g;
}
void
buffer_apply_gain_unaligned ( sample_t * __restrict__ buf, nframes_t nframes, float g )
{
if ( g != 1.0f )
while ( nframes-- )
*(buf++) *= g;
if ( g == 1.0f )
return;
for ( nframes_t i = 0; i < nframes; i++ )
buf[i] *= g;
}
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);
const sample_t * gainbuf_ = (const sample_t*) assume_aligned(gainbuf);
while ( nframes-- )
*(buf_++) *= *(gainbuf_++);
for ( nframes_t i = 0; i < nframes; i++ )
buf_[i] *= gainbuf_[i];
}
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 * gainbuf_ = (const sample_t*) assume_aligned(gainbuf);
while ( nframes-- )
*(dst_++) = *(src_++) * *(gainbuf_++);
for ( nframes_t i = 0; i < nframes; i++ )
dst_[i] = src_[i] * gainbuf_[i];
}
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);
const sample_t * src_ = (const sample_t*) assume_aligned(src);
while ( nframes-- )
*(dst_++) += *(src_++);
for ( nframes_t i = 0; i < nframes; i++ )
dst_[i] += src_[i];
}
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);
const sample_t * src_ = (const sample_t*) assume_aligned(src);
while ( nframes-- )
*(dst_++) += *(src_++) * g;
for ( nframes_t i = 0; i < nframes; i++ )
dst_[i] += src_[i] * g;
}
void
@ -181,7 +185,9 @@ buffer_is_digital_black ( sample_t *buf, nframes_t nframes )
{
while ( nframes-- )
{
if ( 0 != buf[nframes] )
if (! *(buf++) )
continue;
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);
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_++));
p = s > p ? s : p;
pmax = buf_[i] > pmax ? buf_[i] : pmax;
pmin = buf_[i] < pmin ? buf_[i] : pmin;
}
return p;
pmax = fabsf(pmax);
pmin = fabsf(pmin);
return pmax > pmin ? pmax : pmin;
}
void

View File

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