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.

87 lines
2.2KB

  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)
  26. {
  27. fAnchorTime = cur_time;
  28. return int((double(fEngineControl->fBufferSize) * 1000000) / double(fEngineControl->fSampleRate));
  29. }
  30. int JackTimedDriver::CurrentCycle(jack_time_t cur_time)
  31. {
  32. return int((double(fCycleCount) * double(fEngineControl->fBufferSize) * 1000000.) / double(fEngineControl->fSampleRate)) - (cur_time - fAnchorTime);
  33. }
  34. int JackTimedDriver::ProcessAux()
  35. {
  36. jack_time_t cur_time = GetMicroSeconds();
  37. int wait_time;
  38. if (fCycleCount++ == 0) {
  39. wait_time = FirstCycle(cur_time);
  40. } else {
  41. wait_time = CurrentCycle(cur_time);
  42. }
  43. if (wait_time < 0) {
  44. NotifyXRun(cur_time, float(cur_time -fBeginDateUst));
  45. fCycleCount = 0;
  46. wait_time = 0;
  47. }
  48. //jack_log("JackTimedDriver::Process wait_time = %d", wait_time);
  49. JackSleep(wait_time);
  50. return 0;
  51. }
  52. int JackTimedDriver::Process()
  53. {
  54. JackDriver::CycleTakeBeginTime();
  55. JackAudioDriver::Process();
  56. return ProcessAux();
  57. }
  58. int JackTimedDriver::ProcessNull()
  59. {
  60. JackDriver::CycleTakeBeginTime();
  61. if (fEngineControl->fSyncMode) {
  62. ProcessGraphSyncMaster();
  63. } else {
  64. ProcessGraphAsyncMaster();
  65. }
  66. return ProcessAux();
  67. }
  68. } // end of namespace