-
Notifications
You must be signed in to change notification settings - Fork 7
/
base.sfx.soundmanager.freeaudio.c
executable file
·98 lines (61 loc) · 1.55 KB
/
base.sfx.soundmanager.freeaudio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <unistd.h>
#include <stddef.h> //definition of NULL
//forward declaration
int __startThread();
void __onAppExit();
//global vars
int threadID;
int updateStreamsEnabled = -1; //-1 = auto activate on registering a callback
int updateInterval = 500; //in ms
//definition and variable for callback
typedef int (*intCallback)(void);
intCallback updateStreamManagerCallback;
//register cleanup function
//this is called when the calling programme exits
atexit( __onAppExit );
// === FUNCTIONS ===
void __onAppExit() {
stopThread();
}
int stopThread() {
updateStreamsEnabled = 0;
return 1;
}
int startThread(){
updateStreamsEnabled = 1;
return __startThread();
};
int RegisterUpdateStreamManagerCallback ( intCallback callback ) {
updateStreamManagerCallback = callback;
if (updateStreamsEnabled == -1)
startThread();
return 1;
}
void *updateStreamManager(void *v) {
while(updateStreamsEnabled == 1) {
//call the blitzmax function which updates the streams buffers
if(updateStreamManagerCallback != NULL)
updateStreamManagerCallback();
//wait some milliseconds till next update
usleep(updateInterval * 1000);
}
return NULL;
}
// === WINDOWS THREADS ===
#ifdef _WIN32
#include <windows.h>
HANDLE thread;
int __startThread(){
thread = CreateThread(0, 0, updateStreamManager, NULL, 0, &threadID);
return 0;
};
// === POSIX THREADS ===
// Linux, Mac
#else
#include <pthread.h>
pthread_t thread;
int __startThread(){
threadID = pthread_create(&thread, NULL, updateStreamManager, NULL);
return 0;
};
#endif