zenilib  0.5.3.0
 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 
104 {
106  return ALC_TRUE;
107 }
108 
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 = {
141  NULL,
142  NULL,
143  NULL,
144  NULL,
145  NULL,
146  NULL,
150 };
151 
153 {
154  *func_list = null_funcs;
155  return ALC_TRUE;
156 }
157 
158 void alc_null_deinit(void)
159 {
160 }
161 
163 {
164  switch(type)
165  {
166  case ALL_DEVICE_PROBE:
168  break;
170  break;
171  }
172 }
ALCboolean Connected
Definition: alMain.h:564
void ALvoid
Definition: al.h:74
static ALuint NullProc(ALvoid *ptr)
Definition: null.c:40
#define ALC_TRUE
Definition: alc.h:84
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
char * strdup(const char *inStr)
Definition: strdup.c:6
#define NULL
Definition: ftobjs.h:61
GLuint start
Definition: glew.h:1239
ALuint timeGetTime(void)
Definition: helpers.c:376
SDL_EventEntry * free
Definition: SDL_events.c:80
ALuint Frequency
Definition: alMain.h:569
ALCboolean alc_null_init(BackendFuncs *func_list)
Definition: null.c:152
ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size)
Definition: ALu.c:970
ALint64 ALCdevice_GetLatencyDefault(ALCdevice *device)
Definition: ALc.c:1285
#define calloc
Definition: SDL_malloc.c:636
char ALCchar
Definition: alc.h:42
#define Sleep(x)
Definition: allatency.c:34
static ALCboolean null_start_playback(ALCdevice *device)
Definition: null.c:109
void * ExtraData
Definition: alMain.h:630
#define ALC_FALSE
Definition: alc.h:81
ALuint StopThread(ALvoid *thread)
Definition: alcThread.c:131
void SetDefaultWFXChannelOrder(ALCdevice *device)
Definition: ALc.c:1295
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
static void null_close_playback(ALCdevice *device)
Definition: null.c:95
void alc_null_probe(enum DevProbe type)
Definition: null.c:162
void alc_null_deinit(void)
Definition: null.c:158
unsigned int ALuint
Definition: al.h:59
static SDL_Thread * thread
#define ALC_NO_ERROR
Definition: alc.h:102
void ALCdevice_LockDefault(ALCdevice *device)
Definition: ALc.c:1277
char ALCboolean
Definition: alc.h:39
ALuint UpdateSize
Definition: alMain.h:570
static const BackendFuncs null_funcs
Definition: null.c:135
ALCchar * DeviceName
Definition: alMain.h:575
#define ALC_INVALID_VALUE
Definition: alc.h:114
static void null_stop_playback(ALCdevice *device)
Definition: null.c:120
static ALCboolean null_reset_playback(ALCdevice *device)
Definition: null.c:103
int ALCenum
Definition: alc.h:66
static ALCenum null_open_playback(ALCdevice *device, const ALCchar *deviceName)
Definition: null.c:79
void ALCdevice_UnlockDefault(ALCdevice *device)
Definition: ALc.c:1281
static const ALCchar nullDevice[]
Definition: null.c:38
void AppendAllDevicesList(const ALCchar *name)
ALvoid * StartThread(ALuint(*func)(ALvoid *), ALvoid *ptr)
Definition: alcThread.c:100
DevProbe
Definition: alMain.h:383