2 * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
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.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include "win_utils.h"
24 #include "pbd/compose.h"
34 QueryPerformanceFrequency(&freq);
40 old_timer_resolution ()
42 static UINT timer_res_ms = 0;
51 set_min_timer_resolution ()
55 if (timeGetDevCaps (&caps, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
56 DEBUG_TIMING ("Could not get timer device capabilities.\n");
59 old_timer_resolution () = caps.wPeriodMin;
60 if (timeBeginPeriod (caps.wPeriodMin) != TIMERR_NOERROR) {
61 DEBUG_TIMING (string_compose (
62 "Could not set minimum timer resolution to %1(ms)\n", caps.wPeriodMin));
67 DEBUG_TIMING (string_compose ("Multimedia timer resolution set to %1(ms)\n",
74 reset_timer_resolution ()
76 if (old_timer_resolution ()) {
77 if (timeEndPeriod (old_timer_resolution ()) != TIMERR_NOERROR) {
78 DEBUG_TIMING ("Could not reset timer resolution.\n");
83 DEBUG_TIMING (string_compose ("Multimedia timer resolution set to %1(ms)\n",
84 old_timer_resolution ()));
89 uint64_t get_microseconds ()
91 static LARGE_INTEGER frequency = get_frequency ();
92 LARGE_INTEGER current_val;
94 QueryPerformanceCounter (¤t_val);
96 return (uint64_t)(((double)current_val.QuadPart) /
97 ((double)frequency.QuadPart) * 1000000.0);