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,71 +150,100 @@ AL_CloseAudio(_THIS) ...@@ -149,71 +150,100 @@ 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 16: case AUDIO_S16SYS:
{ /* Signed 16 bit audio data */
spec->format = AUDIO_S16MSB;
width = AL_SAMPLE_16; width = AL_SAMPLE_16;
} fmt = AL_SAMPFMT_TWOSCOMP;
break;
case AUDIO_F32SYS:
width = 0; /* not used here... */
fmt = AL_SAMPFMT_FLOAT;
break; break;
/* Docs say there is int24, but not int32.... */
default: default:
{ valid = 0;
SDL_SetError("Unsupported audio format"); test_format = SDL_NextAudioFormat();
return (-1); break;
}
} }
/* Update the fragment size as size in bytes */ if (valid) {
SDL_CalculateAudioSpec(spec); ALconfig audio_config = alNewConfig();
valid = 0;
/* Set output frequency */ if (audio_config) {
#ifdef OLD_IRIX_AUDIO if (alSetChannels(audio_config, spec->channels) < 0) {
audio_param[0] = AL_OUTPUT_RATE; if (spec->channels > 2) { /* can't handle > stereo? */
audio_param[1] = spec->freq; spec->channels = 2; /* try again below. */
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);
} }
/* Open the audio port with the requested frequency */ if ((alSetSampFmt(audio_config, fmt) >= 0) &&
audio_port = NULL; ((!width) || (alSetWidth(audio_config, width) >= 0)) &&
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) && (alSetQueueSize(audio_config, spec->samples * 2) >= 0) &&
(alSetChannels(audio_config, spec->channels) >= 0)) { (alSetChannels(audio_config, spec->channels) >= 0)) {
audio_port = alOpenPort("SDL audio", "w", audio_config); 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); alFreeConfig(audio_config);
if (audio_port == NULL) { }
SDL_SetError("Unable to open audio port"); }
}
if (!valid) {
SDL_SetError("Unsupported audio format");
return (-1); return (-1);
} }
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);
/* Allocate mixing buffer */ /* Allocate mixing buffer */
mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size); mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size);
if (mixbuf == NULL) { if (mixbuf == NULL) {
......
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