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" 45 #include <sys/machine.h> 47 #include <sys/audio.h> 51 #define OPEN_FLAGS O_WRONLY 56 #define _PATH_DEV_DSP "/dev/%caud%c/%c" 59 static char devsettings[][3] = {
60 {
'p',
'0',
'1'}, {
'p',
'0',
'2'}, {
'p',
'0',
'3'}, {
'p',
'0',
'4'},
61 {
'p',
'1',
'1'}, {
'p',
'1',
'2'}, {
'p',
'1',
'3'}, {
'p',
'1',
'4'},
62 {
'p',
'2',
'1'}, {
'p',
'2',
'2'}, {
'p',
'2',
'3'}, {
'p',
'2',
'4'},
63 {
'p',
'3',
'1'}, {
'p',
'3',
'2'}, {
'p',
'3',
'3'}, {
'p',
'3',
'4'},
64 {
'b',
'0',
'1'}, {
'b',
'0',
'2'}, {
'b',
'0',
'3'}, {
'b',
'0',
'4'},
65 {
'b',
'1',
'1'}, {
'b',
'1',
'2'}, {
'b',
'1',
'3'}, {
'b',
'1',
'4'},
66 {
'b',
'2',
'1'}, {
'b',
'2',
'2'}, {
'b',
'2',
'3'}, {
'b',
'2',
'4'},
67 {
'b',
'3',
'1'}, {
'b',
'3',
'2'}, {
'b',
'3',
'3'}, {
'b',
'3',
'4'},
72 OpenUserDefinedDevice(
char *
path,
int maxlen,
int flags)
81 if (audiodev ==
NULL) {
84 fd = open(audiodev, flags, 0);
87 path[maxlen - 1] =
'\0';
93 OpenAudioPath(
char *path,
int maxlen,
int flags,
int classic)
97 int fd = OpenUserDefinedDevice(path, maxlen, flags);
104 while (devsettings[cycle][0] !=
'\0') {
105 char audiopath[1024];
108 devsettings[cycle][0],
109 devsettings[cycle][1], devsettings[cycle][2]);
111 if (stat(audiopath, &sb) == 0) {
112 fd = open(audiopath, flags, 0);
126 PAUDIO_WaitDevice(
_THIS)
131 if (this->hidden->frame_ticks) {
140 audio_buffer paud_bufinfo;
145 FD_SET(this->hidden->audio_fd, &fdset);
147 if (ioctl(this->hidden->audio_fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
149 fprintf(stderr,
"Couldn't get audio buffer information\n");
154 long ms_in_buf = paud_bufinfo.write_buf_time;
155 timeout.tv_sec = ms_in_buf / 1000;
156 ms_in_buf = ms_in_buf -
timeout.tv_sec * 1000;
157 timeout.tv_usec = ms_in_buf * 1000;
160 "Waiting for write_buf_time=%ld,%ld\n",
166 fprintf(stderr,
"Waiting for audio to get ready\n");
171 "Audio timeout - buggy audio driver? (disabled)";
177 fprintf(stderr,
"SDL: %s - %s\n", strerror(errno), message);
180 this->hidden->audio_fd = -1;
182 fprintf(stderr,
"Done disabling audio\n");
186 fprintf(stderr,
"Ready!\n");
192 PAUDIO_PlayDevice(
_THIS)
195 const Uint8 *mixbuf = this->hidden->mixbuf;
196 const size_t mixlen = this->hidden->mixlen;
200 written = write(this->hidden->audio_fd, mixbuf, mixlen);
201 if ((written < 0) && ((errno == 0) || (errno == EAGAIN))) {
204 }
while ((written < 0) &&
205 ((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
208 if (this->hidden->frame_ticks) {
209 this->hidden->next_frame += this->hidden->frame_ticks;
217 fprintf(stderr,
"Wrote %d bytes of audio data\n", written);
222 PAUDIO_GetDeviceBuf(
_THIS)
224 return this->hidden->mixbuf;
228 PAUDIO_CloseDevice(
_THIS)
230 if (this->hidden->audio_fd >= 0) {
231 close(this->hidden->audio_fd);
238 PAUDIO_OpenDevice(
_THIS,
void *handle,
const char *devname,
int iscapture)
240 const char *workaround =
SDL_getenv(
"SDL_DSP_NOSELECT");
242 const char *err =
NULL;
244 int bytes_per_sample;
246 audio_init paud_init;
247 audio_buffer paud_bufinfo;
248 audio_status paud_status;
249 audio_control paud_control;
250 audio_change paud_change;
256 if (this->hidden ==
NULL) {
262 fd = OpenAudioPath(audiodev,
sizeof(audiodev), OPEN_FLAGS, 0);
263 this->hidden->audio_fd = fd;
265 return SDL_SetError(
"Couldn't open %s: %s", audiodev, strerror(errno));
272 if (ioctl(fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
273 return SDL_SetError(
"Couldn't get audio buffer information");
327 paud_init.mode = PCM;
328 paud_init.operation = PLAY;
334 !format && test_format;) {
336 fprintf(stderr,
"Trying format 0x%4.4x\n", test_format);
338 switch (test_format) {
340 bytes_per_sample = 1;
341 paud_init.bits_per_sample = 8;
342 paud_init.flags = TWOS_COMPLEMENT | FIXED;
346 bytes_per_sample = 1;
347 paud_init.bits_per_sample = 8;
348 paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED;
352 bytes_per_sample = 2;
353 paud_init.bits_per_sample = 16;
354 paud_init.flags = SIGNED | TWOS_COMPLEMENT | FIXED;
358 bytes_per_sample = 2;
359 paud_init.bits_per_sample = 16;
360 paud_init.flags = BIG_ENDIAN | SIGNED | TWOS_COMPLEMENT | FIXED;
364 bytes_per_sample = 2;
365 paud_init.bits_per_sample = 16;
366 paud_init.flags = TWOS_COMPLEMENT | FIXED;
370 bytes_per_sample = 2;
371 paud_init.bits_per_sample = 16;
372 paud_init.flags = BIG_ENDIAN | TWOS_COMPLEMENT | FIXED;
384 fprintf(stderr,
"Couldn't find any hardware audio formats\n");
386 return SDL_SetError(
"Couldn't find any hardware audio formats");
400 if (paud_bufinfo.request_buf_cap == 1) {
407 paud_init.bsize = bytes_per_sample * this->
spec.
channels;
419 if (ioctl(fd, AUDIO_INIT, &paud_init) < 0) {
420 switch (paud_init.rc) {
422 err =
"Couldn't set audio format: DSP can't do play requests";
425 err =
"Couldn't set audio format: DSP can't do record requests";
428 err =
"Couldn't set audio format: request was invalid";
431 err =
"Couldn't set audio format: conflict with open's flags";
434 err =
"Couldn't set audio format: out of DSP MIPS or memory";
437 err =
"Couldn't set audio format: not documented in sys/audio.h";
447 this->hidden->mixlen = this->
spec.
size;
449 if (this->hidden->mixbuf ==
NULL) {
452 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
458 paud_change.input = AUDIO_IGNORE;
459 paud_change.output = OUTPUT_1;
460 paud_change.monitor = AUDIO_IGNORE;
461 paud_change.volume = 0x7fffffff;
462 paud_change.volume_delay = AUDIO_IGNORE;
463 paud_change.balance = 0x3fffffff;
464 paud_change.balance_delay = AUDIO_IGNORE;
465 paud_change.treble = AUDIO_IGNORE;
466 paud_change.bass = AUDIO_IGNORE;
467 paud_change.pitch = AUDIO_IGNORE;
469 paud_control.ioctl_request = AUDIO_CHANGE;
470 paud_control.request_info = (
char *) &paud_change;
471 if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
473 fprintf(stderr,
"Can't change audio display settings\n");
481 paud_control.ioctl_request = AUDIO_START;
482 paud_control.position = 0;
483 if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
485 fprintf(stderr,
"Can't start audio play\n");
491 if (workaround !=
NULL) {
492 this->hidden->frame_ticks = (float) (this->
spec.
samples * 1000) /
494 this->hidden->next_frame =
SDL_GetTicks() + this->hidden->frame_ticks;
505 int fd = OpenAudioPath(
NULL, 0, OPEN_FLAGS, 0);
524 "paud",
"AIX Paudio", PAUDIO_Init, 0
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
SDL_AudioFormat SDL_FirstAudioFormat(SDL_AudioFormat format)
GLuint GLsizei const GLchar * message
void(* PlayDevice)(_THIS)
void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device)
Uint16 SDL_AudioFormat
Audio format flags.
SDL_AudioFormat SDL_NextAudioFormat(void)
int OnlyHasDefaultOutputDevice
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
uint8_t Uint8
An unsigned 8-bit integer type.
AudioBootStrap PAUDIO_bootstrap
void SDL_CalculateAudioSpec(SDL_AudioSpec *spec)
int32_t Sint32
A signed 32-bit integer type.
int(* OpenDevice)(_THIS, void *handle, const char *devname, int iscapture)
#define SDL_OutOfMemory()
void(* CloseDevice)(_THIS)
GLbitfield GLuint64 timeout
Uint8 *(* GetDeviceBuf)(_THIS)
#define SDL_arraysize(array)
GLsizei const GLchar *const * path