jack1 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.

71 lines
2.2KB

  1. /*
  2. Copyright (C) 2001-2004 Paul Davis, Tilman Linneweh
  3. Generic version, overridden by OS-specific definition when needed.
  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. $Id$
  16. */
  17. #ifndef __jack_time_h__
  18. #define __jack_time_h__
  19. #include <stdio.h>
  20. #include <jack/internal.h>
  21. #include <sysdeps/cycles.h>
  22. /* This is a kludge. We need one global instantiation of this
  23. * variable in each address space. So, libjack/client.c declares the
  24. * actual storage. Other source files will see it as an extern. */
  25. #define JACK_TIME_GLOBAL_DECL jack_time_t __jack_cpu_mhz
  26. extern JACK_TIME_GLOBAL_DECL;
  27. static inline jack_time_t
  28. jack_get_microseconds (void) {
  29. return get_cycles() / __jack_cpu_mhz;
  30. }
  31. /* This function is inspired by similar code in MPLayer.
  32. * It should be quite portable
  33. */
  34. static inline jack_time_t
  35. jack_get_mhz (void)
  36. {
  37. jack_time_t tsc_start, tsc_end;
  38. struct timeval tv_start, tv_end;
  39. long usec_delay;
  40. jack_time_t mhz;
  41. tsc_start = get_cycles();
  42. gettimeofday(&tv_start, NULL);
  43. usleep(100000);
  44. tsc_end = get_cycles();
  45. gettimeofday(&tv_end, NULL);
  46. usec_delay = 1000000 * (tv_end.tv_sec - tv_start.tv_sec)
  47. + (tv_end.tv_usec - tv_start.tv_usec);
  48. mhz = (tsc_end - tsc_start) / usec_delay;
  49. return mhz;
  50. }
  51. /* This should only be called ONCE per process. */
  52. static inline void
  53. jack_init_time ()
  54. {
  55. __jack_cpu_mhz = jack_get_mhz ();
  56. }
  57. #endif /* __jack_time_h__ */