summaryrefslogtreecommitdiff
path: root/libs/backends
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2015-09-12 21:41:00 +1000
committerTim Mayberry <mojofunk@gmail.com>2015-09-16 11:22:16 +1000
commit3f5c01e4eb2d3bd925a7d4d5335cd025546480c6 (patch)
tree6fc706cc7ba51f1b0f78a42b20d39026f9417e1d /libs/backends
parent4ffe8ffc0faef8ea4bb17e27963bf3998a006995 (diff)
Move Windows timer utility functions from PA backend into libpbd
Diffstat (limited to 'libs/backends')
-rw-r--r--libs/backends/portaudio/portaudio_backend.cc2
-rw-r--r--libs/backends/portaudio/win_utils.cc183
-rw-r--r--libs/backends/portaudio/win_utils.h86
-rw-r--r--libs/backends/portaudio/winmmemidi_input_device.cc2
-rw-r--r--libs/backends/portaudio/winmmemidi_io.cc2
-rw-r--r--libs/backends/portaudio/winmmemidi_output_device.cc2
-rw-r--r--libs/backends/portaudio/wscript1
7 files changed, 4 insertions, 274 deletions
diff --git a/libs/backends/portaudio/portaudio_backend.cc b/libs/backends/portaudio/portaudio_backend.cc
index f4ab827556..2275c44276 100644
--- a/libs/backends/portaudio/portaudio_backend.cc
+++ b/libs/backends/portaudio/portaudio_backend.cc
@@ -32,12 +32,12 @@
#include "pbd/compose.h"
#include "pbd/error.h"
#include "pbd/file_utils.h"
+#include "pbd/windows_timer_utils.h"
#include "ardour/filesystem_paths.h"
#include "ardour/port_manager.h"
#include "i18n.h"
-#include "win_utils.h"
#include "mmcss.h"
#include "audio_utils.h"
diff --git a/libs/backends/portaudio/win_utils.cc b/libs/backends/portaudio/win_utils.cc
deleted file mode 100644
index 6d0e404749..0000000000
--- a/libs/backends/portaudio/win_utils.cc
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include "win_utils.h"
-
-#include <windows.h>
-#include <mmsystem.h>
-
-#include "pbd/compose.h"
-
-#include "debug.h"
-
-namespace {
-
-UINT&
-old_timer_resolution ()
-{
- static UINT timer_res_ms = 0;
- return timer_res_ms;
-}
-
-} // anon namespace
-
-namespace PBD {
-
-namespace MMTIMERS {
-
-bool
-set_min_resolution ()
-{
- TIMECAPS caps;
-
- if (timeGetDevCaps (&caps, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
- DEBUG_TIMING ("Could not get timer device capabilities.\n");
- return false;
- }
- return set_resolution(caps.wPeriodMin);
-}
-
-bool
-set_resolution (uint32_t timer_resolution_ms)
-{
- TIMECAPS caps;
-
- if (timeGetDevCaps (&caps, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
- DEBUG_TIMING ("Could not get timer device capabilities.\n");
- return false;
- }
-
- UINT old_timer_res = caps.wPeriodMin;
-
- if (timeBeginPeriod(timer_resolution_ms) != TIMERR_NOERROR) {
- DEBUG_TIMING(
- string_compose("Could not set minimum timer resolution to %1(ms)\n",
- timer_resolution_ms));
- return false;
- }
-
- old_timer_resolution () = old_timer_res;
-
- DEBUG_TIMING (string_compose ("Multimedia timer resolution set to %1(ms)\n",
- caps.wPeriodMin));
- return true;
-}
-
-bool
-get_resolution (uint32_t& timer_resolution_ms)
-{
- TIMECAPS caps;
-
- if (timeGetDevCaps(&caps, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
- DEBUG_TIMING ("Could not get timer device capabilities.\n");
- return false;
- }
- timer_resolution_ms = caps.wPeriodMin;
- return true;
-}
-
-bool
-reset_resolution ()
-{
- if (old_timer_resolution ()) {
- if (timeEndPeriod (old_timer_resolution ()) != TIMERR_NOERROR) {
- DEBUG_TIMING ("Could not reset timer resolution.\n");
- return false;
- }
- }
-
- DEBUG_TIMING (string_compose ("Multimedia timer resolution set to %1(ms)\n",
- old_timer_resolution ()));
-
- return true;
-}
-
-} // namespace MMTIMERS
-
-namespace {
-
-bool&
-qpc_frequency_success ()
-{
- static bool success = false;
- return success;
-}
-
-LARGE_INTEGER
-qpc_frequency ()
-{
- LARGE_INTEGER freq;
- if (QueryPerformanceFrequency(&freq) == 0) {
- DEBUG_TIMING ("Failed to determine frequency of QPC\n");
- qpc_frequency_success() = false;
- } else {
- qpc_frequency_success() = true;
- }
-
- return freq;
-}
-
-LARGE_INTEGER
-qpc_frequency_cached ()
-{
- static LARGE_INTEGER frequency = qpc_frequency ();
- return frequency;
-}
-
-} // anon namespace
-
-namespace QPC {
-
-bool
-get_timer_valid ()
-{
- // setup caching the timer frequency
- qpc_frequency_cached ();
- return qpc_frequency_success ();
-}
-
-int64_t
-get_microseconds ()
-{
- LARGE_INTEGER current_val;
-
- if (qpc_frequency_success()) {
- // MS docs say this will always succeed for systems >= XP but it may
- // not return a monotonic value with non-invariant TSC's etc
- if (QueryPerformanceCounter(&current_val) != 0) {
- return (int64_t)(((double)current_val.QuadPart) /
- ((double)qpc_frequency_cached().QuadPart) * 1000000.0);
- }
- }
- DEBUG_TIMING ("Could not get QPC timer\n");
- return -1;
-}
-
-} // namespace QPC
-
-int64_t
-get_microseconds ()
-{
- if (qpc_frequency_success()) {
- return QPC::get_microseconds ();
- }
- // For XP systems that don't support a high-res performance counter
- return g_get_monotonic_time ();
-}
-
-} // namespace PBD
diff --git a/libs/backends/portaudio/win_utils.h b/libs/backends/portaudio/win_utils.h
deleted file mode 100644
index c0c7bbf491..0000000000
--- a/libs/backends/portaudio/win_utils.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef WIN_UTILS_H
-#define WIN_UTILS_H
-
-#include <stdint.h>
-
-namespace PBD {
-
-namespace MMTIMERS {
-
-/**
- * Set the minimum Multimedia Timer resolution as supported by the system
- * @return true if min timer resolution was successfully set
- *
- * Call reset_resolution to restore old timer resolution
- */
-bool set_min_resolution ();
-
-/**
- * Get current Multimedia Timer resolution
- * @return true if getting the timer value was successful
- */
-bool get_resolution(uint32_t& timer_resolution_us);
-
-/**
- * Set current Multimedia Timer resolution
- * @return true if setting the timer value was successful
- */
-bool set_resolution(uint32_t timer_resolution_us);
-
-/**
- * Reset the Multimedia Timer back to what it was originally before
- * setting the timer resolution.
- */
-bool reset_resolution ();
-
-} // namespace MMTIMERS
-
-namespace QPC {
-
-/**
- * @return true if QueryPerformanceCounter is usable as a timer source
- */
-bool get_timer_valid ();
-
-/**
- * @return the value of the performance counter converted to microseconds
- *
- * If get_counter_valid returns true then get_microseconds will always
- * return a positive value. If QPC is not supported(OS < XP) then -1 is
- * returned but the MS docs say that this won't occur for systems >= XP.
- */
-int64_t get_microseconds ();
-
-} // namespace QPC
-
-/**
- * The highest resolution timer source provided by the system. On Vista and
- * above this is the value returned by QueryPerformanceCounter(QPC). On XP,
- * this will QPC if supported or otherwise g_get_monotonic_time will be used.
- *
- * @return A timer value in microseconds or -1 in the event that the reading
- * the timer source fails.
- */
-int64_t get_microseconds ();
-
-} // namespace PBD
-
-#endif // WIN_UTILS_H
diff --git a/libs/backends/portaudio/winmmemidi_input_device.cc b/libs/backends/portaudio/winmmemidi_input_device.cc
index 95e7faa476..4e5d2da257 100644
--- a/libs/backends/portaudio/winmmemidi_input_device.cc
+++ b/libs/backends/portaudio/winmmemidi_input_device.cc
@@ -22,8 +22,8 @@
#include <cmath>
#include "pbd/compose.h"
+#include "pbd/windows_timer_utils.h"
-#include "win_utils.h"
#include "midi_util.h"
#include "mmcss.h"
diff --git a/libs/backends/portaudio/winmmemidi_io.cc b/libs/backends/portaudio/winmmemidi_io.cc
index 4c93799637..427ff486d7 100644
--- a/libs/backends/portaudio/winmmemidi_io.cc
+++ b/libs/backends/portaudio/winmmemidi_io.cc
@@ -23,9 +23,9 @@
#include "pbd/error.h"
#include "pbd/compose.h"
+#include "pbd/windows_timer_utils.h"
#include "winmmemidi_io.h"
-#include "win_utils.h"
#include "debug.h"
#include "i18n.h"
diff --git a/libs/backends/portaudio/winmmemidi_output_device.cc b/libs/backends/portaudio/winmmemidi_output_device.cc
index a1d76cd236..f8071dd9b1 100644
--- a/libs/backends/portaudio/winmmemidi_output_device.cc
+++ b/libs/backends/portaudio/winmmemidi_output_device.cc
@@ -22,9 +22,9 @@
#include "pbd/debug.h"
#include "pbd/compose.h"
+#include "pbd/windows_timer_utils.h"
#include "rt_thread.h"
-#include "win_utils.h"
#include "midi_util.h"
#include "mmcss.h"
diff --git a/libs/backends/portaudio/wscript b/libs/backends/portaudio/wscript
index 9c661d83b0..c67490f1c7 100644
--- a/libs/backends/portaudio/wscript
+++ b/libs/backends/portaudio/wscript
@@ -26,7 +26,6 @@ def build(bld):
'winmmemidi_io.cc',
'winmmemidi_input_device.cc',
'winmmemidi_output_device.cc',
- 'win_utils.cc',
'midi_util.cc',
'mmcss.cc'
]