21 #include "../../SDL_internal.h" 23 #if SDL_AUDIO_DRIVER_BSD 34 #include <sys/ioctl.h> 36 #include <sys/types.h> 37 #include <sys/audioio.h> 41 #include "../SDL_audiomem.h" 42 #include "../SDL_audio_c.h" 43 #include "../SDL_audiodev_c.h" 54 BSDAUDIO_DetectDevices(
void)
61 BSDAUDIO_Status(
_THIS)
67 if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
68 fprintf(stderr,
"AUDIO_GETINFO failed.\n");
72 "[play/record info]\n" 73 "buffer size : %d bytes\n" 74 "sample rate : %i Hz\n" 76 "precision : %i-bit\n" 82 "error occured : %s\n" 86 info.play.buffer_size,
87 info.play.sample_rate,
94 info.play.pause ?
"yes" :
"no",
95 info.play.error ?
"yes" :
"no",
96 info.play.waiting ?
"yes" :
"no",
97 info.play.active ?
"yes" :
"no");
101 "monitor_gain : %i\n" 102 "hw block size : %d bytes\n" 103 "hi watermark : %i\n" 104 "lo watermark : %i\n" 109 info.hiwat, info.lowat,
110 (info.mode == AUMODE_PLAY) ?
"PLAY" 111 : (info.mode = AUMODE_RECORD) ?
"RECORD" 112 : (info.mode == AUMODE_PLAY_ALL ?
"PLAY_ALL" :
"?"));
120 BSDAUDIO_WaitDevice(
_THIS)
122 #ifndef USE_BLOCKING_WRITES 124 if (this->hidden->frame_ticks) {
138 FD_SET(this->hidden->audio_fd, &fdset);
142 fprintf(stderr,
"Waiting for audio to get ready\n");
147 "Audio timeout - buggy audio driver? (disabled)";
152 fprintf(stderr,
"SDL: %s\n", message);
155 this->hidden->audio_fd = -1;
157 fprintf(stderr,
"Done disabling audio\n");
161 fprintf(stderr,
"Ready!\n");
168 BSDAUDIO_PlayDevice(
_THIS)
174 written = write(this->hidden->audio_fd,
175 &this->hidden->mixbuf[p], this->hidden->mixlen - p);
179 if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
186 || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
189 }
while (p < written);
192 if (this->hidden->frame_ticks) {
193 this->hidden->next_frame += this->hidden->frame_ticks;
201 fprintf(stderr,
"Wrote %d bytes of audio data\n", written);
206 BSDAUDIO_GetDeviceBuf(
_THIS)
208 return (this->hidden->mixbuf);
212 BSDAUDIO_CloseDevice(
_THIS)
214 if (this->hidden !=
NULL) {
216 this->hidden->mixbuf =
NULL;
217 if (this->hidden->audio_fd >= 0) {
218 close(this->hidden->audio_fd);
219 this->hidden->audio_fd = -1;
227 BSDAUDIO_OpenDevice(
_THIS,
void *handle,
const char *devname,
int iscapture)
235 if (devname ==
NULL) {
237 if (devname ==
NULL) {
245 if (this->hidden ==
NULL) {
248 SDL_memset(this->hidden, 0, (
sizeof *this->hidden));
251 this->hidden->audio_fd = open(devname, flags, 0);
252 if (this->hidden->audio_fd < 0) {
253 return SDL_SetError(
"Couldn't open %s: %s", devname, strerror(errno));
256 AUDIO_INITINFO(&info);
262 info.mode = AUMODE_PLAY;
263 if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
264 BSDAUDIO_CloseDevice(
this);
265 return SDL_SetError(
"Couldn't put device into play mode");
268 AUDIO_INITINFO(&info);
273 info.play.encoding = AUDIO_ENCODING_ULINEAR;
274 info.play.precision = 8;
277 info.play.encoding = AUDIO_ENCODING_SLINEAR;
278 info.play.precision = 8;
281 info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
282 info.play.precision = 16;
285 info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
286 info.play.precision = 16;
289 info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
290 info.play.precision = 16;
293 info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
294 info.play.precision = 16;
300 if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
306 BSDAUDIO_CloseDevice(
this);
312 AUDIO_INITINFO(&info);
314 if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
317 AUDIO_INITINFO(&info);
318 info.play.sample_rate = this->
spec.
freq;
322 (
void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
323 (
void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
324 this->
spec.
freq = info.play.sample_rate;
326 this->hidden->mixlen = this->
spec.
size;
328 if (this->hidden->mixbuf ==
NULL) {
329 BSDAUDIO_CloseDevice(
this);
332 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
334 BSDAUDIO_Status(
this);
358 "bsd",
"BSD audio", BSDAUDIO_Init, 0
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
void(* DetectDevices)(void)
GLuint GLsizei const GLchar * message
void(* PlayDevice)(_THIS)
void(* WaitDevice)(_THIS)
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
Uint16 SDL_AudioFormat
Audio format flags.
AudioBootStrap BSD_AUDIO_bootstrap
SDL_AudioFormat SDL_NextAudioFormat(void)
#define SDL_GetAudioDeviceName
void SDL_EnumUnixAudioDevices(const int classic, int(*test)(int))
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
#define OPEN_FLAGS_OUTPUT
uint8_t Uint8
An unsigned 8-bit integer type.
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
#define SDL_AllocAudioMem
int32_t Sint32
A signed 32-bit integer type.
int(* OpenDevice)(_THIS, void *handle, const char *devname, int iscapture)
#define SDL_OutOfMemory()
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
void(* CloseDevice)(_THIS)
int AllowsArbitraryDeviceNames
GLbitfield GLuint64 timeout
Uint8 *(* GetDeviceBuf)(_THIS)