Win64 doesn't allow _controlfp or __control87_2 to set the precision control bits
[openal-soft.git] / Alc / backends / null.c
blob0b58310a8e1bc0f9ab4d3d1af87042df787a7638
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.
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
21 #include "config.h"
23 #include <stdlib.h>
25 #include "alMain.h"
26 #include "alu.h"
29 typedef struct {
30 volatile int killNow;
31 ALvoid *thread;
32 } null_data;
35 static const ALCchar nullDevice[] = "No Output";
37 static ALuint NullProc(ALvoid *ptr)
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;
46 done = 0;
47 start = timeGetTime();
48 while(!data->killNow && Device->Connected)
50 now = timeGetTime();
52 avail = (ALuint64)(now-start) * Device->Frequency / 1000;
53 if(avail < done)
55 /* Timer wrapped (50 days???). Add the remainder of the cycle to
56 * the available count and reset the number of samples done */
57 avail += ((ALuint64)1<<32)*Device->Frequency/1000 - done;
58 done = 0;
60 if(avail-done < Device->UpdateSize)
62 Sleep(restTime);
63 continue;
66 while(avail-done >= Device->UpdateSize)
68 aluMixData(Device, NULL, Device->UpdateSize);
69 done += Device->UpdateSize;
73 return 0;
76 static ALCenum null_open_playback(ALCdevice *device, const ALCchar *deviceName)
78 null_data *data;
80 if(!deviceName)
81 deviceName = nullDevice;
82 else if(strcmp(deviceName, nullDevice) != 0)
83 return ALC_INVALID_VALUE;
85 data = (null_data*)calloc(1, sizeof(*data));
87 device->DeviceName = strdup(deviceName);
88 device->ExtraData = data;
89 return ALC_NO_ERROR;
92 static void null_close_playback(ALCdevice *device)
94 null_data *data = (null_data*)device->ExtraData;
96 free(data);
97 device->ExtraData = NULL;
100 static ALCboolean null_reset_playback(ALCdevice *device)
102 SetDefaultWFXChannelOrder(device);
103 return ALC_TRUE;
106 static ALCboolean null_start_playback(ALCdevice *device)
108 null_data *data = (null_data*)device->ExtraData;
110 data->thread = StartThread(NullProc, device);
111 if(data->thread == NULL)
112 return ALC_FALSE;
114 return ALC_TRUE;
117 static void null_stop_playback(ALCdevice *device)
119 null_data *data = (null_data*)device->ExtraData;
121 if(!data->thread)
122 return;
124 data->killNow = 1;
125 StopThread(data->thread);
126 data->thread = NULL;
128 data->killNow = 0;
132 static const BackendFuncs null_funcs = {
133 null_open_playback,
134 null_close_playback,
135 null_reset_playback,
136 null_start_playback,
137 null_stop_playback,
138 NULL,
139 NULL,
140 NULL,
141 NULL,
142 NULL,
143 NULL,
144 ALCdevice_LockDefault,
145 ALCdevice_UnlockDefault,
146 ALCdevice_GetLatencyDefault
149 ALCboolean alc_null_init(BackendFuncs *func_list)
151 *func_list = null_funcs;
152 return ALC_TRUE;
155 void alc_null_deinit(void)
159 void alc_null_probe(enum DevProbe type)
161 switch(type)
163 case ALL_DEVICE_PROBE:
164 AppendAllDevicesList(nullDevice);
165 break;
166 case CAPTURE_DEVICE_PROBE:
167 break;