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
38 static const ALCchar nullDevice
[] = "No Output";
40 static ALuint
NullProc(ALvoid
*ptr
)
42 ALCdevice
*Device
= (ALCdevice
*)ptr
;
43 null_data
*data
= (null_data
*)Device
->ExtraData
;
46 const ALuint restTime
= (ALuint64
)Device
->UpdateSize
* 1000 /
47 Device
->Frequency
/ 2;
50 start
= timeGetTime();
51 while(!data
->killNow
&& Device
->Connected
)
55 avail
= (ALuint64
)(now
-start
) * Device
->Frequency
/ 1000;
58 AL_PRINT("Timer wrapped\n");
59 aluHandleDisconnect(Device
);
62 if(avail
-done
< Device
->UpdateSize
)
68 while(avail
-done
>= Device
->UpdateSize
)
70 aluMixData(Device
, data
->buffer
, Device
->UpdateSize
);
71 done
+= Device
->UpdateSize
;
78 static ALCboolean
null_open_playback(ALCdevice
*device
, const ALCchar
*deviceName
)
83 deviceName
= nullDevice
;
84 else if(strcmp(deviceName
, nullDevice
) != 0)
87 data
= (null_data
*)calloc(1, sizeof(*data
));
89 device
->szDeviceName
= strdup(deviceName
);
90 device
->ExtraData
= data
;
94 static void null_close_playback(ALCdevice
*device
)
96 null_data
*data
= (null_data
*)device
->ExtraData
;
99 device
->ExtraData
= NULL
;
102 static ALCboolean
null_reset_playback(ALCdevice
*device
)
104 null_data
*data
= (null_data
*)device
->ExtraData
;
106 data
->size
= device
->UpdateSize
* aluFrameSizeFromFormat(device
->Format
);
107 data
->buffer
= malloc(data
->size
);
110 AL_PRINT("buffer malloc failed\n");
113 SetDefaultWFXChannelOrder(device
);
115 data
->thread
= StartThread(NullProc
, device
);
116 if(data
->thread
== NULL
)
126 static void null_stop_playback(ALCdevice
*device
)
128 null_data
*data
= (null_data
*)device
->ExtraData
;
134 StopThread(data
->thread
);
144 static ALCboolean
null_open_capture(ALCdevice
*device
, const ALCchar
*deviceName
)
152 BackendFuncs null_funcs
= {
165 void alc_null_init(BackendFuncs
*func_list
)
167 *func_list
= null_funcs
;
170 void alc_null_deinit(void)
174 void alc_null_probe(int type
)
176 if(type
== DEVICE_PROBE
)
177 AppendDeviceList(nullDevice
);
178 else if(type
== ALL_DEVICE_PROBE
)
179 AppendAllDeviceList(nullDevice
);