21 #include "../../SDL_internal.h" 23 #if SDL_AUDIO_DRIVER_PAUDIO 31 #include <sys/ioctl.h> 32 #include <sys/types.h> 38 #include "../SDL_audio_c.h" 39 #include "../../core/unix/SDL_poll.h" 46 #include <sys/machine.h> 48 #include <sys/audio.h> 52 #define OPEN_FLAGS O_WRONLY 57 #define _PATH_DEV_DSP "/dev/%caud%c/%c" 60 static char devsettings[][3] = {
61 {
'p',
'0',
'1'}, {
'p',
'0',
'2'}, {
'p',
'0',
'3'}, {
'p',
'0',
'4'},
62 {
'p',
'1',
'1'}, {
'p',
'1',
'2'}, {
'p',
'1',
'3'}, {
'p',
'1',
'4'},
63 {
'p',
'2',
'1'}, {
'p',
'2',
'2'}, {
'p',
'2',
'3'}, {
'p',
'2',
'4'},
64 {
'p',
'3',
'1'}, {
'p',
'3',
'2'}, {
'p',
'3',
'3'}, {
'p',
'3',
'4'},
65 {
'b',
'0',
'1'}, {
'b',
'0',
'2'}, {
'b',
'0',
'3'}, {
'b',
'0',
'4'},
66 {
'b',
'1',
'1'}, {
'b',
'1',
'2'}, {
'b',
'1',
'3'}, {
'b',
'1',
'4'},
67 {
'b',
'2',
'1'}, {
'b',
'2',
'2'}, {
'b',
'2',
'3'}, {
'b',
'2',
'4'},
68 {
'b',
'3',
'1'}, {
'b',
'3',
'2'}, {
'b',
'3',
'3'}, {
'b',
'3',
'4'},
73 OpenUserDefinedDevice(
char *
path,
int maxlen,
int flags)
82 if (audiodev ==
NULL) {
85 fd = open(audiodev, flags, 0);
88 path[maxlen - 1] =
'\0';
94 OpenAudioPath(
char *path,
int maxlen,
int flags,
int classic)
98 int fd = OpenUserDefinedDevice(path, maxlen, flags);
105 while (devsettings[cycle][0] !=
'\0') {
106 char audiopath[1024];
109 devsettings[cycle][0],
110 devsettings[cycle][1], devsettings[cycle][2]);
112 if (stat(audiopath, &sb) == 0) {
113 fd = open(audiopath, flags, 0);
127 PAUDIO_WaitDevice(
_THIS)
132 if (this->hidden->frame_ticks) {
142 audio_buffer paud_bufinfo;
144 if (ioctl(this->hidden->audio_fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
146 fprintf(stderr,
"Couldn't get audio buffer information\n");
148 timeoutMS = 10 * 1000;
150 timeoutMS = paud_bufinfo.write_buf_time;
152 fprintf(stderr,
"Waiting for write_buf_time=%d ms\n", timeoutMS);
157 fprintf(stderr,
"Waiting for audio to get ready\n");
165 fprintf(stderr,
"SDL: %s - Audio timeout - buggy audio driver? (disabled)\n", strerror(errno));
168 this->hidden->audio_fd = -1;
170 fprintf(stderr,
"Done disabling audio\n");
174 fprintf(stderr,
"Ready!\n");
180 PAUDIO_PlayDevice(
_THIS)
183 const Uint8 *mixbuf = this->hidden->mixbuf;
184 const size_t mixlen = this->hidden->mixlen;
188 written = write(this->hidden->audio_fd, mixbuf, mixlen);
189 if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
192 }
while ((written < 0) &&
193 ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
196 if (this->hidden->frame_ticks) {
197 this->hidden->next_frame += this->hidden->frame_ticks;
205 fprintf(stderr,
"Wrote %d bytes of audio data\n", written);
210 PAUDIO_GetDeviceBuf(
_THIS)
212 return this->hidden->mixbuf;
216 PAUDIO_CloseDevice(
_THIS)
218 if (this->hidden->audio_fd >= 0) {
219 close(this->hidden->audio_fd);
226 PAUDIO_OpenDevice(
_THIS,
void *
handle,
const char *devname,
int iscapture)
228 const char *workaround =
SDL_getenv(
"SDL_DSP_NOSELECT");
230 const char *err =
NULL;
232 int bytes_per_sample;
234 audio_init paud_init;
235 audio_buffer paud_bufinfo;
236 audio_control paud_control;
237 audio_change paud_change;
243 if (this->hidden ==
NULL) {
249 fd = OpenAudioPath(audiodev,
sizeof(audiodev), OPEN_FLAGS, 0);
250 this->hidden->audio_fd =
fd;
252 return SDL_SetError(
"Couldn't open %s: %s", audiodev, strerror(errno));
259 if (ioctl(fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
260 return SDL_SetError(
"Couldn't get audio buffer information");
314 paud_init.mode = PCM;
315 paud_init.operation = PLAY;
321 !format && test_format;) {
323 fprintf(stderr,
"Trying format 0x%4.4x\n", test_format);
325 switch (test_format) {
327 bytes_per_sample = 1;
328 paud_init.bits_per_sample = 8;
329 paud_init.flags = TWOS_COMPLEMENT | FIXED;
333 bytes_per_sample = 1;
334 paud_init.bits_per_sample = 8;
335 paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED;
339 bytes_per_sample = 2;
340 paud_init.bits_per_sample = 16;
341 paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED;
345 bytes_per_sample = 2;
346 paud_init.bits_per_sample = 16;
347 paud_init.flags = BIG_ENDIAN | SIGNED | TWOS_COMPLEMENT | FIXED;
351 bytes_per_sample = 2;
352 paud_init.bits_per_sample = 16;
353 paud_init.flags = TWOS_COMPLEMENT | FIXED;
357 bytes_per_sample = 2;
358 paud_init.bits_per_sample = 16;
359 paud_init.flags = BIG_ENDIAN | TWOS_COMPLEMENT | FIXED;
371 fprintf(stderr,
"Couldn't find any hardware audio formats\n");
373 return SDL_SetError(
"Couldn't find any hardware audio formats");
387 if (paud_bufinfo.request_buf_cap == 1) {
394 paud_init.bsize = bytes_per_sample * this->
spec.
channels;
406 if (ioctl(fd, AUDIO_INIT, &paud_init) < 0) {
407 switch (paud_init.rc) {
409 err =
"Couldn't set audio format: DSP can't do play requests";
412 err =
"Couldn't set audio format: DSP can't do record requests";
415 err =
"Couldn't set audio format: request was invalid";
418 err =
"Couldn't set audio format: conflict with open's flags";
421 err =
"Couldn't set audio format: out of DSP MIPS or memory";
424 err =
"Couldn't set audio format: not documented in sys/audio.h";
434 this->hidden->mixlen = this->
spec.
size;
436 if (this->hidden->mixbuf ==
NULL) {
439 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
445 paud_change.input = AUDIO_IGNORE;
446 paud_change.output = OUTPUT_1;
447 paud_change.monitor = AUDIO_IGNORE;
448 paud_change.volume = 0x7fffffff;
449 paud_change.volume_delay = AUDIO_IGNORE;
450 paud_change.balance = 0x3fffffff;
451 paud_change.balance_delay = AUDIO_IGNORE;
452 paud_change.treble = AUDIO_IGNORE;
453 paud_change.bass = AUDIO_IGNORE;
454 paud_change.pitch = AUDIO_IGNORE;
456 paud_control.ioctl_request = AUDIO_CHANGE;
457 paud_control.request_info = (
char *) &paud_change;
458 if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
460 fprintf(stderr,
"Can't change audio display settings\n");
468 paud_control.ioctl_request = AUDIO_START;
469 paud_control.position = 0;
470 if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
472 fprintf(stderr,
"Can't start audio play\n");
478 if (workaround !=
NULL) {
479 this->hidden->frame_ticks = (float) (this->
spec.
samples * 1000) /
481 this->hidden->next_frame =
SDL_GetTicks() + this->hidden->frame_ticks;
492 int fd = OpenAudioPath(
NULL, 0, OPEN_FLAGS, 0);
511 "paud",
"AIX Paudio", PAUDIO_Init, 0
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
int SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
void(* PlayDevice)(_THIS)
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
Uint16 SDL_AudioFormat
Audio format flags.
SDL_AudioFormat SDL_NextAudioFormat(void)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
int OnlyHasDefaultOutputDevice
EGLImageKHR EGLint EGLint * handle
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
int(* OpenDevice)(_THIS, void *handle, const char *devname, int iscapture)
#define SDL_OutOfMemory()
void(* CloseDevice)(_THIS)
AudioBootStrap PAUDIO_bootstrap
Uint8 *(* GetDeviceBuf)(_THIS)
#define SDL_arraysize(array)
GLsizei const GLchar *const * path