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 char *solaris_device
;
52 static ALuint
SolarisProc(ALvoid
*ptr
)
54 ALCdevice
*pDevice
= (ALCdevice
*)ptr
;
55 solaris_data
*data
= (solaris_data
*)pDevice
->ExtraData
;
61 int len
= data
->data_size
- remaining
;
66 aluMixData(pDevice
->Context
, data
->mix_data
+remaining
, len
, pDevice
->Format
);
71 wrote
= write(data
->fd
, data
->mix_data
, remaining
);
74 AL_PRINT("write failed: %s\n", strerror(errno
));
81 memmove(data
->mix_data
, data
->mix_data
+wrote
, remaining
);
91 static ALCboolean
solaris_open_playback(ALCdevice
*device
, const ALCchar
*deviceName
)
99 strncpy(driver
, GetConfigValue("solaris", "device", "/dev/audio"), sizeof(driver
)-1);
100 driver
[sizeof(driver
)-1] = 0;
103 if(strcmp(deviceName
, solaris_device
))
105 device
->szDeviceName
= solaris_device
;
108 device
->szDeviceName
= solaris_device
;
110 data
= (solaris_data
*)calloc(1, sizeof(solaris_data
));
113 data
->fd
= open(driver
, O_WRONLY
);
117 AL_PRINT("Could not open %s: %s\n", driver
, strerror(errno
));
121 numChannels
= aluChannelsFromFormat(device
->Format
);
122 AUDIO_INITINFO(&info
);
123 info
.play
.sample_rate
= device
->Frequency
;
124 info
.play
.channels
= numChannels
;
126 switch(aluBytesFromFormat(device
->Format
))
129 info
.play
.precision
= 8;
130 info
.play
.encoding
= AUDIO_ENCODING_LINEAR8
;
133 info
.play
.precision
= 16;
134 info
.play
.encoding
= AUDIO_ENCODING_LINEAR
;
137 AL_PRINT("Unknown format?! %x\n", device
->Format
);
140 frameSize
= numChannels
* aluBytesFromFormat(device
->Format
);
141 info
.play
.buffer_size
= device
->UpdateSize
* frameSize
;
143 if(ioctl(data
->fd
, AUDIO_SETINFO
, &info
) < 0)
145 AL_PRINT("ioctl failed: %s\n", strerror(errno
));
151 device
->Frequency
= info
.play
.sample_rate
;
153 if(aluChannelsFromFormat(device
->Format
) != info
.play
.channels
)
155 AL_PRINT("Could not set %d channels, got %d instead\n", aluChannelsFromFormat(device
->Format
), info
.play
.channels
);
161 if(!((info
.play
.precision
== 8 && aluBytesFromFormat(device
->Format
) == 1) ||
162 (info
.play
.precision
== 16 && aluBytesFromFormat(device
->Format
) == 2)))
164 AL_PRINT("Could not set %d-bit output, got %d\n", aluBytesFromFormat(device
->Format
)*8, info
.play
.precision
);
170 device
->UpdateSize
= info
.play
.buffer_size
/ 4;
172 data
->data_size
= device
->UpdateSize
* frameSize
;
173 data
->mix_data
= calloc(1, data
->data_size
);
175 device
->ExtraData
= data
;
176 data
->thread
= StartThread(SolarisProc
, device
);
177 if(data
->thread
== NULL
)
179 device
->ExtraData
= NULL
;
180 free(data
->mix_data
);
188 static void solaris_close_playback(ALCdevice
*device
)
190 solaris_data
*data
= (solaris_data
*)device
->ExtraData
;
192 StopThread(data
->thread
);
196 free(data
->mix_data
);
198 device
->ExtraData
= NULL
;
202 static ALCboolean
solaris_open_capture(ALCdevice
*device
, const ALCchar
*deviceName
, ALCuint frequency
, ALCenum format
, ALCsizei SampleSize
)
212 static void solaris_close_capture(ALCdevice
*device
)
217 static void solaris_start_capture(ALCdevice
*pDevice
)
222 static void solaris_stop_capture(ALCdevice
*pDevice
)
227 static void solaris_capture_samples(ALCdevice
*pDevice
, ALCvoid
*pBuffer
, ALCuint lSamples
)
234 static ALCuint
solaris_available_samples(ALCdevice
*pDevice
)
241 BackendFuncs solaris_funcs
= {
242 solaris_open_playback
,
243 solaris_close_playback
,
244 solaris_open_capture
,
245 solaris_close_capture
,
246 solaris_start_capture
,
247 solaris_stop_capture
,
248 solaris_capture_samples
,
249 solaris_available_samples
252 void alc_solaris_init(BackendFuncs
*func_list
)
254 *func_list
= solaris_funcs
;
256 solaris_device
= AppendDeviceList("Solaris Software");
257 AppendAllDeviceList(solaris_device
);