More latency compensation tweaks.

pull/116/head
Jonathan Moore Liles 2013-09-14 19:27:03 -07:00
parent 8675f7d31c
commit f3b73381d7
6 changed files with 91 additions and 105 deletions

View File

@ -401,56 +401,41 @@ Chain::set_latency ( JACK::Port::direction_e dir )
{
nframes_t tmax = 0;
nframes_t tmin = 0;
nframes_t added = 0;
nframes_t added_min = 0;
nframes_t added_max = 0;
if ( dir == JACK::Port::Input )
for ( int i = 0; i < modules(); i++ )
{
for ( int i = 0; i < modules(); ++i )
Module *m;
if ( dir == JACK::Port::Input )
m = module( i );
else
m = module( (modules() - 1) - i );
nframes_t min,max;
min = max = 0;
nframes_t a = m->get_module_latency();
added_min += a;
added_max += a;
if ( dir == JACK::Port::Input ? m->aux_audio_input.size() : m->aux_audio_output.size() )
{
Module *m = module( i );
nframes_t min,max;
/* added = m->get_latency( JACK::Port::Input, &min, &max ); */
added += m->get_latency( JACK::Port::Input, &min, &max );
min += added;
max += added;
if ( min > tmin )
tmin = min;
if ( max > tmax )
tmax = max;
m->set_latency( dir, tmin, tmax );
}
}
else
{
tmin = JACK_MAX_FRAMES >> 1;
for ( int i = modules(); i--; )
{
Module *m = module( i );
nframes_t min,max;
added += m->get_latency( JACK::Port::Output, &min, &max );
min += added;
max += added;
if ( min < tmin )
tmin = min;
if ( max > tmax )
tmax = max;
DMESSAGE( "Chain %s/%s: setting %s latency minimum to %lu", name(),
m->name(),
dir == JACK::Port::Input ? "Capture" : "Playback",
(unsigned long)tmin);
m->set_latency( dir, tmin, tmax );
m->get_latency( dir, &min, &max );
tmin = 0;
added_min = 0;
}
if ( min > tmin )
tmin = min;
if ( max > tmax )
tmax = max;
m->set_latency( dir, tmin + added_min, tmax + added_max );
}
}

View File

@ -125,6 +125,7 @@ Module::~Module ( )
void
Module::init ( void )
{
@ -143,9 +144,18 @@ Module::init ( void )
labelsize(12);
color( fl_rgb_color( 122,190,200 ) );
tooltip( "Left click to edit parameters; Ctrl + left click to select; right click or MENU key for menu." );
tooltip();
}
void
Module::update_tooltip ( void )
{
char *s;
asprintf( &s, "Left click to edit parameters; Ctrl + left click to select; right click or MENU key for menu. (info: latency: %lu)", (unsigned long) get_module_latency() );
copy_tooltip(s);
free(s);
}
void
Module::get ( Log_Entry &e ) const
@ -1156,61 +1166,43 @@ Module::auto_disconnect_outputs ( void )
}
}
nframes_t
void
Module::get_latency ( JACK::Port::direction_e dir, nframes_t *min, nframes_t *max ) const
{
nframes_t tmin = JACK_MAX_FRAMES >> 1;
nframes_t tmax = 0;
const std::vector<Port> *ports;
if ( dir == JACK::Port::Input )
ports = &aux_audio_input;
else
ports = &aux_audio_output;
if ( ports->size() )
{
if ( aux_audio_input.size() )
for ( unsigned int i = 0; i < ports->size(); i++ )
{
for ( unsigned int i = 0; i < aux_audio_input.size(); i++ )
{
/* if ( ! aux_audio_input[i].jack_port()->connected() ) */
/* continue; */
/* if ( ! ports->[i].jack_port()->connected() ) */
/* continue; */
nframes_t min,max;
aux_audio_input[i].jack_port()->get_latency( dir, &min, &max );
if ( min < tmin )
tmin = min;
if ( max > tmax )
tmax = max;
}
}
else
{
tmin = 0;
nframes_t min,max;
(*ports)[i].jack_port()->get_latency( dir, &min, &max );
if ( min < tmin )
tmin = min;
if ( max > tmax )
tmax = max;
}
}
else
{
if ( aux_audio_output.size() )
{
for ( unsigned int i = 0; i < aux_audio_output.size(); i++ )
{
/* if ( ! aux_audio_output[i].jack_port()->connected() ) */
/* continue; */
nframes_t min,max;
aux_audio_output[i].jack_port()->get_latency( dir, &min, &max );
if ( min < tmin )
tmin = min;
if ( max > tmax )
tmax = max;
}
}
tmin = 0;
}
*min = tmin;
*max = tmax;
return 0;
}
void

View File

@ -46,7 +46,6 @@ class Module : public Fl_Group, public Loggable {
nframes_t _nframes;
Chain *_chain;
bool _is_default;
// nframes_t _latency;
static nframes_t _sample_rate;
static Module *_copied_module_empty;
@ -72,7 +71,9 @@ protected:
public:
virtual nframes_t get_latency ( JACK::Port::direction_e dir, nframes_t *min, nframes_t *max ) const;
virtual nframes_t get_module_latency ( void ) const { return 0; }
virtual void get_latency ( JACK::Port::direction_e dir, nframes_t *min, nframes_t *max ) const;
virtual void set_latency ( JACK::Port::direction_e dir, nframes_t min, nframes_t max );
/* true if this module was added by default and not under normal user control */
@ -81,6 +82,8 @@ public:
virtual void update ( void ) {}
virtual void update_tooltip ( void );
class Port
{
/* char *type_names[] = { "Audio", "Control" }; */

View File

@ -151,6 +151,8 @@ Plugin_Module::update ( void )
}
_last_latency = _latency;
update_tooltip();
}
int
@ -407,7 +409,7 @@ Plugin_Module::bypass ( bool v )
}
nframes_t
Plugin_Module::get_plugin_latency ( void ) const
Plugin_Module::get_module_latency ( void ) const
{
for ( unsigned int i = ncontrol_outputs(); i--; )
{
@ -420,14 +422,6 @@ Plugin_Module::get_plugin_latency ( void ) const
return 0;
}
nframes_t
Plugin_Module::get_latency ( JACK::Port::direction_e dir, nframes_t *min, nframes_t *max ) const
{
Module::get_latency( dir, min, max );
return get_plugin_latency();
}
bool
Plugin_Module::load ( unsigned long id )
{
@ -808,7 +802,7 @@ Plugin_Module::process ( nframes_t nframes )
for ( unsigned int i = 0; i < _idata->handle.size(); ++i )
_idata->descriptor->run( _idata->handle[i], nframes );
_latency = get_plugin_latency();
_latency = get_module_latency();
}
}

View File

@ -68,8 +68,6 @@ private:
volatile nframes_t _latency;
nframes_t _last_latency;
nframes_t get_plugin_latency ( void ) const;
void init ( void );
void bbox ( int &X, int &Y, int &W, int &H )
@ -111,8 +109,9 @@ private:
public:
virtual nframes_t get_module_latency ( void ) const;
virtual void update ( void );
virtual nframes_t get_latency ( JACK::Port::direction_e dir, nframes_t *min, nframes_t *max ) const;
static std::list<Plugin_Info> get_all_plugins ( void );

View File

@ -370,16 +370,29 @@ Track::compute_latency_compensation ( void )
{
if ( Timeline::playback_latency_compensation && output.size() )
{
nframes_t min,max;
output[0].get_latency( JACK::Port::Output, &min, &max );
nframes_t tmin,tmax;
tmin = JACK_MAX_FRAMES >> 1;
tmax = 0;
DMESSAGE( "Track %s, setting undelay to %lu", name(), (unsigned long)max);
for ( unsigned int i = 0; i < output.size(); i++ )
{
nframes_t min,max;
output[i].get_latency( JACK::Port::Output, &min, &max );
if ( max > tmax )
tmax = max;
if ( min < tmin )
tmin = min;
}
DMESSAGE( "Track %s, setting undelay to %lu", name(), (unsigned long)tmax);
char s[256];
snprintf( s, sizeof(s), "Latency Comp: -%lu", (unsigned long)max);
snprintf( s, sizeof(s), "Latency Comp: -%lu", (unsigned long)tmax);
copy_tooltip(s);
undelay( max );
undelay( tmax );
}
else
{