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.
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.
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
41 static const ALCchar nullDevice
[] = "Null Output";
43 static ALuint
NullProc(ALvoid
*ptr
)
45 ALCdevice
*Device
= (ALCdevice
*)ptr
;
46 null_data
*data
= (null_data
*)Device
->ExtraData
;
49 const ALuint restTime
= (ALuint64
)Device
->UpdateSize
* 1000 /
50 Device
->Frequency
/ 2;
53 start
= data
->startTime
;
54 while(!data
->killNow
&& Device
->Connected
)
58 avail
= (ALuint64
)(now
-start
) * Device
->Frequency
/ 1000;
61 AL_PRINT("Timer wrapped\n");
62 aluHandleDisconnect(Device
);
65 if(avail
-done
< Device
->UpdateSize
)
71 while(avail
-done
>= Device
->UpdateSize
)
73 aluMixData(Device
, data
->buffer
, Device
->UpdateSize
);
74 done
+= Device
->UpdateSize
;
81 static ALCboolean
null_open_playback(ALCdevice
*device
, const ALCchar
*deviceName
)
86 deviceName
= nullDevice
;
87 else if(strcmp(deviceName
, nullDevice
) != 0)
90 data
= (null_data
*)calloc(1, sizeof(*data
));
92 device
->szDeviceName
= strdup(deviceName
);
93 device
->ExtraData
= data
;
97 static void null_close_playback(ALCdevice
*device
)
99 null_data
*data
= (null_data
*)device
->ExtraData
;
102 device
->ExtraData
= NULL
;
105 static ALCboolean
null_reset_playback(ALCdevice
*device
)
107 null_data
*data
= (null_data
*)device
->ExtraData
;
109 data
->size
= device
->UpdateSize
* aluFrameSizeFromFormat(device
->Format
);
110 data
->buffer
= malloc(data
->size
);
113 AL_PRINT("buffer malloc failed\n");
116 SetDefaultWFXChannelOrder(device
);
118 device
->TimeRes
= 1000000;
120 data
->startTime
= timeGetTime();
121 data
->thread
= StartThread(NullProc
, device
);
122 if(data
->thread
== NULL
)
132 static void null_stop_playback(ALCdevice
*device
)
134 null_data
*data
= (null_data
*)device
->ExtraData
;
141 StopThread(data
->thread
);
146 ext
= timeGetTime() - data
->startTime
;
147 data
->baseTime
+= (ALuint64
)ext
* 1000000;
154 static ALCboolean
null_open_capture(ALCdevice
*device
, const ALCchar
*deviceName
)
161 static ALuint64
null_get_time(ALCdevice
*Device
)
163 null_data
*data
= (null_data
*)Device
->ExtraData
;
166 ext
= timeGetTime() - data
->startTime
;
167 return data
->baseTime
+ ((ALuint64
)ext
* 1000000);
171 BackendFuncs null_funcs
= {
185 void alc_null_init(BackendFuncs
*func_list
)
187 *func_list
= null_funcs
;
190 void alc_null_deinit(void)
194 void alc_null_probe(int type
)
196 if(type
== DEVICE_PROBE
)
197 AppendDeviceList(nullDevice
);
198 else if(type
== ALL_DEVICE_PROBE
)
199 AppendAllDeviceList(nullDevice
);