Tweak latency reporting/compensation.

This commit is contained in:
Jonathan Moore Liles 2013-09-12 00:07:18 -07:00
parent 758f7b86b4
commit 9b634cf001
6 changed files with 88 additions and 49 deletions

View File

@ -399,24 +399,57 @@ Chain::configure_ports ( void )
void void
Chain::set_latency ( JACK::Port::direction_e dir ) Chain::set_latency ( JACK::Port::direction_e dir )
{ {
nframes_t total_latency = 0; nframes_t tmax = 0;
nframes_t tmin = 0;
nframes_t added = 0;
if ( dir == JACK::Port::Input ) if ( dir == JACK::Port::Input )
{ {
for ( int i = 0; i < modules(); ++i ) for ( int i = 0; i < modules(); ++i )
{ {
Module *m = module( i ); Module *m = module( i );
total_latency += m->get_latency( dir ); nframes_t min,max;
m->set_latency( dir, total_latency );
/* 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 else
{ {
tmin = JACK_MAX_FRAMES >> 1;
for ( int i = modules(); i--; ) for ( int i = modules(); i--; )
{ {
Module *m = module( i ); Module *m = module( i );
total_latency += m->get_latency( dir );
m->set_latency( dir, total_latency ); 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 );
} }
} }
} }

View File

@ -1157,9 +1157,9 @@ Module::auto_disconnect_outputs ( void )
} }
nframes_t nframes_t
Module::get_latency ( JACK::Port::direction_e dir ) const Module::get_latency ( JACK::Port::direction_e dir, nframes_t *min, nframes_t *max ) const
{ {
nframes_t tmin = 0; nframes_t tmin = JACK_MAX_FRAMES >> 1;
nframes_t tmax = 0; nframes_t tmax = 0;
if ( dir == JACK::Port::Input ) if ( dir == JACK::Port::Input )
@ -1168,21 +1168,23 @@ Module::get_latency ( JACK::Port::direction_e dir ) const
{ {
for ( unsigned int i = 0; i < aux_audio_input.size(); i++ ) for ( unsigned int i = 0; i < aux_audio_input.size(); i++ )
{ {
/* if ( ! aux_audio_input[i].jack_port()->connected() ) */
/* continue; */
nframes_t min,max; nframes_t min,max;
aux_audio_input[i].jack_port()->get_latency( dir, &min, &max ); aux_audio_input[i].jack_port()->get_latency( dir, &min, &max );
tmin += min; if ( min < tmin )
tmax += max; tmin = min;
if ( max > tmax )
tmax = max;
} }
tmin /= aux_audio_input.size();
tmax /= aux_audio_input.size();
} }
else
return tmin; {
/* for ( unsigned int i = 0; i < aux_audio_output.size(); i++ ) */ tmin = 0;
/* aux_audio_output[i].set_latency( dir, tmin, tmax ); */ }
} }
else else
{ {
@ -1190,38 +1192,39 @@ Module::get_latency ( JACK::Port::direction_e dir ) const
{ {
for ( unsigned int i = 0; i < aux_audio_output.size(); i++ ) for ( unsigned int i = 0; i < aux_audio_output.size(); i++ )
{ {
/* if ( ! aux_audio_output[i].jack_port()->connected() ) */
/* continue; */
nframes_t min,max; nframes_t min,max;
aux_audio_output[i].jack_port()->get_latency( dir, &min, &max ); aux_audio_output[i].jack_port()->get_latency( dir, &min, &max );
tmin += min; if ( min < tmin )
tmax += max; tmin = min;
if ( max > tmax )
tmax = max;
} }
tmin /= aux_audio_output.size();
tmax /= aux_audio_output.size();
} }
return tmin;
/* for ( unsigned int i = 0; i < aux_audio_output.size(); i++ ) */
/* aux_audio_output[i].set_latency( dir, tmin, tmax ); */
} }
*min = tmin;
*max = tmax;
return 0;
} }
void void
Module::set_latency ( JACK::Port::direction_e dir, nframes_t latency ) Module::set_latency ( JACK::Port::direction_e dir, nframes_t min, nframes_t max )
{ {
if ( dir == JACK::Port::Input ) if ( dir == JACK::Port::Output )
{ {
for ( unsigned int i = 0; i < aux_audio_output.size(); i++ ) for ( unsigned int i = 0; i < aux_audio_input.size(); i++ )
aux_audio_output[i].jack_port()->set_latency( dir, latency, latency ); aux_audio_input[i].jack_port()->set_latency( dir, min, max );
} }
else else
{ {
for ( unsigned int i = 0; i < aux_audio_input.size(); i++ ) for ( unsigned int i = 0; i < aux_audio_output.size(); i++ )
aux_audio_input[i].jack_port()->set_latency( dir, latency, latency ); aux_audio_output[i].jack_port()->set_latency( dir, min, max );
} }
} }

View File

@ -72,8 +72,8 @@ protected:
public: public:
virtual nframes_t get_latency ( JACK::Port::direction_e dir ) const; virtual nframes_t 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 latency ); 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 */ /* true if this module was added by default and not under normal user control */
bool is_default ( void ) const { return _is_default; } bool is_default ( void ) const { return _is_default; }

View File

@ -420,15 +420,12 @@ Plugin_Module::get_plugin_latency ( void ) const
return 0; return 0;
} }
nframes_t nframes_t
Plugin_Module::get_latency ( JACK::Port::direction_e dir ) const Plugin_Module::get_latency ( JACK::Port::direction_e dir, nframes_t *min, nframes_t *max ) const
{ {
nframes_t latency = Module::get_latency( dir ); Module::get_latency( dir, min, max );
latency += get_plugin_latency(); return get_plugin_latency();
return latency;
} }
bool bool

View File

@ -67,7 +67,7 @@ private:
volatile nframes_t _latency; volatile nframes_t _latency;
nframes_t _last_latency; nframes_t _last_latency;
nframes_t get_plugin_latency ( void ) const; nframes_t get_plugin_latency ( void ) const;
void init ( void ); void init ( void );
@ -112,7 +112,7 @@ private:
public: public:
virtual void update ( void ); virtual void update ( void );
virtual nframes_t get_latency ( JACK::Port::direction_e dir ) const; 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 ); static std::list<Plugin_Info> get_all_plugins ( void );

View File

@ -312,18 +312,20 @@ Track::record ( Capture *c, nframes_t frame )
{ {
/* in freewheeling mode, assume we're bouncing and only /* in freewheeling mode, assume we're bouncing and only
* compensate for capture latency */ * compensate for capture latency */
_capture_offset = min; _capture_offset = max;
} }
else else
{ {
/* not freewheeling, so assume we're overdubbing and need to /* not freewheeling, so assume we're overdubbing and need to
* compensate for both capture and playback latency */ * compensate for both capture and playback latency */
_capture_offset = min; _capture_offset = max;
/* since the track output might not be connected to /* since the track output might not be connected to
* anything, just get the playback latency */ * anything, just get the playback latency */
/* When playback latency compensation is enabled, this will
_capture_offset += engine->playback_latency(); * have already been done. */
if ( ! Timeline::playback_latency_compensation )
_capture_offset += engine->playback_latency();
} }
} }
@ -371,9 +373,13 @@ Track::compute_latency_compensation ( void )
nframes_t min,max; nframes_t min,max;
output[0].get_latency( JACK::Port::Output, &min, &max ); output[0].get_latency( JACK::Port::Output, &min, &max );
DMESSAGE( "Track %s, setting undelay to %lu", name(), (unsigned long)min); DMESSAGE( "Track %s, setting undelay to %lu", name(), (unsigned long)max);
char s[256];
snprintf( s, sizeof(s), "Latency Comp: -%lu", (unsigned long)max);
copy_tooltip(s);
undelay( min ); undelay( max );
} }
else else
{ {