Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/windows/native/libjsound/PLATFORM_API_WinOS_Util.c
41149 views
1
/*
2
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
27
#define USE_ERROR
28
//#define USE_TRACE
29
30
#include "PLATFORM_API_WinOS_Util.h"
31
32
#if (USE_PLATFORM_MIDI_IN == TRUE) || (USE_PLATFORM_MIDI_OUT == TRUE)
33
34
/* set the startTime field in MidiDeviceHandle */
35
void MIDI_SetStartTime(MidiDeviceHandle* handle) {
36
if (handle != NULL) {
37
handle->startTime = (INT64) timeGetTime();
38
}
39
}
40
41
42
/* return time stamp in microseconds */
43
INT64 MIDI_GetTimeStamp(MidiDeviceHandle* handle) {
44
INT64 res;
45
if (handle == NULL) {
46
return (INT64) -1;
47
}
48
res = ((INT64) timeGetTime()) - handle->startTime;
49
if (res < 0) {
50
res *= (INT64) -1000;
51
} else {
52
res *= (INT64) 1000;
53
}
54
return res;
55
}
56
57
58
void* MIDI_CreateLock() {
59
CRITICAL_SECTION* lock = (CRITICAL_SECTION*) malloc(sizeof(CRITICAL_SECTION));
60
InitializeCriticalSection(lock);
61
TRACE0("MIDI_CreateLock\n");
62
return lock;
63
}
64
65
void MIDI_DestroyLock(void* lock) {
66
if (lock) {
67
DeleteCriticalSection((CRITICAL_SECTION*) lock);
68
free(lock);
69
TRACE0("MIDI_DestroyLock\n");
70
}
71
}
72
73
void MIDI_Lock(void* lock) {
74
if (lock) {
75
EnterCriticalSection((CRITICAL_SECTION*) lock);
76
}
77
}
78
79
void MIDI_Unlock(void* lock) {
80
if (lock) {
81
LeaveCriticalSection((CRITICAL_SECTION*) lock);
82
}
83
}
84
int MIDI_WinCreateEmptyLongBufferQueue(MidiDeviceHandle* handle, int count) {
85
return MIDI_WinCreateLongBufferQueue(handle, count, 0, NULL);
86
}
87
88
int MIDI_WinCreateLongBufferQueue(MidiDeviceHandle* handle, int count, int size, UBYTE* preAllocatedMem) {
89
SysExQueue* sysex;
90
int i;
91
UBYTE* dataPtr;
92
int structSize = sizeof(SysExQueue) + ((count - 1) * sizeof(MIDIHDR));
93
94
sysex = (SysExQueue*) malloc(structSize);
95
if (!sysex) return FALSE;
96
memset(sysex, 0, structSize);
97
sysex->count = count;
98
sysex->size = size;
99
100
// prepare memory block which will contain the actual data
101
if (!preAllocatedMem && size > 0) {
102
preAllocatedMem = (UBYTE*) malloc(count*size);
103
if (!preAllocatedMem) {
104
free(sysex);
105
return FALSE;
106
}
107
sysex->ownsLinearMem = 1;
108
}
109
sysex->linearMem = preAllocatedMem;
110
handle->longBuffers = sysex;
111
112
// set up headers
113
dataPtr = preAllocatedMem;
114
for (i=0; i<count; i++) {
115
sysex->header[i].lpData = dataPtr;
116
sysex->header[i].dwBufferLength = size;
117
// user data is the index of the buffer
118
sysex->header[i].dwUser = (DWORD) i;
119
dataPtr += size;
120
}
121
return TRUE;
122
}
123
124
void MIDI_WinDestroyLongBufferQueue(MidiDeviceHandle* handle) {
125
SysExQueue* sysex = (SysExQueue*) handle->longBuffers;
126
if (sysex) {
127
handle->longBuffers = NULL;
128
if (sysex->ownsLinearMem && sysex->linearMem) {
129
free(sysex->linearMem);
130
}
131
free(sysex);
132
}
133
}
134
135
#endif // USE_PLATFORM_MIDI_IN || USE_PLATFORM_MIDI_OUT
136
137