Commit 3e4e1371 authored by Ryan C. Gordon's avatar Ryan C. Gordon

Cleaned up IRIX audio driver, added float32 support and fallbacks when

 a specific audiospec isn't supported or the hardware fails.

Usual disclaimer: No IRIX box, so this may not even compile.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402049
parent bb7ad968
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
Sam Lantinga Sam Lantinga
slouken@libsdl.org slouken@libsdl.org
*/ */
#include <errno.h>
#include "SDL_config.h" #include "SDL_config.h"
/* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */ /* Allow access to a raw mixing buffer (For IRIX 6.5 and higher) */
...@@ -149,70 +150,99 @@ AL_CloseAudio(_THIS) ...@@ -149,70 +150,99 @@ AL_CloseAudio(_THIS)
static int static int
AL_OpenAudio(_THIS, SDL_AudioSpec * spec) AL_OpenAudio(_THIS, SDL_AudioSpec * spec)
{ {
ALconfig audio_config; SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
long width = 0;
long fmt = 0;
int valid = 0;
#ifdef OLD_IRIX_AUDIO #ifdef OLD_IRIX_AUDIO
long audio_param[2]; {
long audio_param[2];
audio_param[0] = AL_OUTPUT_RATE;
audio_param[1] = spec->freq;
valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0);
}
#else #else
ALpv audio_param; {
ALpv audio_param;
audio_param.param = AL_RATE;
audio_param.value.i = spec->freq;
valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0);
}
#endif #endif
int width;
/* Determine the audio parameters from the AudioSpec */ while ((!valid) && (test_format)) {
switch (spec->format & 0xFF) { valid = 1;
spec->format = test_format;
case 8: switch (test_format) {
{ /* Signed 8 bit audio data */ case AUDIO_S8:
spec->format = AUDIO_S8; width = AL_SAMPLE_8;
width = AL_SAMPLE_8; fmt = AL_SAMPFMT_TWOSCOMP;
} break;
break;
case AUDIO_S16SYS:
width = AL_SAMPLE_16;
fmt = AL_SAMPFMT_TWOSCOMP;
break;
case 16: case AUDIO_F32SYS:
{ /* Signed 16 bit audio data */ width = 0; /* not used here... */
spec->format = AUDIO_S16MSB; fmt = AL_SAMPFMT_FLOAT;
width = AL_SAMPLE_16; break;
/* Docs say there is int24, but not int32.... */
default:
valid = 0;
test_format = SDL_NextAudioFormat();
break;
} }
break;
default: if (valid) {
{ ALconfig audio_config = alNewConfig();
SDL_SetError("Unsupported audio format"); valid = 0;
return (-1); if (audio_config) {
if (alSetChannels(audio_config, spec->channels) < 0) {
if (spec->channels > 2) { /* can't handle > stereo? */
spec->channels = 2; /* try again below. */
}
}
if ((alSetSampFmt(audio_config, fmt) >= 0) &&
((!width) || (alSetWidth(audio_config, width) >= 0)) &&
(alSetQueueSize(audio_config, spec->samples * 2) >= 0) &&
(alSetChannels(audio_config, spec->channels) >= 0)) {
audio_port = alOpenPort("SDL audio", "w", audio_config);
if (audio_port == NULL) {
/* docs say AL_BAD_CHANNELS happens here, too. */
int err = oserror();
if (err == AL_BAD_CHANNELS) {
spec->channels = 2;
alSetChannels(audio_config, spec->channels);
audio_port = alOpenPort("SDL audio", "w",
audio_config);
}
}
if (audio_port != NULL) {
valid = 1;
}
}
alFreeConfig(audio_config);
}
} }
} }
/* Update the fragment size as size in bytes */ if (!valid) {
SDL_CalculateAudioSpec(spec); SDL_SetError("Unsupported audio format");
/* Set output frequency */
#ifdef OLD_IRIX_AUDIO
audio_param[0] = AL_OUTPUT_RATE;
audio_param[1] = spec->freq;
if (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0) {
#else
audio_param.param = AL_RATE;
audio_param.value.i = spec->freq;
if (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0) {
#endif
SDL_SetError("alSetParams failed");
return (-1); return (-1);
} }
/* Open the audio port with the requested frequency */ /* Update the fragment size as size in bytes */
audio_port = NULL; SDL_CalculateAudioSpec(spec);
audio_config = alNewConfig();
if (audio_config &&
(alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) &&
(alSetWidth(audio_config, width) >= 0) &&
(alSetQueueSize(audio_config, spec->samples * 2) >= 0) &&
(alSetChannels(audio_config, spec->channels) >= 0)) {
audio_port = alOpenPort("SDL audio", "w", audio_config);
}
alFreeConfig(audio_config);
if (audio_port == NULL) {
SDL_SetError("Unable to open audio port");
return (-1);
}
/* Allocate mixing buffer */ /* Allocate mixing buffer */
mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size); mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment