23 #if SDL_AUDIO_DRIVER_BSD
34 #include <sys/ioctl.h>
37 #include <sys/audioio.h>
41 #include "../SDL_audiomem.h"
42 #include "../SDL_audio_c.h"
43 #include "../SDL_audiodev_c.h"
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) {
140 FD_SET(this->hidden->audio_fd, &fdset);
144 fprintf(stderr,
"Waiting for audio to get ready\n");
149 "Audio timeout - buggy audio driver? (disabled)";
154 fprintf(stderr,
"SDL: %s\n", message);
157 this->hidden->audio_fd = -1;
159 fprintf(stderr,
"Done disabling audio\n");
163 fprintf(stderr,
"Ready!\n");
170 BSDAUDIO_PlayDevice(
_THIS)
176 written = write(this->hidden->audio_fd,
177 &this->hidden->mixbuf[p], this->hidden->mixlen - p);
181 if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
188 || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
191 }
while (p < written);
194 if (this->hidden->frame_ticks) {
195 this->hidden->next_frame += this->hidden->frame_ticks;
203 fprintf(stderr,
"Wrote %d bytes of audio data\n", written);
208 BSDAUDIO_GetDeviceBuf(
_THIS)
210 return (this->hidden->mixbuf);
214 BSDAUDIO_CloseDevice(
_THIS)
216 if (this->hidden !=
NULL) {
218 this->hidden->mixbuf =
NULL;
219 if (this->hidden->audio_fd >= 0) {
220 close(this->hidden->audio_fd);
221 this->hidden->audio_fd = -1;
229 BSDAUDIO_OpenDevice(
_THIS,
const char *devname,
int iscapture)
237 if (devname ==
NULL) {
239 if (devname ==
NULL) {
247 if (this->hidden ==
NULL) {
250 SDL_memset(this->hidden, 0, (
sizeof *this->hidden));
253 this->hidden->audio_fd = open(devname, flags, 0);
254 if (this->hidden->audio_fd < 0) {
255 return SDL_SetError(
"Couldn't open %s: %s", devname, strerror(errno));
258 AUDIO_INITINFO(&info);
264 info.mode = AUMODE_PLAY;
265 if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
266 BSDAUDIO_CloseDevice(
this);
267 return SDL_SetError(
"Couldn't put device into play mode");
270 AUDIO_INITINFO(&info);
275 info.play.encoding = AUDIO_ENCODING_ULINEAR;
276 info.play.precision = 8;
279 info.play.encoding = AUDIO_ENCODING_SLINEAR;
280 info.play.precision = 8;
283 info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
284 info.play.precision = 16;
287 info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
288 info.play.precision = 16;
291 info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
292 info.play.precision = 16;
295 info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
296 info.play.precision = 16;
302 if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
308 BSDAUDIO_CloseDevice(
this);
309 return SDL_SetError(
"No supported encoding for 0x%x", this->spec.format);
312 this->spec.format =
format;
314 AUDIO_INITINFO(&info);
315 info.play.channels = this->spec.channels;
316 if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
317 this->spec.channels = 1;
319 AUDIO_INITINFO(&info);
320 info.play.sample_rate = this->spec.freq;
321 info.blocksize = this->spec.size;
324 (
void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
325 (
void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
326 this->spec.freq = info.play.sample_rate;
328 this->hidden->mixlen = this->spec.size;
330 if (this->hidden->mixbuf ==
NULL) {
331 BSDAUDIO_CloseDevice(
this);
334 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
336 BSDAUDIO_Status(
this);
358 "bsd",
"BSD audio", BSDAUDIO_Init, 0
void(* CloseDevice)(_THIS)
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
int32_t Sint32
A signed 32-bit integer type.
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
GLsizei GLenum GLuint GLuint GLsizei GLchar * message
void(* SDL_AddAudioDevice)(const char *name)
void(* WaitDevice)(_THIS)
void SDL_EnumUnixAudioDevices(int iscapture, int classic, int(*test)(int fd), SDL_AddAudioDevice addfn)
GLenum GLsizei const GLuint GLboolean enabled
Uint8 *(* GetDeviceBuf)(_THIS)
DECLSPEC void SDLCALL SDL_free(void *mem)
Uint16 SDL_AudioFormat
Audio format flags.
int(* OpenDevice)(_THIS, const char *devname, int iscapture)
AudioBootStrap BSD_AUDIO_bootstrap
SDL_AudioFormat SDL_NextAudioFormat(void)
void(* PlayDevice)(_THIS)
DECLSPEC Uint32 SDLCALL SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
void(* DetectDevices)(int iscapture, SDL_AddAudioDevice addfn)
DECLSPEC const char *SDLCALL SDL_GetAudioDeviceName(int index, int iscapture)
#define OPEN_FLAGS_OUTPUT
DECLSPEC void SDLCALL SDL_Delay(Uint32 ms)
Wait a specified number of milliseconds before returning.
DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
#define SDL_AllocAudioMem
GLbitfield GLuint64 timeout
#define SDL_OutOfMemory()
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
uint8_t Uint8
An unsigned 8-bit integer type.