jack2 codebase
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.

106 lines
2.7KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include "JackTimedDriver.h"
  17. #include "JackEngineControl.h"
  18. #include "JackTime.h"
  19. #include "JackCompilerDeps.h"
  20. #include <iostream>
  21. #ifndef _MSC_VER
  22. #include <unistd.h>
  23. #endif
  24. #include <math.h>
  25. namespace Jack
  26. {
  27. int JackTimedDriver::FirstCycle(jack_time_t cur_time_usec)
  28. {
  29. fAnchorTimeUsec = cur_time_usec;
  30. return int((double(fEngineControl->fBufferSize) * 1000000) / double(fEngineControl->fSampleRate));
  31. }
  32. int JackTimedDriver::CurrentCycle(jack_time_t cur_time_usec)
  33. {
  34. return int(((double(fCycleCount) * double(fEngineControl->fBufferSize) * 1000000.) / double(fEngineControl->fSampleRate)) - (cur_time_usec - fAnchorTimeUsec));
  35. }
  36. int JackTimedDriver::Start()
  37. {
  38. fCycleCount = 0;
  39. return JackAudioDriver::Start();
  40. }
  41. void JackTimedDriver::ProcessWait()
  42. {
  43. jack_time_t cur_time_usec = GetMicroSeconds();
  44. int wait_time_usec;
  45. if (fCycleCount++ == 0) {
  46. wait_time_usec = FirstCycle(cur_time_usec);
  47. } else {
  48. wait_time_usec = CurrentCycle(cur_time_usec);
  49. }
  50. if (wait_time_usec < 0) {
  51. NotifyXRun(cur_time_usec, float(cur_time_usec - fBeginDateUst));
  52. fCycleCount = 0;
  53. wait_time_usec = 0;
  54. jack_error("JackTimedDriver::Process XRun = %ld usec", (cur_time_usec - fBeginDateUst));
  55. }
  56. //jack_log("JackTimedDriver::Process wait_time = %d", wait_time_usec);
  57. JackSleep(wait_time_usec);
  58. }
  59. int JackWaiterDriver::ProcessNull()
  60. {
  61. JackDriver::CycleTakeBeginTime();
  62. // Graph processing without Read/Write
  63. if (fEngineControl->fSyncMode) {
  64. ProcessGraphSync();
  65. } else {
  66. ProcessGraphAsync();
  67. }
  68. // Keep end cycle time
  69. JackDriver::CycleTakeEndTime();
  70. ProcessWait();
  71. return 0;
  72. }
  73. void JackRestarterDriver::SetRestartDriver(JackDriver* driver)
  74. {
  75. fRestartDriver = driver;
  76. }
  77. int JackRestarterDriver::RestartWait()
  78. {
  79. if (!fRestartDriver) {
  80. jack_error("JackRestartedDriver::RestartWait driver not set");
  81. return -1;
  82. }
  83. return fRestartDriver->Start();
  84. }
  85. } // end of namespace