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.

104 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. #include <unistd.h>
  22. #include <math.h>
  23. namespace Jack
  24. {
  25. int JackTimedDriver::FirstCycle(jack_time_t cur_time_usec)
  26. {
  27. fAnchorTimeUsec = cur_time_usec;
  28. return int((double(fEngineControl->fBufferSize) * 1000000) / double(fEngineControl->fSampleRate));
  29. }
  30. int JackTimedDriver::CurrentCycle(jack_time_t cur_time_usec)
  31. {
  32. return int(((double(fCycleCount) * double(fEngineControl->fBufferSize) * 1000000.) / double(fEngineControl->fSampleRate)) - (cur_time_usec - fAnchorTimeUsec));
  33. }
  34. int JackTimedDriver::Start()
  35. {
  36. fCycleCount = 0;
  37. return JackAudioDriver::Start();
  38. }
  39. void JackTimedDriver::ProcessWait()
  40. {
  41. jack_time_t cur_time_usec = GetMicroSeconds();
  42. int wait_time_usec;
  43. if (fCycleCount++ == 0) {
  44. wait_time_usec = FirstCycle(cur_time_usec);
  45. } else {
  46. wait_time_usec = CurrentCycle(cur_time_usec);
  47. }
  48. if (wait_time_usec < 0) {
  49. NotifyXRun(cur_time_usec, float(cur_time_usec - fBeginDateUst));
  50. fCycleCount = 0;
  51. wait_time_usec = 0;
  52. jack_error("JackTimedDriver::Process XRun = %ld usec", (cur_time_usec - fBeginDateUst));
  53. }
  54. //jack_log("JackTimedDriver::Process wait_time = %d", wait_time_usec);
  55. JackSleep(wait_time_usec);
  56. }
  57. int JackWaiterDriver::ProcessNull()
  58. {
  59. JackDriver::CycleTakeBeginTime();
  60. // Graph processing without Read/Write
  61. if (fEngineControl->fSyncMode) {
  62. ProcessGraphSync();
  63. } else {
  64. ProcessGraphAsync();
  65. }
  66. // Keep end cycle time
  67. JackDriver::CycleTakeEndTime();
  68. ProcessWait();
  69. return 0;
  70. }
  71. void JackRestarterDriver::SetRestartDriver(JackDriver* driver)
  72. {
  73. fRestartDriver = driver;
  74. }
  75. int JackRestarterDriver::RestartWait()
  76. {
  77. if (!fRestartDriver) {
  78. jack_error("JackRestartedDriver::RestartWait driver not set");
  79. return -1;
  80. }
  81. return fRestartDriver->Start();
  82. }
  83. } // end of namespace