Mercurial > audio-send
comparison Alc/backends/null.c @ 0:f9476ff7637e
initial forking of open-al to create multiple listeners
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 25 Oct 2011 13:02:31 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f9476ff7637e |
---|---|
1 /** | |
2 * OpenAL cross platform audio library | |
3 * Copyright (C) 2010 by Chris Robinson | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Library General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Library General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Library General Public | |
15 * License along with this library; if not, write to the | |
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
17 * Boston, MA 02111-1307, USA. | |
18 * Or go to http://www.gnu.org/copyleft/lgpl.html | |
19 */ | |
20 | |
21 #include "config.h" | |
22 | |
23 #include <stdlib.h> | |
24 #include "alMain.h" | |
25 #include "AL/al.h" | |
26 #include "AL/alc.h" | |
27 | |
28 | |
29 typedef struct { | |
30 volatile int killNow; | |
31 ALvoid *thread; | |
32 } null_data; | |
33 | |
34 | |
35 static const ALCchar nullDevice[] = "No Output"; | |
36 | |
37 static ALuint NullProc(ALvoid *ptr) | |
38 { | |
39 ALCdevice *Device = (ALCdevice*)ptr; | |
40 null_data *data = (null_data*)Device->ExtraData; | |
41 ALuint now, start; | |
42 ALuint64 avail, done; | |
43 const ALuint restTime = (ALuint64)Device->UpdateSize * 1000 / | |
44 Device->Frequency / 2; | |
45 | |
46 done = 0; | |
47 start = timeGetTime(); | |
48 while(!data->killNow && Device->Connected) | |
49 { | |
50 now = timeGetTime(); | |
51 | |
52 avail = (ALuint64)(now-start) * Device->Frequency / 1000; | |
53 if(avail < done) | |
54 { | |
55 /* Timer wrapped. Add the remainder of the cycle to the available | |
56 * count and reset the number of samples done */ | |
57 avail += (ALuint64)0xFFFFFFFFu*Device->Frequency/1000 - done; | |
58 done = 0; | |
59 } | |
60 if(avail-done < Device->UpdateSize) | |
61 { | |
62 Sleep(restTime); | |
63 continue; | |
64 } | |
65 | |
66 while(avail-done >= Device->UpdateSize) | |
67 { | |
68 aluMixData(Device, NULL, Device->UpdateSize); | |
69 done += Device->UpdateSize; | |
70 } | |
71 } | |
72 | |
73 return 0; | |
74 } | |
75 | |
76 static ALCboolean null_open_playback(ALCdevice *device, const ALCchar *deviceName) | |
77 { | |
78 null_data *data; | |
79 | |
80 if(!deviceName) | |
81 deviceName = nullDevice; | |
82 else if(strcmp(deviceName, nullDevice) != 0) | |
83 return ALC_FALSE; | |
84 | |
85 data = (null_data*)calloc(1, sizeof(*data)); | |
86 | |
87 device->szDeviceName = strdup(deviceName); | |
88 device->ExtraData = data; | |
89 return ALC_TRUE; | |
90 } | |
91 | |
92 static void null_close_playback(ALCdevice *device) | |
93 { | |
94 null_data *data = (null_data*)device->ExtraData; | |
95 | |
96 free(data); | |
97 device->ExtraData = NULL; | |
98 } | |
99 | |
100 static ALCboolean null_reset_playback(ALCdevice *device) | |
101 { | |
102 null_data *data = (null_data*)device->ExtraData; | |
103 | |
104 SetDefaultWFXChannelOrder(device); | |
105 | |
106 data->thread = StartThread(NullProc, device); | |
107 if(data->thread == NULL) | |
108 return ALC_FALSE; | |
109 | |
110 return ALC_TRUE; | |
111 } | |
112 | |
113 static void null_stop_playback(ALCdevice *device) | |
114 { | |
115 null_data *data = (null_data*)device->ExtraData; | |
116 | |
117 if(!data->thread) | |
118 return; | |
119 | |
120 data->killNow = 1; | |
121 StopThread(data->thread); | |
122 data->thread = NULL; | |
123 | |
124 data->killNow = 0; | |
125 } | |
126 | |
127 | |
128 static const BackendFuncs null_funcs = { | |
129 null_open_playback, | |
130 null_close_playback, | |
131 null_reset_playback, | |
132 null_stop_playback, | |
133 NULL, | |
134 NULL, | |
135 NULL, | |
136 NULL, | |
137 NULL, | |
138 NULL | |
139 }; | |
140 | |
141 ALCboolean alc_null_init(BackendFuncs *func_list) | |
142 { | |
143 *func_list = null_funcs; | |
144 return ALC_TRUE; | |
145 } | |
146 | |
147 void alc_null_deinit(void) | |
148 { | |
149 } | |
150 | |
151 void alc_null_probe(enum DevProbe type) | |
152 { | |
153 switch(type) | |
154 { | |
155 case DEVICE_PROBE: | |
156 AppendDeviceList(nullDevice); | |
157 break; | |
158 case ALL_DEVICE_PROBE: | |
159 AppendAllDeviceList(nullDevice); | |
160 break; | |
161 case CAPTURE_DEVICE_PROBE: | |
162 break; | |
163 } | |
164 } |