summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/portmidi/porttime
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/portmidi/porttime')
-rw-r--r--3rdparty/portmidi/porttime/porttime-VC8.vcproj225
-rw-r--r--3rdparty/portmidi/porttime/porttime.dsp104
-rw-r--r--3rdparty/portmidi/porttime/porttime.h58
-rw-r--r--3rdparty/portmidi/porttime/porttime.vcproj184
-rw-r--r--3rdparty/portmidi/porttime/pthaiku.cpp88
-rw-r--r--3rdparty/portmidi/porttime/ptlinux.c26
-rw-r--r--3rdparty/portmidi/porttime/ptmacosx_cf.c6
-rw-r--r--3rdparty/portmidi/porttime/ptmacosx_mach.c103
-rw-r--r--3rdparty/portmidi/porttime/ptwinmm.c6
9 files changed, 227 insertions, 573 deletions
diff --git a/3rdparty/portmidi/porttime/porttime-VC8.vcproj b/3rdparty/portmidi/porttime/porttime-VC8.vcproj
deleted file mode 100644
index 9a4562495b2..00000000000
--- a/3rdparty/portmidi/porttime/porttime-VC8.vcproj
+++ /dev/null
@@ -1,225 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="8.00"
- Name="porttime"
- ProjectGUID="{338224B8-D575-408D-BACF-95C557B429BE}"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Release|Win32"
- OutputDirectory=".\Release"
- IntermediateDirectory=".\Release"
- ConfigurationType="4"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
- StringPooling="true"
- RuntimeLibrary="0"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile=".\Release/porttime.pch"
- AssemblerListingLocation=".\Release/"
- ObjectFile=".\Release/"
- ProgramDataBaseFileName=".\Release/"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- OutputFile=".\Release\porttime.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- SuppressStartupBanner="true"
- OutputFile=".\Release/porttime.bsc"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory=".\Debug"
- IntermediateDirectory=".\Debug"
- ConfigurationType="4"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- PreprocessorDefinitions="_LIB;WIN32;_DEBUG"
- MinimalRebuild="true"
- BasicRuntimeChecks="3"
- RuntimeLibrary="1"
- PrecompiledHeaderFile=".\Debug/porttime.pch"
- AssemblerListingLocation=".\Debug/"
- ObjectFile=".\Debug/"
- ProgramDataBaseFileName=".\Debug/"
- WarningLevel="3"
- SuppressStartupBanner="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- OutputFile=".\Debug\porttime.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- SuppressStartupBanner="true"
- OutputFile=".\Debug/porttime.bsc"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <Filter
- Name="Source Files"
- Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
- >
- <File
- RelativePath="porttime.c"
- >
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- PreprocessorDefinitions=""
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- PreprocessorDefinitions=""
- />
- </FileConfiguration>
- </File>
- <File
- RelativePath="ptwinmm.c"
- >
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- PreprocessorDefinitions=""
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Debug|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- PreprocessorDefinitions=""
- />
- </FileConfiguration>
- </File>
- </Filter>
- <Filter
- Name="Header Files"
- Filter="h;hpp;hxx;hm;inl"
- >
- <File
- RelativePath="porttime.h"
- >
- </File>
- </Filter>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/3rdparty/portmidi/porttime/porttime.dsp b/3rdparty/portmidi/porttime/porttime.dsp
deleted file mode 100644
index 2771842af31..00000000000
--- a/3rdparty/portmidi/porttime/porttime.dsp
+++ /dev/null
@@ -1,104 +0,0 @@
-# Microsoft Developer Studio Project File - Name="porttime" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Static Library" 0x0104
-
-CFG=porttime - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "porttime.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "porttime.mak" CFG="porttime - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "porttime - Win32 Release" (based on "Win32 (x86) Static Library")
-!MESSAGE "porttime - Win32 Debug" (based on "Win32 (x86) Static Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "porttime - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF "$(CFG)" == "porttime - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "_LIB" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "USE_DLL_FOR_CLEANUP" /YX /FD /GZ /c
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ENDIF
-
-# Begin Target
-
-# Name "porttime - Win32 Release"
-# Name "porttime - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\porttime.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ptwinmm.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\porttime.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/3rdparty/portmidi/porttime/porttime.h b/3rdparty/portmidi/porttime/porttime.h
index f5ffd5c1f49..29d93dc2c59 100644
--- a/3rdparty/portmidi/porttime/porttime.h
+++ b/3rdparty/portmidi/porttime/porttime.h
@@ -1,4 +1,4 @@
-/* porttime.h -- portable interface to millisecond timer */
+/** @file porttime.h portable interface to millisecond timer. */
/* CHANGE LOG FOR PORTTIME
10-Jun-03 Mark Nelson & RBD
@@ -25,8 +25,16 @@ extern "C" {
#endif
#ifndef PMEXPORT
+#ifdef _WINDLL
+#define PMEXPORT __declspec(dllexport)
+#else
#define PMEXPORT
#endif
+#endif
+
+/** @defgroup grp_porttime PortTime: Millisecond Timer
+ @{
+*/
typedef enum {
ptNoError = 0, /* success */
@@ -34,55 +42,57 @@ typedef enum {
ptAlreadyStarted, /* cannot start timer because it is already started */
ptAlreadyStopped, /* cannot stop timer because it is already stopped */
ptInsufficientMemory /* memory could not be allocated */
-} PtError;
-
+} PtError; /**< @brief @enum PtError PortTime error code; a common return type.
+ * No error is indicated by zero; errors are indicated by < 0.
+ */
+/** real time or time offset in milliseconds. */
typedef int32_t PtTimestamp;
-typedef void (PtCallback)( PtTimestamp timestamp, void *userData );
+/** a function that gets a current time */
+typedef void (PtCallback)(PtTimestamp timestamp, void *userData);
-/*
- Pt_Start() starts a real-time service.
+/** start a real-time clock service.
- resolution is the timer resolution in ms. The time will advance every
- resolution ms.
+ @param resolution the timer resolution in ms. The time will advance every
+ \p resolution ms.
- callback is a function pointer to be called every resolution ms.
+ @param callback a function pointer to be called every resolution ms.
- userData is passed to callback as a parameter.
+ @param userData is passed to \p callback as a parameter.
- return value:
- Upon success, returns ptNoError. See PtError for other values.
+ @return #ptNoError on success. See #PtError for other values.
*/
PMEXPORT PtError Pt_Start(int resolution, PtCallback *callback, void *userData);
-/*
- Pt_Stop() stops the timer.
+/** stop the timer.
- return value:
- Upon success, returns ptNoError. See PtError for other values.
+ @return #ptNoError on success. See #PtError for other values.
*/
PMEXPORT PtError Pt_Stop(void);
-/*
- Pt_Started() returns true iff the timer is running.
+/** test if the timer is running.
+
+ @return TRUE or FALSE
*/
PMEXPORT int Pt_Started(void);
-/*
- Pt_Time() returns the current time in ms.
+/** get the current time in ms.
+
+ @return the current time
*/
PMEXPORT PtTimestamp Pt_Time(void);
-/*
- Pt_Sleep() pauses, allowing other threads to run.
+/** pauses the current thread, allowing other threads to run.
- duration is the length of the pause in ms. The true duration
+ @param duration the length of the pause in ms. The true duration
of the pause may be rounded to the nearest or next clock tick
- as determined by resolution in Pt_Start().
+ as determined by resolution in #Pt_Start().
*/
PMEXPORT void Pt_Sleep(int32_t duration);
+/** @} */
+
#ifdef __cplusplus
}
#endif
diff --git a/3rdparty/portmidi/porttime/porttime.vcproj b/3rdparty/portmidi/porttime/porttime.vcproj
deleted file mode 100644
index a386cce6257..00000000000
--- a/3rdparty/portmidi/porttime/porttime.vcproj
+++ /dev/null
@@ -1,184 +0,0 @@
-<?xml version="1.0" encoding="Windows-1252"?>
-<VisualStudioProject
- ProjectType="Visual C++"
- Version="9.00"
- Name="PortTime"
- ProjectGUID="{338224B8-D575-408D-BACF-95C557B429BE}"
- TargetFrameworkVersion="131072"
- >
- <Platforms>
- <Platform
- Name="Win32"
- />
- </Platforms>
- <ToolFiles>
- </ToolFiles>
- <Configurations>
- <Configuration
- Name="Release|Win32"
- OutputDirectory="$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="4"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="2"
- InlineFunctionExpansion="1"
- PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
- StringPooling="true"
- RuntimeLibrary="0"
- EnableFunctionLevelLinking="true"
- PrecompiledHeaderFile=".\$(OutDir)\porttime.pch"
- AssemblerListingLocation=".\$(OutDir)\"
- ObjectFile=".\$(OutDir)\"
- ProgramDataBaseFileName=".\$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- OutputFile=".\$(OutDir)\porttime.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- SuppressStartupBanner="true"
- OutputFile=".\$(OutDir)\porttime.bsc"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- <Configuration
- Name="Debug|Win32"
- OutputDirectory="$(ConfigurationName)"
- IntermediateDirectory="$(ConfigurationName)"
- ConfigurationType="4"
- InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
- UseOfMFC="0"
- ATLMinimizesCRunTimeLibraryUsage="false"
- CharacterSet="2"
- >
- <Tool
- Name="VCPreBuildEventTool"
- />
- <Tool
- Name="VCCustomBuildTool"
- />
- <Tool
- Name="VCXMLDataGeneratorTool"
- />
- <Tool
- Name="VCWebServiceProxyGeneratorTool"
- />
- <Tool
- Name="VCMIDLTool"
- />
- <Tool
- Name="VCCLCompilerTool"
- Optimization="0"
- PreprocessorDefinitions="_LIB;WIN32;_DEBUG"
- MinimalRebuild="true"
- BasicRuntimeChecks="3"
- RuntimeLibrary="3"
- PrecompiledHeaderFile=".\$(OutDir)\porttime.pch"
- AssemblerListingLocation=".\$(OutDir)\"
- ObjectFile=".\$(OutDir)\"
- ProgramDataBaseFileName=".\$(OutDir)\"
- WarningLevel="3"
- SuppressStartupBanner="true"
- DebugInformationFormat="3"
- />
- <Tool
- Name="VCManagedResourceCompilerTool"
- />
- <Tool
- Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
- Culture="1033"
- />
- <Tool
- Name="VCPreLinkEventTool"
- />
- <Tool
- Name="VCLibrarianTool"
- OutputFile=".\$(OutDir)\porttime.lib"
- SuppressStartupBanner="true"
- />
- <Tool
- Name="VCALinkTool"
- />
- <Tool
- Name="VCXDCMakeTool"
- />
- <Tool
- Name="VCBscMakeTool"
- SuppressStartupBanner="true"
- OutputFile=".\$(OutDir)\porttime.bsc"
- />
- <Tool
- Name="VCFxCopTool"
- />
- <Tool
- Name="VCPostBuildEventTool"
- />
- </Configuration>
- </Configurations>
- <References>
- </References>
- <Files>
- <File
- RelativePath=".\porttime.c"
- >
- </File>
- <File
- RelativePath=".\porttime.h"
- >
- </File>
- <File
- RelativePath=".\ptwinmm.c"
- >
- </File>
- </Files>
- <Globals>
- </Globals>
-</VisualStudioProject>
diff --git a/3rdparty/portmidi/porttime/pthaiku.cpp b/3rdparty/portmidi/porttime/pthaiku.cpp
new file mode 100644
index 00000000000..9d8de14fd3d
--- /dev/null
+++ b/3rdparty/portmidi/porttime/pthaiku.cpp
@@ -0,0 +1,88 @@
+// pthaiku.cpp - portable timer implementation for Haiku
+
+#include "porttime.h"
+#include <Looper.h>
+#include <MessageRunner.h>
+#include <OS.h>
+
+namespace {
+ const uint32 timerMessage = 'PTTM';
+
+ struct TimerLooper : BLooper {
+ TimerLooper() : BLooper() {
+ }
+
+
+ virtual void MessageReceived(BMessage *message)
+ {
+ PtCallback *callback;
+ void *userData;
+ if (message->what == timerMessage && message->FindPointer("callback", (void**)&callback) == B_OK && message->FindPointer("userData", &userData) == B_OK) {
+ (*callback)(Pt_Time(), userData);
+ }
+ BLooper::MessageReceived(message);
+ }
+ };
+
+ bool time_started_flag = false;
+ bigtime_t time_offset;
+ TimerLooper *timerLooper;
+ BMessageRunner *timerRunner;
+}
+
+extern "C" {
+ PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
+ {
+ if (time_started_flag) return ptAlreadyStarted;
+ time_offset = system_time();
+ if (callback) {
+ timerLooper = new TimerLooper;
+ timerLooper->Run();
+ BMessenger target(timerLooper);
+ BMessage message(timerMessage);
+ message.AddPointer("callback", (void*)callback);
+ message.AddPointer("userData", userData);
+ bigtime_t interval = resolution * 1000;
+ timerRunner = new BMessageRunner(target, &message, interval);
+ if(timerRunner->InitCheck() != B_OK) {
+ delete timerRunner;
+ timerRunner = NULL;
+ timerLooper->PostMessage(B_QUIT_REQUESTED);
+ timerLooper = NULL;
+ return ptHostError;
+ }
+ }
+ time_started_flag = true;
+ return ptNoError;
+ }
+
+
+ PtError Pt_Stop()
+ {
+ if (!time_started_flag) return ptAlreadyStopped;
+ time_started_flag = false;
+ delete timerRunner;
+ timerRunner = NULL;
+ timerLooper->PostMessage(B_QUIT_REQUESTED);
+ timerLooper = NULL;
+ return ptNoError;
+ }
+
+
+ int Pt_Started()
+ {
+ return time_started_flag;
+ }
+
+
+ PtTimestamp Pt_Time()
+ {
+ return (system_time() - time_offset) / 1000;
+ }
+
+
+ void Pt_Sleep(int32_t duration)
+ {
+ snooze(duration * 1000);
+ }
+}
diff --git a/3rdparty/portmidi/porttime/ptlinux.c b/3rdparty/portmidi/porttime/ptlinux.c
index c58107c36ad..7302e212311 100644
--- a/3rdparty/portmidi/porttime/ptlinux.c
+++ b/3rdparty/portmidi/porttime/ptlinux.c
@@ -29,7 +29,7 @@ CHANGE LOG
#include <unistd.h>
#include <sys/types.h>
#include "porttime.h"
-#include "sys/time.h"
+#include "time.h"
#include "sys/resource.h"
#include "sys/timeb.h"
#include "pthread.h"
@@ -38,7 +38,7 @@ CHANGE LOG
#define FALSE 0
static int time_started_flag = FALSE;
-static struct timeval time_offset = {0, 0};
+static struct timespec time_offset = {0, 0};
static pthread_t pt_thread_pid;
static int pt_thread_created = FALSE;
@@ -79,7 +79,8 @@ static void *Pt_CallbackProc(void *p)
PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
{
if (time_started_flag) return ptNoError;
- gettimeofday(&time_offset, NULL); /* need this set before process runs */
+ /* need this set before process runs: */
+ clock_gettime(CLOCK_MONOTONIC_RAW, &time_offset);
if (callback) {
int res;
pt_callback_parameters *parms = (pt_callback_parameters *)
@@ -99,7 +100,7 @@ PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
}
-PtError Pt_Stop()
+PtError Pt_Stop(void)
{
/* printf("Pt_Stop called\n"); */
pt_callback_proc_id++;
@@ -112,20 +113,20 @@ PtError Pt_Stop()
}
-int Pt_Started()
+int Pt_Started(void)
{
return time_started_flag;
}
-PtTimestamp Pt_Time()
+PtTimestamp Pt_Time(void)
{
- long seconds, milliseconds;
- struct timeval now;
- gettimeofday(&now, NULL);
+ long seconds, ms;
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC_RAW, &now);
seconds = now.tv_sec - time_offset.tv_sec;
- milliseconds = now.tv_usec - time_offset.tv_usec;
- return seconds * 1000 + milliseconds;
+ ms = (now.tv_nsec - time_offset.tv_nsec) / 1000000; /* round down */
+ return seconds * 1000 + ms;
}
@@ -133,6 +134,3 @@ void Pt_Sleep(int32_t duration)
{
usleep(duration * 1000);
}
-
-
-
diff --git a/3rdparty/portmidi/porttime/ptmacosx_cf.c b/3rdparty/portmidi/porttime/ptmacosx_cf.c
index 3eb0de12f82..1bc9658d216 100644
--- a/3rdparty/portmidi/porttime/ptmacosx_cf.c
+++ b/3rdparty/portmidi/porttime/ptmacosx_cf.c
@@ -111,7 +111,7 @@ PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
}
-PtError Pt_Stop()
+PtError Pt_Stop(void)
{
printf("Pt_Stop called\n");
@@ -121,13 +121,13 @@ PtError Pt_Stop()
}
-int Pt_Started()
+int Pt_Started(void)
{
return time_started_flag;
}
-PtTimestamp Pt_Time()
+PtTimestamp Pt_Time(void)
{
CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
return (PtTimestamp) ((now - startTime) * 1000.0);
diff --git a/3rdparty/portmidi/porttime/ptmacosx_mach.c b/3rdparty/portmidi/porttime/ptmacosx_mach.c
index f4fec09d4c4..bc6a1a01084 100644
--- a/3rdparty/portmidi/porttime/ptmacosx_mach.c
+++ b/3rdparty/portmidi/porttime/ptmacosx_mach.c
@@ -4,20 +4,29 @@
#include <stdio.h>
#include <CoreAudio/HostTime.h>
-#include <mach/mach.h>
-#include <mach/mach_error.h>
-#include <mach/mach_time.h>
-#include <mach/clock.h>
+#import <mach/mach.h>
+#import <mach/mach_error.h>
+#import <mach/mach_time.h>
+#import <mach/clock.h>
#include <unistd.h>
+#include <AvailabilityMacros.h>
#include "porttime.h"
#include "sys/time.h"
#include "pthread.h"
-#if !defined NSEC_PER_MSEC
-#define NSEC_PER_MSEC 1000000ull
+#ifndef NSEC_PER_MSEC
+#define NSEC_PER_MSEC 1000000
+#endif
+#define THREAD_IMPORTANCE 63
+
+// QOS headers are available as of macOS 10.10
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
+#include "sys/qos.h"
+#define HAVE_APPLE_QOS 1
+#else
+#undef HAVE_APPLE_QOS
#endif
-#define THREAD_IMPORTANCE 30
static int time_started_flag = FALSE;
static UInt64 start_time;
@@ -47,7 +56,7 @@ static void *Pt_CallbackProc(void *p)
(thread_policy_t)&extendedPolicy,
THREAD_EXTENDED_POLICY_COUNT);
if (error != KERN_SUCCESS) {
- mach_error((char *)"Couldn't set thread timeshare policy", error);
+ mach_error("Couldn't set thread timeshare policy", error);
}
precedencePolicy.importance = THREAD_IMPORTANCE;
@@ -55,22 +64,65 @@ static void *Pt_CallbackProc(void *p)
(thread_policy_t)&precedencePolicy,
THREAD_PRECEDENCE_POLICY_COUNT);
if (error != KERN_SUCCESS) {
- mach_error((char *)"Couldn't set thread precedence policy", error);
+ mach_error("Couldn't set thread precedence policy", error);
}
+ // Most important, set real-time constraints.
+
+ // Define the guaranteed and max fraction of time for the audio thread.
+ // These "duty cycle" values can range from 0 to 1. A value of 0.5
+ // means the scheduler would give half the time to the thread.
+ // These values have empirically been found to yield good behavior.
+ // Good means that audio performance is high and other threads won't starve.
+ const double kGuaranteedAudioDutyCycle = 0.75;
+ const double kMaxAudioDutyCycle = 0.85;
+
+ // Define constants determining how much time the audio thread can
+ // use in a given time quantum. All times are in milliseconds.
+
+ // About 128 frames @44.1KHz
+ const double kTimeQuantum = 2.9;
+
+ // Time guaranteed each quantum.
+ const double kAudioTimeNeeded = kGuaranteedAudioDutyCycle * kTimeQuantum;
+
+ // Maximum time each quantum.
+ const double kMaxTimeAllowed = kMaxAudioDutyCycle * kTimeQuantum;
+ // Get the conversion factor from milliseconds to absolute time
+ // which is what the time-constraints call needs.
+ mach_timebase_info_data_t tb_info;
+ mach_timebase_info(&tb_info);
+ double ms_to_abs_time =
+ ((double)tb_info.denom / (double)tb_info.numer) * 1000000;
+
+ thread_time_constraint_policy_data_t time_constraints;
+ time_constraints.period = (uint32_t)(kTimeQuantum * ms_to_abs_time);
+ time_constraints.computation = (uint32_t)(kAudioTimeNeeded * ms_to_abs_time);
+ time_constraints.constraint = (uint32_t)(kMaxTimeAllowed * ms_to_abs_time);
+ time_constraints.preemptible = 0;
+
+ error = thread_policy_set(mach_thread_self(),
+ THREAD_TIME_CONSTRAINT_POLICY,
+ (thread_policy_t)&time_constraints,
+ THREAD_TIME_CONSTRAINT_POLICY_COUNT);
+ if (error != KERN_SUCCESS) {
+ mach_error("Couldn't set thread precedence policy", error);
+ }
+
/* to kill a process, just increment the pt_callback_proc_id */
- /* printf("pt_callback_proc_id %d, id %d\n", pt_callback_proc_id, parameters->id); */
+ /* printf("pt_callback_proc_id %d, id %d\n", pt_callback_proc_id,
+ parameters->id); */
while (pt_callback_proc_id == parameters->id) {
/* wait for a multiple of resolution ms */
UInt64 wait_time;
int delay = mytime++ * parameters->resolution - Pt_Time();
- PtTimestamp timestamp;
+ PtTimestamp timestamp;
if (delay < 0) delay = 0;
wait_time = AudioConvertNanosToHostTime((UInt64)delay * NSEC_PER_MSEC);
wait_time += AudioGetCurrentHostTime();
- error = mach_wait_until(wait_time);
- timestamp = Pt_Time();
+ mach_wait_until(wait_time);
+ timestamp = Pt_Time();
(*(parameters->callback))(timestamp, parameters->userData);
}
free(parameters);
@@ -93,7 +145,26 @@ PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
parms->resolution = resolution;
parms->callback = callback;
parms->userData = userData;
+
+#ifdef HAVE_APPLE_QOS
+ pthread_attr_t qosAttribute;
+ pthread_attr_init(&qosAttribute);
+ pthread_attr_set_qos_class_np(&qosAttribute,
+ QOS_CLASS_USER_INTERACTIVE, 0);
+
+ res = pthread_create(&pt_thread_pid, &qosAttribute, Pt_CallbackProc,
+ parms);
+#else
res = pthread_create(&pt_thread_pid, NULL, Pt_CallbackProc, parms);
+#endif
+
+ struct sched_param sp;
+ memset(&sp, 0, sizeof(struct sched_param));
+ sp.sched_priority = sched_get_priority_max(SCHED_RR);
+ if (pthread_setschedparam(pthread_self(), SCHED_RR, &sp) == -1) {
+ return ptHostError;
+ }
+
if (res != 0) return ptHostError;
}
@@ -102,7 +173,7 @@ PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
}
-PtError Pt_Stop()
+PtError Pt_Stop(void)
{
/* printf("Pt_Stop called\n"); */
pt_callback_proc_id++;
@@ -112,13 +183,13 @@ PtError Pt_Stop()
}
-int Pt_Started()
+int Pt_Started(void)
{
return time_started_flag;
}
-PtTimestamp Pt_Time()
+PtTimestamp Pt_Time(void)
{
UInt64 clock_time, nsec_time;
clock_time = AudioGetCurrentHostTime() - start_time;
diff --git a/3rdparty/portmidi/porttime/ptwinmm.c b/3rdparty/portmidi/porttime/ptwinmm.c
index 17675bd6c6a..05f5c74eea3 100644
--- a/3rdparty/portmidi/porttime/ptwinmm.c
+++ b/3rdparty/portmidi/porttime/ptwinmm.c
@@ -38,7 +38,7 @@ PMEXPORT PtError Pt_Start(int resolution, PtCallback *callback, void *userData)
}
-PMEXPORT PtError Pt_Stop()
+PMEXPORT PtError Pt_Stop(void)
{
if (!time_started_flag) return ptAlreadyStopped;
if (time_callback && timer_id) {
@@ -52,13 +52,13 @@ PMEXPORT PtError Pt_Stop()
}
-PMEXPORT int Pt_Started()
+PMEXPORT int Pt_Started(void)
{
return time_started_flag;
}
-PMEXPORT PtTimestamp Pt_Time()
+PMEXPORT PtTimestamp Pt_Time(void)
{
return timeGetTime() - time_offset;
}