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 Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __JackFrameTimer__
  17. #define __JackFrameTimer__
  18. #include "JackAtomicState.h"
  19. #include "JackCompilerDeps.h"
  20. #include "types.h"
  21. namespace Jack
  22. {
  23. /*!
  24. \brief A structure used for time management.
  25. */
  26. PRE_PACKED_STRUCTURE
  27. class SERVER_EXPORT JackTimer
  28. {
  29. friend class JackFrameTimer;
  30. private:
  31. jack_nframes_t fFrames;
  32. jack_time_t fCurrentWakeup;
  33. jack_time_t fCurrentCallback;
  34. jack_time_t fNextWakeUp;
  35. float fPeriodUsecs;
  36. float fFilterOmega; /* set once, never altered */
  37. bool fInitialized;
  38. public:
  39. JackTimer();
  40. ~JackTimer()
  41. {}
  42. jack_nframes_t Time2Frames(jack_time_t time, jack_nframes_t buffer_size);
  43. jack_time_t Frames2Time(jack_nframes_t frames, jack_nframes_t buffer_size);
  44. jack_nframes_t FramesSinceCycleStart(jack_time_t cur_time, jack_nframes_t frames_rate);
  45. int GetCycleTimes(jack_nframes_t* current_frames, jack_time_t* current_usecs, jack_time_t* next_usecs, float* period_usecs);
  46. jack_nframes_t CurFrame()
  47. {
  48. return fFrames;
  49. }
  50. jack_time_t CurTime()
  51. {
  52. return fCurrentWakeup;
  53. }
  54. } POST_PACKED_STRUCTURE;
  55. /*!
  56. \brief A class using the JackAtomicState to manage jack time.
  57. */
  58. PRE_PACKED_STRUCTURE
  59. class SERVER_EXPORT JackFrameTimer : public JackAtomicState<JackTimer>
  60. {
  61. private:
  62. bool fFirstWakeUp;
  63. void IncFrameTimeAux(jack_nframes_t buffer_size, jack_time_t callback_usecs, jack_time_t period_usecs);
  64. void InitFrameTimeAux(jack_time_t callback_usecs, jack_time_t period_usecs);
  65. public:
  66. JackFrameTimer(): fFirstWakeUp(true)
  67. {}
  68. ~JackFrameTimer()
  69. {}
  70. void InitFrameTime();
  71. void ResetFrameTime(jack_time_t callback_usecs);
  72. void IncFrameTime(jack_nframes_t buffer_size, jack_time_t callback_usecs, jack_time_t period_usecs);
  73. void ReadFrameTime(JackTimer* timer);
  74. } POST_PACKED_STRUCTURE;
  75. } // end of namespace
  76. #endif