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_latency.cpp 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Carla JACK API for external applications
  3. * Copyright (C) 2016-2022 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_PLUGIN_EXPORT
  21. int jack_set_latency_callback(jack_client_t* client, JackLatencyCallback callback, void* arg)
  22. {
  23. carla_stderr2("%s(%p, %p, %p)", __FUNCTION__, client, callback, arg);
  24. return 0;
  25. }
  26. // --------------------------------------------------------------------------------------------------------------------
  27. CARLA_PLUGIN_EXPORT
  28. void jack_port_get_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range)
  29. {
  30. carla_debug("%s(%p, %u, %p)", __FUNCTION__, port, mode, range);
  31. range->min = range->max = 0;
  32. return;
  33. // unused
  34. (void)port;
  35. (void)mode;
  36. }
  37. CARLA_PLUGIN_EXPORT
  38. void jack_port_set_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range)
  39. {
  40. carla_stderr2("%s(%p, %u, %p)", __FUNCTION__, port, mode, range);
  41. }
  42. // --------------------------------------------------------------------------------------------------------------------
  43. CARLA_PLUGIN_EXPORT
  44. int jack_recompute_total_latencies(jack_client_t* client)
  45. {
  46. carla_stderr2("%s(%p)", __FUNCTION__, client);
  47. return 0;
  48. }
  49. CARLA_PLUGIN_EXPORT
  50. jack_nframes_t jack_port_get_latency(jack_port_t* port)
  51. {
  52. carla_debug("%s(%p)", __FUNCTION__, port);
  53. JackPortState* const jport = (JackPortState*)port;
  54. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  55. if (jport->isMidi || ! jport->isSystem)
  56. return 0;
  57. // TODO
  58. const uint32_t bufferSize = 128;
  59. const uint32_t latencyMultiplier = 3;
  60. if (jport->flags & JackPortIsInput)
  61. return bufferSize*latencyMultiplier;
  62. if (jport->flags & JackPortIsOutput)
  63. return bufferSize;
  64. return 0;
  65. }
  66. CARLA_PLUGIN_EXPORT
  67. jack_nframes_t jack_port_get_total_latency(jack_client_t* client, jack_port_t* port)
  68. {
  69. carla_debug("%s(%p, %p)", __FUNCTION__, client, port);
  70. JackClientState* const jclient = (JackClientState*)client;
  71. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 1);
  72. JackPortState* const jport = (JackPortState*)port;
  73. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  74. if (jport->isMidi)
  75. return 0;
  76. // TODO
  77. const uint32_t bufferSize = jclient->server.bufferSize;
  78. const uint32_t latencyMultiplier = 3;
  79. if (jport->isSystem)
  80. {
  81. if (jport->flags & JackPortIsInput)
  82. return bufferSize*latencyMultiplier;
  83. if (jport->flags & JackPortIsOutput)
  84. return bufferSize;
  85. }
  86. else
  87. {
  88. if (jport->flags & JackPortIsInput)
  89. return bufferSize;
  90. if (jport->flags & JackPortIsOutput)
  91. return bufferSize*latencyMultiplier;
  92. }
  93. return 0;
  94. }
  95. // --------------------------------------------------------------------------------------------------------------------
  96. // deprecated calls
  97. CARLA_PLUGIN_EXPORT
  98. void jack_port_set_latency(jack_port_t* port, jack_nframes_t nframes)
  99. {
  100. carla_stderr2("%s(%p, %u)", __FUNCTION__, port, nframes);
  101. }
  102. CARLA_PLUGIN_EXPORT
  103. int jack_recompute_total_latency(jack_client_t* client, jack_port_t* port)
  104. {
  105. carla_stderr2("%s(%p, %p)", __FUNCTION__, client, port);
  106. return 0;
  107. }
  108. // --------------------------------------------------------------------------------------------------------------------