2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2007 by authors.
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
23 #include <sys/ioctl.h>
24 #include <sys/types.h>
37 #include <sys/audioio.h>
40 static const ALCchar solaris_device
[] = "Solaris Default";
52 static ALuint
SolarisProc(ALvoid
*ptr
)
54 ALCdevice
*pDevice
= (ALCdevice
*)ptr
;
55 solaris_data
*data
= (solaris_data
*)pDevice
->ExtraData
;
62 frameSize
= aluFrameSizeFromFormat(pDevice
->Format
);
64 while(!data
->killNow
&& pDevice
->Connected
)
66 ALint len
= data
->data_size
;
67 ALubyte
*WritePtr
= data
->mix_data
;
69 aluMixData(pDevice
, WritePtr
, len
/frameSize
);
70 while(len
> 0 && !data
->killNow
)
72 wrote
= write(data
->fd
, WritePtr
, len
);
75 if(errno
!= EAGAIN
&& errno
!= EWOULDBLOCK
&& errno
!= EINTR
)
77 AL_PRINT("write failed: %s\n", strerror(errno
));
78 aluHandleDisconnect(pDevice
);
95 static ALCboolean
solaris_open_playback(ALCdevice
*device
, const ALCchar
*deviceName
)
100 strncpy(driver
, GetConfigValue("solaris", "device", "/dev/audio"), sizeof(driver
)-1);
101 driver
[sizeof(driver
)-1] = 0;
103 deviceName
= solaris_device
;
104 else if(strcmp(deviceName
, solaris_device
) != 0)
107 data
= (solaris_data
*)calloc(1, sizeof(solaris_data
));
110 data
->fd
= open(driver
, O_WRONLY
);
114 AL_PRINT("Could not open %s: %s\n", driver
, strerror(errno
));
118 device
->szDeviceName
= strdup(deviceName
);
119 device
->ExtraData
= data
;
123 static void solaris_close_playback(ALCdevice
*device
)
125 solaris_data
*data
= (solaris_data
*)device
->ExtraData
;
129 device
->ExtraData
= NULL
;
132 static ALCboolean
solaris_reset_playback(ALCdevice
*device
)
134 solaris_data
*data
= (solaris_data
*)device
->ExtraData
;
139 AUDIO_INITINFO(&info
);
141 switch(aluBytesFromFormat(device
->Format
))
144 info
.play
.precision
= 8;
145 info
.play
.encoding
= AUDIO_ENCODING_LINEAR8
;
150 case 1: device
->Format
= AL_FORMAT_MONO16
; break;
151 case 2: device
->Format
= AL_FORMAT_STEREO16
; break;
152 case 4: device
->Format
= AL_FORMAT_QUAD16
; break;
153 case 6: device
->Format
= AL_FORMAT_51CHN16
; break;
154 case 7: device
->Format
= AL_FORMAT_61CHN16
; break;
155 case 8: device
->Format
= AL_FORMAT_71CHN16
; break;
159 info
.play
.precision
= 16;
160 info
.play
.encoding
= AUDIO_ENCODING_LINEAR
;
163 AL_PRINT("Unknown format: 0x%x\n", device
->Format
);
167 numChannels
= aluChannelsFromFormat(device
->Format
);
168 info
.play
.sample_rate
= device
->Frequency
;
169 info
.play
.channels
= numChannels
;
171 frameSize
= numChannels
* aluBytesFromFormat(device
->Format
);
172 info
.play
.buffer_size
= device
->UpdateSize
*device
->NumUpdates
* frameSize
;
174 if(ioctl(data
->fd
, AUDIO_SETINFO
, &info
) < 0)
176 AL_PRINT("ioctl failed: %s\n", strerror(errno
));
180 if(aluChannelsFromFormat(device
->Format
) != info
.play
.channels
)
182 AL_PRINT("Could not set %d channels, got %d instead\n", aluChannelsFromFormat(device
->Format
), info
.play
.channels
);
186 if(!((info
.play
.precision
== 8 && aluBytesFromFormat(device
->Format
) == 1) ||
187 (info
.play
.precision
== 16 && aluBytesFromFormat(device
->Format
) == 2)))
189 AL_PRINT("Could not set %d-bit output, got %d\n", aluBytesFromFormat(device
->Format
)*8, info
.play
.precision
);
193 device
->Frequency
= info
.play
.sample_rate
;
194 device
->UpdateSize
= (info
.play
.buffer_size
/device
->NumUpdates
) + 1;
195 device
->TimeRes
= (ALuint64
)device
->UpdateSize
* 1000000000 /
198 data
->data_size
= device
->UpdateSize
* frameSize
;
199 data
->mix_data
= calloc(1, data
->data_size
);
201 SetDefaultChannelOrder(device
);
203 data
->thread
= StartThread(SolarisProc
, device
);
204 if(data
->thread
== NULL
)
206 free(data
->mix_data
);
207 data
->mix_data
= NULL
;
214 static void solaris_stop_playback(ALCdevice
*device
)
216 solaris_data
*data
= (solaris_data
*)device
->ExtraData
;
222 StopThread(data
->thread
);
227 free(data
->mix_data
);
228 data
->mix_data
= NULL
;
232 static ALCboolean
solaris_open_capture(ALCdevice
*device
, const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
242 static void solaris_close_capture(ALCdevice
*device
)
247 static void solaris_start_capture(ALCdevice
*pDevice
)
252 static void solaris_stop_capture(ALCdevice
*pDevice
)
257 static void solaris_capture_samples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCuint lSamples
)
264 static ALCuint
solaris_available_samples(ALCdevice
*pDevice
)
270 static ALuint64
solaris_get_time(ALCdevice
*Device
)
272 return Device
->SamplesPlayed
* 1000000000 / Device
->Frequency
;
276 BackendFuncs solaris_funcs
= {
277 solaris_open_playback
,
278 solaris_close_playback
,
279 solaris_reset_playback
,
280 solaris_stop_playback
,
281 solaris_open_capture
,
282 solaris_close_capture
,
283 solaris_start_capture
,
284 solaris_stop_capture
,
285 solaris_capture_samples
,
286 solaris_available_samples
,
290 void alc_solaris_init(BackendFuncs
*func_list
)
292 *func_list
= solaris_funcs
;
295 void alc_solaris_deinit(void)
299 void alc_solaris_probe(int type
)
303 if(stat(GetConfigValue("solaris", "device", "/dev/audio"), &buf
) != 0)
307 if(type
== DEVICE_PROBE
)
308 AppendDeviceList(solaris_device
);
309 else if(type
== ALL_DEVICE_PROBE
)
310 AppendAllDeviceList(solaris_device
);