Browse Source

libjack: implement jack_get_cycle_times

tags/v2.1-rc1
falkTX 5 years ago
parent
commit
1b49ad13f7
3 changed files with 33 additions and 9 deletions
  1. +1
    -0
      source/libjack/libjack.cpp
  2. +3
    -1
      source/libjack/libjack.hpp
  3. +29
    -8
      source/libjack/libjack_time.cpp

+ 1
- 0
source/libjack/libjack.cpp View File

@@ -979,6 +979,7 @@ bool CarlaJackAppClient::handleRtData()
{
carla_stderr2("CarlaJackAppClient: fRealtimeThreadMutex tryLock failed");
}
fServer.monotonic_frame += frames;
break;
}



+ 3
- 1
source/libjack/libjack.hpp View File

@@ -276,6 +276,7 @@ struct JackServerState {

bool playing;
jack_position_t position;
jack_nframes_t monotonic_frame;

JackServerState(CarlaJackAppClient* const app)
: jackAppPtr(app),
@@ -286,7 +287,8 @@ struct JackServerState {
numMidiIns(0),
numMidiOuts(0),
playing(false),
position()
position(),
monotonic_frame(0)
{
carla_zeroStruct(position);
}


+ 29
- 8
source/libjack/libjack_time.cpp View File

@@ -37,7 +37,7 @@ jack_nframes_t jack_frame_time(const jack_client_t* client)
const JackClientState* const jclient = (const JackClientState*)client;
CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 0);

// FIXME
// FIXME this is wrong
return static_cast<jack_nframes_t>(jclient->server.position.usecs);
}

@@ -47,15 +47,32 @@ jack_nframes_t jack_last_frame_time(const jack_client_t* client)
const JackClientState* const jclient = (const JackClientState*)client;
CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 0);

// FIXME
return static_cast<jack_nframes_t>(jclient->server.position.usecs);
return static_cast<jack_nframes_t>(jclient->server.monotonic_frame);
}

// int jack_get_cycle_times(const jack_client_t *client,
// jack_nframes_t *current_frames,
// jack_time_t *current_usecs,
// jack_time_t *next_usecs,
// float *period_usecs) JACK_OPTIONAL_WEAK_EXPORT;
CARLA_EXPORT
int jack_get_cycle_times(const jack_client_t *client,
jack_nframes_t *current_frames,
jack_time_t *current_usecs,
jack_time_t *next_usecs,
float *period_usecs)
{
const JackClientState* const jclient = (const JackClientState*)client;
CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 1);

/* current_frames: the frame time counter at the start of the current cycle, same as jack_last_frame_time().
* current_usecs: the microseconds time at the start of the current cycle.
* next_usecs: the microseconds time of the start of the next next cycle as computed by the DLL.
* period_usecs: the current best estimate of the period time in microseconds.
*/
const double _period_usecs = static_cast<double>(jclient->server.bufferSize) / jclient->server.sampleRate;

*current_frames = jclient->server.monotonic_frame;
*current_usecs = jclient->server.position.usecs;
*next_usecs = jclient->server.position.usecs + static_cast<jack_time_t>(_period_usecs + 0.5);
*period_usecs = static_cast<float>(_period_usecs);
return 0;
}

// --------------------------------------------------------------------------------------------------------------------

@@ -81,7 +98,11 @@ CARLA_EXPORT
jack_time_t jack_get_time(void)
{
timespec t;
#ifdef CLOCK_MONOTONIC_RAW
clock_gettime(CLOCK_MONOTONIC_RAW, &t);
#else
clock_gettime(CLOCK_MONOTONIC, &t);
#endif
return static_cast<jack_time_t>(t.tv_sec * 1000000 + t.tv_nsec / 1000);
}



Loading…
Cancel
Save