zenilib: zenilib/jni/external/openal-soft/Alc/backends/null.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
null.c
Go to the documentation of this file.
1
21 #include "config.h"
22
23 #include <stdlib.h>
24 #ifdef HAVE_WINDOWS_H
25 #include <windows.h>
26 #endif
27
28 #include "alMain.h"
29 #include "alu.h"
30
31
32 typedef struct {
33 volatile int killNow;
34 ALvoid *thread;
35 } null_data;
36
37
38 static const ALCchar nullDevice[] = "No Output";
39
40 static ALuint NullProc(ALvoid *ptr)
41 {
42 ALCdevice *Device = (ALCdevice*)ptr;
43 null_data *data = (null_data*)Device->ExtraData;
44 ALuint now, start;
45 ALuint64 avail, done;
46 const ALuint restTime = (ALuint64)Device->UpdateSize * 1000 /
47 Device->Frequency / 2;
48
49 done = 0;
50 start = timeGetTime();
51 while(!data->killNow && Device->Connected)
52 {
53 now = timeGetTime();
54
55 avail = (ALuint64)(now-start) * Device->Frequency / 1000;
56 if(avail < done)
57 {
58 /* Timer wrapped (50 days???). Add the remainder of the cycle to
59 * the available count and reset the number of samples done */
60 avail += ((ALuint64)1<<32)*Device->Frequency/1000 - done;
61 done = 0;
62 }
63 if(avail-done < Device->UpdateSize)
64 {
65 Sleep(restTime);
66 continue;
67 }
68
69 while(avail-done >= Device->UpdateSize)
70 {
71 aluMixData(Device, NULL, Device->UpdateSize);
72 done += Device->UpdateSize;
73 }
74 }
75
76 return 0;
77 }
78
79 static ALCenum null_open_playback(ALCdevice *device, const ALCchar *deviceName)
80 {
81 null_data *data;
82
83 if(!deviceName)
84 deviceName = nullDevice;
85 else if(strcmp(deviceName, nullDevice) != 0)
86 return ALC_INVALID_VALUE;
87
88 data = (null_data*)calloc(1, sizeof(*data));
89
90 device->DeviceName = strdup(deviceName);
91 device->ExtraData = data;
92 return ALC_NO_ERROR;
93 }
94
95 static void null_close_playback(ALCdevice *device)
96 {
97 null_data *data = (null_data*)device->ExtraData;
98
99 free(data);
100 device->ExtraData = NULL;
101 }
102
103 static ALCboolean null_reset_playback(ALCdevice *device)
104 {
105 SetDefaultWFXChannelOrder(device);
106 return ALC_TRUE;
107 }
108
109 static ALCboolean null_start_playback(ALCdevice *device)
110 {
111 null_data *data = (null_data*)device->ExtraData;
112
113 data->thread = StartThread(NullProc, device);
114 if(data->thread == NULL)
115 return ALC_FALSE;
116
117 return ALC_TRUE;
118 }
119
120 static void null_stop_playback(ALCdevice *device)
121 {
122 null_data *data = (null_data*)device->ExtraData;
123
124 if(!data->thread)
125 return;
126
127 data->killNow = 1;
128 StopThread(data->thread);
129 data->thread = NULL;
130
131 data->killNow = 0;
132 }
133
134
135 static const BackendFuncs null_funcs = {
136 null_open_playback,
137 null_close_playback,
138 null_reset_playback,
139 null_start_playback,
140 null_stop_playback,
141 NULL,
142 NULL,
143 NULL,
144 NULL,
145 NULL,
146 NULL,
147 ALCdevice_LockDefault,
148 ALCdevice_UnlockDefault,
149 ALCdevice_GetLatencyDefault
150 };
151
152 ALCboolean alc_null_init(BackendFuncs *func_list)
153 {
154 *func_list = null_funcs;
155 return ALC_TRUE;
156 }
157
158 void alc_null_deinit(void)
159 {
160 }
161
162 void alc_null_probe(enum DevProbe type)
163 {
164 switch(type)
165 {
166 case ALL_DEVICE_PROBE:
167 AppendAllDevicesList(nullDevice);
168 break;
169 case CAPTURE_DEVICE_PROBE:
170 break;
171 }
172 }
ALCdevice_struct::Connected
ALCboolean Connected
Definition: alMain.h:564
ALvoid
void ALvoid
Definition: al.h:74
NullProc
static ALuint NullProc(ALvoid *ptr)
Definition: null.c:40
ALC_TRUE
#define ALC_TRUE
Definition: alc.h:84
type
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
BackendFuncs
Definition: alMain.h:388
strdup
char * strdup(const char *inStr)
Definition: strdup.c:6
NULL
#define NULL
Definition: ftobjs.h:61
start
GLuint start
Definition: glew.h:1239
timeGetTime
ALuint timeGetTime(void)
Definition: helpers.c:376
alu.h
free
SDL_EventEntry * free
Definition: SDL_events.c:80
ALCdevice_struct::Frequency
ALuint Frequency
Definition: alMain.h:569
alc_null_init
ALCboolean alc_null_init(BackendFuncs *func_list)
Definition: null.c:152
ALCdevice_struct
Definition: alMain.h:560
aluMixData
ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
Definition: ALu.c:970
ALCdevice_GetLatencyDefault
ALint64 ALCdevice_GetLatencyDefault(ALCdevice *device)
Definition: ALc.c:1285
calloc
#define calloc
Definition: SDL_malloc.c:636
ALCchar
char ALCchar
Definition: alc.h:42
Sleep
#define Sleep(x)
Definition: allatency.c:34
null_start_playback
static ALCboolean null_start_playback(ALCdevice *device)
Definition: null.c:109
ALL_DEVICE_PROBE
Definition: alMain.h:384
ALCdevice_struct::ExtraData
void * ExtraData
Definition: alMain.h:630
ALC_FALSE
#define ALC_FALSE
Definition: alc.h:81
StopThread
ALuint StopThread(ALvoid *thread)
Definition: alcThread.c:131
SetDefaultWFXChannelOrder
void SetDefaultWFXChannelOrder(ALCdevice *device)
Definition: ALc.c:1295
alMain.h
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
null_close_playback
static void null_close_playback(ALCdevice *device)
Definition: null.c:95
alc_null_probe
void alc_null_probe(enum DevProbe type)
Definition: null.c:162
alc_null_deinit
void alc_null_deinit(void)
Definition: null.c:158
ALuint
unsigned int ALuint
Definition: al.h:59
thread
static SDL_Thread * thread
Definition: SDL_sysjoystick.c:41
CAPTURE_DEVICE_PROBE
Definition: alMain.h:385
ALC_NO_ERROR
#define ALC_NO_ERROR
Definition: alc.h:102
ALCdevice_LockDefault
void ALCdevice_LockDefault(ALCdevice *device)
Definition: ALc.c:1277
ALCboolean
char ALCboolean
Definition: alc.h:39
ALCdevice_struct::UpdateSize
ALuint UpdateSize
Definition: alMain.h:570
null_funcs
static const BackendFuncs null_funcs
Definition: null.c:135
ALCdevice_struct::DeviceName
ALCchar * DeviceName
Definition: alMain.h:575
ALC_INVALID_VALUE
#define ALC_INVALID_VALUE
Definition: alc.h:114
null_stop_playback
static void null_stop_playback(ALCdevice *device)
Definition: null.c:120
null_reset_playback
static ALCboolean null_reset_playback(ALCdevice *device)
Definition: null.c:103
ALCenum
int ALCenum
Definition: alc.h:66
null_open_playback
static ALCenum null_open_playback(ALCdevice *device, const ALCchar *deviceName)
Definition: null.c:79
ALCdevice_UnlockDefault
void ALCdevice_UnlockDefault(ALCdevice *device)
Definition: ALc.c:1281
nullDevice
static const ALCchar nullDevice[]
Definition: null.c:38
AppendAllDevicesList
void AppendAllDevicesList(const ALCchar *name)
StartThread
ALvoid * StartThread(ALuint(*func)(ALvoid *), ALvoid *ptr)
Definition: alcThread.c:100
DevProbe
DevProbe
Definition: alMain.h:383