Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

libjack_time.cpp 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Carla JACK API for external applications
  3. * Copyright (C) 2016-2018 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "libjack.hpp"
  18. CARLA_BACKEND_USE_NAMESPACE
  19. // --------------------------------------------------------------------------------------------------------------------
  20. CARLA_EXPORT
  21. jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* client)
  22. {
  23. const JackClientState* const jclient = (const JackClientState*)client;
  24. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 0);
  25. // TODO
  26. return 0;
  27. }
  28. CARLA_EXPORT
  29. jack_nframes_t jack_frame_time(const jack_client_t* client)
  30. {
  31. const JackClientState* const jclient = (const JackClientState*)client;
  32. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 0);
  33. // FIXME
  34. return static_cast<jack_nframes_t>(jclient->server.position.usecs);
  35. }
  36. CARLA_EXPORT
  37. jack_nframes_t jack_last_frame_time(const jack_client_t* client)
  38. {
  39. const JackClientState* const jclient = (const JackClientState*)client;
  40. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 0);
  41. // FIXME
  42. return static_cast<jack_nframes_t>(jclient->server.position.usecs);
  43. }
  44. // int jack_get_cycle_times(const jack_client_t *client,
  45. // jack_nframes_t *current_frames,
  46. // jack_time_t *current_usecs,
  47. // jack_time_t *next_usecs,
  48. // float *period_usecs) JACK_OPTIONAL_WEAK_EXPORT;
  49. // --------------------------------------------------------------------------------------------------------------------
  50. CARLA_EXPORT
  51. jack_time_t jack_frames_to_time(const jack_client_t* client, jack_nframes_t frames)
  52. {
  53. const JackClientState* const jclient = (const JackClientState*)client;
  54. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 0);
  55. return static_cast<jack_time_t>(static_cast<double>(frames) / jclient->server.sampleRate * 1000000.0);
  56. }
  57. CARLA_EXPORT
  58. jack_nframes_t jack_time_to_frames(const jack_client_t* client, jack_time_t time)
  59. {
  60. const JackClientState* const jclient = (const JackClientState*)client;
  61. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 0);
  62. return static_cast<jack_nframes_t>(static_cast<double>(time) / 1000000.0 * jclient->server.sampleRate);
  63. }
  64. CARLA_EXPORT
  65. jack_time_t jack_get_time(void)
  66. {
  67. timespec t;
  68. clock_gettime(CLOCK_MONOTONIC, &t);
  69. return static_cast<jack_time_t>(t.tv_sec * 1000000 + t.tv_nsec / 1000);
  70. }
  71. // --------------------------------------------------------------------------------------------------------------------