Changed audio subsystem's OpenDevice interface to return -1 on error.

This lets us 'return SDL_SetError("whatever");' on one line.

 Fixes Bugzilla #1778.
This commit is contained in:
Ryan C. Gordon 2013-03-31 13:05:40 -04:00
parent 4f438b70a2
commit 2df4ed556e
21 changed files with 169 additions and 295 deletions

View file

@ -191,7 +191,7 @@ SDL_AudioDeinitialize_Default(void)
static int
SDL_AudioOpenDevice_Default(_THIS, const char *devname, int iscapture)
{
return 0;
return -1;
}
static void
@ -940,7 +940,7 @@ open_audio_device(const char *devname, int iscapture,
((!iscapture) && (current_audio.outputDevices == NULL)) )
SDL_GetNumAudioDevices(iscapture);
if (!current_audio.impl.OpenDevice(device, devname, iscapture)) {
if (current_audio.impl.OpenDevice(device, devname, iscapture) < 0) {
close_audio_device(device);
return 0;
}

View file

@ -482,8 +482,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -495,9 +494,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
if (status < 0) {
ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't open audio device: %s",
ALSA_snd_strerror(status));
return 0;
return SDL_SetError("ALSA: Couldn't open audio device: %s",
ALSA_snd_strerror(status));
}
this->hidden->pcm_handle = pcm_handle;
@ -507,9 +505,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
if (status < 0) {
ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't get hardware config: %s",
ALSA_snd_strerror(status));
return 0;
return SDL_SetError("ALSA: Couldn't get hardware config: %s",
ALSA_snd_strerror(status));
}
/* SDL only uses interleaved sample output */
@ -517,9 +514,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
SND_PCM_ACCESS_RW_INTERLEAVED);
if (status < 0) {
ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't set interleaved access: %s",
return SDL_SetError("ALSA: Couldn't set interleaved access: %s",
ALSA_snd_strerror(status));
return 0;
}
/* Try for a closest match on audio format */
@ -572,8 +568,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
}
if (status < 0) {
ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't find any hardware audio formats");
return 0;
return SDL_SetError("ALSA: Couldn't find any hardware audio formats");
}
this->spec.format = test_format;
@ -585,8 +580,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels);
if (status < 0) {
ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't set audio channels");
return 0;
return SDL_SetError("ALSA: Couldn't set audio channels");
}
this->spec.channels = channels;
}
@ -597,9 +591,8 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
&rate, NULL);
if (status < 0) {
ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't set audio frequency: %s",
ALSA_snd_strerror(status));
return 0;
return SDL_SetError("ALSA: Couldn't set audio frequency: %s",
ALSA_snd_strerror(status));
}
this->spec.freq = rate;
@ -609,8 +602,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
/* Failed to set desired buffer size, do the best you can... */
if ( ALSA_set_period_size(this, hwparams, 1) < 0 ) {
ALSA_CloseDevice(this);
SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status));
return(-1);
return SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status));
}
}
/* Set the software parameters */
@ -618,31 +610,27 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
if (status < 0) {
ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't get software config: %s",
ALSA_snd_strerror(status));
return 0;
return SDL_SetError("ALSA: Couldn't get software config: %s",
ALSA_snd_strerror(status));
}
status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
if (status < 0) {
ALSA_CloseDevice(this);
SDL_SetError("Couldn't set minimum available samples: %s",
ALSA_snd_strerror(status));
return 0;
return SDL_SetError("Couldn't set minimum available samples: %s",
ALSA_snd_strerror(status));
}
status =
ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
if (status < 0) {
ALSA_CloseDevice(this);
SDL_SetError("ALSA: Couldn't set start threshold: %s",
ALSA_snd_strerror(status));
return 0;
return SDL_SetError("ALSA: Couldn't set start threshold: %s",
ALSA_snd_strerror(status));
}
status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
if (status < 0) {
ALSA_CloseDevice(this);
SDL_SetError("Couldn't set software audio parameters: %s",
ALSA_snd_strerror(status));
return 0;
return SDL_SetError("Couldn't set software audio parameters: %s",
ALSA_snd_strerror(status));
}
/* Calculate the final parameters for this audio specification */
@ -653,8 +641,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
ALSA_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
@ -662,7 +649,7 @@ ALSA_OpenDevice(_THIS, const char *devname, int iscapture)
ALSA_snd_pcm_nonblock(pcm_handle, 0);
/* We're ready to rock and roll. :-) */
return 1;
return 0;
}
static void

View file

@ -42,21 +42,18 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture)
if (iscapture) {
//TODO: implement capture
SDL_SetError("Capture not supported on Android");
return 0;
return SDL_SetError("Capture not supported on Android");
}
if (audioDevice != NULL) {
SDL_SetError("Only one audio device at a time please!");
return 0;
return SDL_SetError("Only one audio device at a time please!");
}
audioDevice = this;
this->hidden = SDL_malloc(sizeof(*(this->hidden)));
if (!this->hidden) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -71,8 +68,7 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture)
if (test_format == 0) {
// Didn't find a compatible format :(
SDL_SetError("No compatible audio format!");
return 0;
return SDL_SetError("No compatible audio format!");
}
if (this->spec.channels > 1) {
@ -94,11 +90,10 @@ AndroidAUD_OpenDevice(_THIS, const char *devname, int iscapture)
if (this->spec.samples == 0) {
// Init failed?
SDL_SetError("Java-side initialization failed!");
return 0;
return SDL_SetError("Java-side initialization failed!");
}
return 1;
return 0;
}
static void

View file

@ -241,8 +241,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -271,22 +270,19 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
}
if (format == 0) {
ARTS_CloseDevice(this);
SDL_SetError("Couldn't find any hardware audio formats");
return 0;
return SDL_SetError("Couldn't find any hardware audio formats");
}
this->spec.format = test_format;
if ((rc = SDL_NAME(arts_init) ()) != 0) {
ARTS_CloseDevice(this);
SDL_SetError("Unable to initialize ARTS: %s",
SDL_NAME(arts_error_text) (rc));
return 0;
return SDL_SetError("Unable to initialize ARTS: %s",
SDL_NAME(arts_error_text) (rc));
}
if (!ARTS_Suspend()) {
ARTS_CloseDevice(this);
SDL_SetError("ARTS can not open audio device");
return 0;
return SDL_SetError("ARTS can not open audio device");
}
this->hidden->stream = SDL_NAME(arts_play_stream) (this->spec.freq,
@ -304,8 +300,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec);
if ((0x01 << frag_spec) != this->spec.size) {
ARTS_CloseDevice(this);
SDL_SetError("Fragment size must be a power of two");
return 0;
return SDL_SetError("Fragment size must be a power of two");
}
frag_spec |= 0x00020000; /* two fragments, for low latency */
@ -326,8 +321,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
ARTS_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
@ -335,7 +329,7 @@ ARTS_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->parent = getpid();
/* We're ready to rock and roll. :-) */
return 1;
return 0;
}

View file

@ -95,8 +95,7 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
/* Initialize all variables that we clean on shutdown */
_this->hidden = new SDL_PrivateAudioData;
if (_this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
@ -153,8 +152,7 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
if (!valid_datatype) { /* shouldn't happen, but just in case... */
BEOSAUDIO_CloseDevice(_this);
SDL_SetError("Unsupported audio format");
return 0;
return SDL_SetError("Unsupported audio format");
}
/* Calculate the final parameters for this audio specification */
@ -173,12 +171,11 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
_this->hidden->audio_obj->SetHasData(true);
} else {
BEOSAUDIO_CloseDevice(_this);
SDL_SetError("Unable to start Be audio");
return 0;
return SDL_SetError("Unable to start Be audio");
}
/* We're running! */
return 1;
return 0;
}
static void

View file

@ -239,8 +239,7 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
if (devname == NULL) {
devname = SDL_GetAudioDeviceName(0, iscapture);
if (devname == NULL) {
SDL_SetError("No such audio device");
return 0;
return SDL_SetError("No such audio device");
}
}
@ -248,16 +247,14 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Open the audio device */
this->hidden->audio_fd = open(devname, flags, 0);
if (this->hidden->audio_fd < 0) {
SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
return 0;
return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
}
AUDIO_INITINFO(&info);
@ -269,8 +266,7 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
info.mode = AUMODE_PLAY;
if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
BSDAUDIO_CloseDevice(this);
SDL_SetError("Couldn't put device into play mode");
return 0;
return SDL_SetError("Couldn't put device into play mode");
}
AUDIO_INITINFO(&info);
@ -312,8 +308,7 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
if (!format) {
BSDAUDIO_CloseDevice(this);
SDL_SetError("No supported encoding for 0x%x", this->spec.format);
return 0;
return SDL_SetError("No supported encoding for 0x%x", this->spec.format);
}
this->spec.format = format;
@ -336,15 +331,14 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
BSDAUDIO_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
BSDAUDIO_Status(this);
/* We're ready to rock and roll. :-) */
return (0);
return 0;
}
static int

View file

@ -469,8 +469,7 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return (0);
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -511,8 +510,7 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
if (!valid_datatype) { /* shouldn't happen, but just in case... */
COREAUDIO_CloseDevice(this);
SDL_SetError("Unsupported audio format");
return 0;
return SDL_SetError("Unsupported audio format");
}
strdesc.mBytesPerFrame =
@ -522,10 +520,10 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
if (!prepare_audiounit(this, devname, iscapture, &strdesc)) {
COREAUDIO_CloseDevice(this);
return 0; /* prepare_audiounit() will call SDL_SetError()... */
return -1; /* prepare_audiounit() will call SDL_SetError()... */
}
return 1; /* good to go. */
return 0; /* good to go. */
}
static int

View file

@ -363,8 +363,7 @@ CreateSecondary(_THIS, HWND focus, WAVEFORMATEX * wavefmt)
DSSCL_NORMAL);
}
if (result != DS_OK) {
SetDSerror("DirectSound SetCooperativeLevel", result);
return (-1);
return SetDSerror("DirectSound SetCooperativeLevel", result);
}
/* Try to create the secondary buffer */
@ -449,8 +448,7 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture)
pDirectSoundEnumerateW(FindDevGUID, &devguid);
if (!devguid.found) {
SDL_SetError("DirectSound: Requested device not found");
return 0;
return SDL_SetError("DirectSound: Requested device not found");
}
guid = &devguid.guid;
}
@ -459,8 +457,7 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -478,8 +475,7 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture)
if (!valid_format) {
DSOUND_CloseDevice(this);
SDL_SetError("DirectSound: Unsupported audio format");
return 0;
return SDL_SetError("DirectSound: Unsupported audio format");
}
SDL_memset(&waveformat, 0, sizeof(waveformat));
@ -499,21 +495,20 @@ DSOUND_OpenDevice(_THIS, const char *devname, int iscapture)
result = pDirectSoundCreate8(guid, &this->hidden->sound, NULL);
if (result != DS_OK) {
DSOUND_CloseDevice(this);
SetDSerror("DirectSoundCreate", result);
return 0;
return SetDSerror("DirectSoundCreate", result);
}
/* Create the audio buffer to which we write */
this->hidden->num_buffers = CreateSecondary(this, NULL, &waveformat);
if (this->hidden->num_buffers < 0) {
DSOUND_CloseDevice(this);
return 0;
return -1;
}
/* The buffer will auto-start playing in DSOUND_WaitDevice() */
this->hidden->mixlen = this->spec.size;
return 1; /* good to go. */
return 0; /* good to go. */
}

View file

@ -110,8 +110,7 @@ DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc(sizeof(*this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, sizeof(*this->hidden));
@ -119,14 +118,14 @@ DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->output = SDL_RWFromFile(fname, "wb");
if (this->hidden->output == NULL) {
DISKAUD_CloseDevice(this);
return 0;
return -1;
}
/* Allocate mixing buffer */
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
DISKAUD_CloseDevice(this);
return 0;
return -1;
}
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
@ -141,7 +140,7 @@ DISKAUD_OpenDevice(_THIS, const char *devname, int iscapture)
#endif
/* We're ready to rock and roll. :-) */
return 1;
return 0;
}
static int

View file

@ -89,8 +89,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
if (devname == NULL) {
devname = SDL_GetAudioDeviceName(0, iscapture);
if (devname == NULL) {
SDL_SetError("No such audio device");
return 0;
return SDL_SetError("No such audio device");
}
}
@ -107,8 +106,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -116,8 +114,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->audio_fd = open(devname, flags, 0);
if (this->hidden->audio_fd < 0) {
DSP_CloseDevice(this);
SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
return 0;
return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
}
this->hidden->mixbuf = NULL;
@ -128,8 +125,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
ctlflags &= ~O_NONBLOCK;
if (fcntl(this->hidden->audio_fd, F_SETFL, ctlflags) < 0) {
DSP_CloseDevice(this);
SDL_SetError("Couldn't set audio blocking mode");
return 0;
return SDL_SetError("Couldn't set audio blocking mode");
}
}
@ -137,8 +133,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
perror("SNDCTL_DSP_GETFMTS");
DSP_CloseDevice(this);
SDL_SetError("Couldn't get audio format list");
return 0;
return SDL_SetError("Couldn't get audio format list");
}
/* Try for a closest match on audio format */
@ -195,8 +190,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
}
if (format == 0) {
DSP_CloseDevice(this);
SDL_SetError("Couldn't find any hardware audio formats");
return 0;
return SDL_SetError("Couldn't find any hardware audio formats");
}
this->spec.format = test_format;
@ -206,8 +200,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
(value != format)) {
perror("SNDCTL_DSP_SETFMT");
DSP_CloseDevice(this);
SDL_SetError("Couldn't set audio format");
return 0;
return SDL_SetError("Couldn't set audio format");
}
/* Set the number of channels of output */
@ -215,8 +208,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
perror("SNDCTL_DSP_CHANNELS");
DSP_CloseDevice(this);
SDL_SetError("Cannot set the number of channels");
return 0;
return SDL_SetError("Cannot set the number of channels");
}
this->spec.channels = value;
@ -225,8 +217,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
perror("SNDCTL_DSP_SPEED");
DSP_CloseDevice(this);
SDL_SetError("Couldn't set audio frequency");
return 0;
return SDL_SetError("Couldn't set audio frequency");
}
this->spec.freq = value;
@ -237,8 +228,7 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec);
if ((0x01U << frag_spec) != this->spec.size) {
DSP_CloseDevice(this);
SDL_SetError("Fragment size must be a power of two");
return 0;
return SDL_SetError("Fragment size must be a power of two");
}
frag_spec |= 0x00020000; /* two fragments, for low latency */
@ -266,13 +256,12 @@ DSP_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
DSP_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
/* We're ready to rock and roll. :-) */
return 1;
return 0;
}

View file

@ -29,7 +29,7 @@
static int
DUMMYAUD_OpenDevice(_THIS, const char *devname, int iscapture)
{
return 1; /* always succeeds. */
return 0; /* always succeeds. */
}
static int

View file

@ -228,8 +228,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
this->hidden->audio_fd = -1;
@ -257,8 +256,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture)
if (!found) {
ESD_CloseDevice(this);
SDL_SetError("Couldn't find any hardware audio formats");
return 0;
return SDL_SetError("Couldn't find any hardware audio formats");
}
if (this->spec.channels == 1) {
@ -277,8 +275,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture)
if (this->hidden->audio_fd < 0) {
ESD_CloseDevice(this);
SDL_SetError("Couldn't open ESD connection");
return 0;
return SDL_SetError("Couldn't open ESD connection");
}
/* Calculate the final parameters for this audio specification */
@ -292,8 +289,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
ESD_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
@ -301,7 +297,7 @@ ESD_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->parent = getpid();
/* We're ready to rock and roll. :-) */
return 1;
return 0;
}
static void

View file

@ -200,8 +200,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -243,8 +242,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture)
if (format == 0) {
SDL_FS_CloseDevice(this);
SDL_SetError("Couldn't find any hardware audio formats");
return 0;
return SDL_SetError("Couldn't find any hardware audio formats");
}
this->spec.format = test_format;
@ -252,8 +250,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture)
ret = SDL_NAME(FusionSoundCreate) (&this->hidden->fs);
if (ret) {
SDL_FS_CloseDevice(this);
SDL_SetError("Unable to initialize FusionSound: %d", ret);
return 0;
return SDL_SetError("Unable to initialize FusionSound: %d", ret);
}
this->hidden->mixsamples = this->spec.size / bytes / this->spec.channels;
@ -272,8 +269,7 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture)
&this->hidden->stream);
if (ret) {
SDL_FS_CloseDevice(this);
SDL_SetError("Unable to create FusionSoundStream: %d", ret);
return 0;
return SDL_SetError("Unable to create FusionSoundStream: %d", ret);
}
/* See what we got */
@ -294,13 +290,12 @@ SDL_FS_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
SDL_FS_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
/* We're ready to rock and roll. :-) */
return 1;
return 0;
}

View file

@ -288,8 +288,7 @@ NAS_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -304,24 +303,21 @@ NAS_OpenDevice(_THIS, const char *devname, int iscapture)
}
if (format == 0) {
NAS_CloseDevice(this);
SDL_SetError("NAS: Couldn't find any hardware audio formats");
return 0;
return SDL_SetError("NAS: Couldn't find any hardware audio formats");
}
this->spec.format = test_format;
this->hidden->aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL);
if (this->hidden->aud == 0) {
NAS_CloseDevice(this);
SDL_SetError("NAS: Couldn't open connection to NAS server");
return 0;
return SDL_SetError("NAS: Couldn't open connection to NAS server");
}
this->hidden->dev = find_device(this, this->spec.channels);
if ((this->hidden->dev == AuNone)
|| (!(this->hidden->flow = NAS_AuCreateFlow(this->hidden->aud, 0)))) {
NAS_CloseDevice(this);
SDL_SetError("NAS: Couldn't find a fitting device on NAS server");
return 0;
return SDL_SetError("NAS: Couldn't find a fitting device on NAS server");
}
buffer_size = this->spec.freq;
@ -354,13 +350,12 @@ NAS_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
NAS_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
/* We're ready to rock and roll. :-) */
return 1;
return 0;
}
static void

View file

@ -264,8 +264,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -274,8 +273,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->audio_fd = fd;
if (fd < 0) {
PAUDIO_CloseDevice(this);
SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
return 0;
return SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
}
/*
@ -284,8 +282,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
*/
if (ioctl(fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
PAUDIO_CloseDevice(this);
SDL_SetError("Couldn't get audio buffer information");
return 0;
return SDL_SetError("Couldn't get audio buffer information");
}
if (this->spec.channels > 1)
@ -399,8 +396,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
fprintf(stderr, "Couldn't find any hardware audio formats\n");
#endif
PAUDIO_CloseDevice(this);
SDL_SetError("Couldn't find any hardware audio formats");
return 0;
return SDL_SetError("Couldn't find any hardware audio formats");
}
this->spec.format = test_format;
@ -458,8 +454,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
if (err != NULL) {
PAUDIO_CloseDevice(this);
SDL_SetError("Paudio: %s", err);
return 0;
return SDL_SetError("Paudio: %s", err);
}
/* Allocate mixing buffer */
@ -467,8 +462,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
PAUDIO_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
@ -506,8 +500,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
#ifdef DEBUG_AUDIO
fprintf(stderr, "Can't start audio play\n");
#endif
SDL_SetError("Can't start audio play");
return 0;
return SDL_SetError("Can't start audio play");
}
/* Check to see if we need to use select() workaround */
@ -518,7 +511,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
}
/* We're ready to rock and roll. :-) */
return 1;
return 0;
}
static int

View file

@ -46,8 +46,7 @@ PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc(sizeof(*this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, sizeof(*this->hidden));
switch (this->spec.format & 0xff) {
@ -56,8 +55,7 @@ PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture)
this->spec.format = AUDIO_S16LSB;
break;
default:
SDL_SetError("Unsupported audio format");
return 0;
return SDL_SetError("Unsupported audio format");
}
/* The sample count must be a multiple of 64. */
@ -86,8 +84,7 @@ PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture)
mixlen = this->spec.size * NUM_BUFFERS;
this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
if (this->hidden->rawbuf == NULL) {
SDL_SetError("Couldn't allocate mixing buffer");
return 0;
return SDL_SetError("Couldn't allocate mixing buffer");
}
/* Setup the hardware channel. */
@ -98,10 +95,9 @@ PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture)
}
this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format);
if (this->hidden->channel < 0) {
SDL_SetError("Couldn't reserve hardware channel");
free(this->hidden->rawbuf);
this->hidden->rawbuf = NULL;
return 0;
return SDL_SetError("Couldn't reserve hardware channel");
}
memset(this->hidden->rawbuf, 0, mixlen);
@ -110,7 +106,7 @@ PSPAUD_OpenDevice(_THIS, const char *devname, int iscapture)
}
this->hidden->next_buffer = 0;
return 1;
return 0;
}
static void PSPAUD_PlayDevice(_THIS)

View file

@ -337,8 +337,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
h = this->hidden;
@ -371,8 +370,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
}
if (paspec.format == PA_SAMPLE_INVALID) {
PULSEAUDIO_CloseDevice(this);
SDL_SetError("Couldn't find any hardware audio formats");
return 0;
return SDL_SetError("Couldn't find any hardware audio formats");
}
this->spec.format = test_format;
@ -387,8 +385,7 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
h->mixbuf = (Uint8 *) SDL_AllocAudioMem(h->mixlen);
if (h->mixbuf == NULL) {
PULSEAUDIO_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(h->mixbuf, this->spec.silence, this->spec.size);
@ -419,36 +416,31 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
/* Set up a new main loop */
if (!(h->mainloop = PULSEAUDIO_pa_mainloop_new())) {
PULSEAUDIO_CloseDevice(this);
SDL_SetError("pa_mainloop_new() failed");
return 0;
return SDL_SetError("pa_mainloop_new() failed");
}
h->mainloop_api = PULSEAUDIO_pa_mainloop_get_api(h->mainloop);
h->context = PULSEAUDIO_pa_context_new(h->mainloop_api, NULL);
if (!h->context) {
PULSEAUDIO_CloseDevice(this);
SDL_SetError("pa_context_new() failed");
return 0;
return SDL_SetError("pa_context_new() failed");
}
/* Connect to the PulseAudio server */
if (PULSEAUDIO_pa_context_connect(h->context, NULL, 0, NULL) < 0) {
PULSEAUDIO_CloseDevice(this);
SDL_SetError("Could not setup connection to PulseAudio");
return 0;
return SDL_SetError("Could not setup connection to PulseAudio");
}
do {
if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
PULSEAUDIO_CloseDevice(this);
SDL_SetError("pa_mainloop_iterate() failed");
return 0;
return SDL_SetError("pa_mainloop_iterate() failed");
}
state = PULSEAUDIO_pa_context_get_state(h->context);
if (!PA_CONTEXT_IS_GOOD(state)) {
PULSEAUDIO_CloseDevice(this);
SDL_SetError("Could not connect to PulseAudio");
return 0;
return SDL_SetError("Could not connect to PulseAudio");
}
} while (state != PA_CONTEXT_READY);
@ -461,33 +453,29 @@ PULSEAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
if (h->stream == NULL) {
PULSEAUDIO_CloseDevice(this);
SDL_SetError("Could not set up PulseAudio stream");
return 0;
return SDL_SetError("Could not set up PulseAudio stream");
}
if (PULSEAUDIO_pa_stream_connect_playback(h->stream, NULL, &paattr, flags,
NULL, NULL) < 0) {
PULSEAUDIO_CloseDevice(this);
SDL_SetError("Could not connect PulseAudio stream");
return 0;
return SDL_SetError("Could not connect PulseAudio stream");
}
do {
if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
PULSEAUDIO_CloseDevice(this);
SDL_SetError("pa_mainloop_iterate() failed");
return 0;
return SDL_SetError("pa_mainloop_iterate() failed");
}
state = PULSEAUDIO_pa_stream_get_state(h->stream);
if (!PA_STREAM_IS_GOOD(state)) {
PULSEAUDIO_CloseDevice(this);
SDL_SetError("Could not create to PulseAudio stream");
return 0;
return SDL_SetError("Could not create to PulseAudio stream");
}
} while (state != PA_STREAM_READY);
/* We're ready to rock and roll. :-) */
return 1;
return 0;
}

View file

@ -83,10 +83,10 @@ uint32_t qsa_playback_devices;
QSA_Device qsa_capture_device[QSA_MAX_DEVICES];
uint32_t qsa_capture_devices;
static inline void
static inline int
QSA_SetError(const char *fn, int status)
{
SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status));
return SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status));
}
/* card names check to apply the workarounds */
@ -183,13 +183,13 @@ QSA_WaitDevice(_THIS)
switch (selectret) {
case -1:
{
SDL_SetError("QSA: select() failed: %s\n", strerror(errno));
SDL_SetError("QSA: select() failed: %s", strerror(errno));
return;
}
break;
case 0:
{
SDL_SetError("QSA: timeout on buffer waiting occured\n");
SDL_SetError("QSA: timeout on buffer waiting occured");
this->hidden->timeout_on_wait = 1;
return;
}
@ -237,7 +237,7 @@ QSA_PlayDevice(_THIS)
/* the audio device driver */
if ((errno == EAGAIN) && (written == 0)) {
if (this->hidden->timeout_on_wait != 0) {
SDL_SetError("QSA: buffer playback timeout\n");
SDL_SetError("QSA: buffer playback timeout");
return;
}
}
@ -355,8 +355,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
(struct
SDL_PrivateAudioData)));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
@ -384,8 +383,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
device++;
if (device >= qsa_playback_devices) {
QSA_CloseDevice(this);
SDL_SetError("No such playback device");
return 0;
return SDL_SetError("No such playback device");
}
} while (1);
}
@ -409,8 +407,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
device++;
if (device >= qsa_capture_devices) {
QSA_CloseDevice(this);
SDL_SetError("No such capture device");
return 0;
return SDL_SetError("No such capture device");
}
} while (1);
}
@ -448,8 +445,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
if (status < 0) {
this->hidden->audio_handle = NULL;
QSA_CloseDevice(this);
QSA_SetError("snd_pcm_open", status);
return 0;
return QSA_SetError("snd_pcm_open", status);
}
if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) {
@ -459,8 +455,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
PLUGIN_DISABLE_MMAP);
if (status < 0) {
QSA_CloseDevice(this);
QSA_SetError("snd_pcm_plugin_set_disable", status);
return 0;
return QSA_SetError("snd_pcm_plugin_set_disable", status);
}
}
@ -546,8 +541,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
/* assumes test_format not 0 on success */
if (test_format == 0) {
QSA_CloseDevice(this);
SDL_SetError("QSA: Couldn't find any hardware audio formats");
return 0;
return SDL_SetError("QSA: Couldn't find any hardware audio formats");
}
this->spec.format = test_format;
@ -565,8 +559,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
if (status < 0) {
QSA_CloseDevice(this);
QSA_SetError("snd_pcm_channel_params", status);
return 0;
return QSA_SetError("snd_pcm_channel_params", status);
}
/* Make sure channel is setup right one last time */
@ -580,8 +573,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
/* Setup an audio channel */
if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
QSA_CloseDevice(this);
SDL_SetError("QSA: Unable to setup channel\n");
return 0;
return SDL_SetError("QSA: Unable to setup channel");
}
/* Calculate the final parameters for this audio specification */
@ -604,8 +596,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
(Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len);
if (this->hidden->pcm_buf == NULL) {
QSA_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden->pcm_buf, this->spec.silence,
this->hidden->pcm_len);
@ -623,8 +614,7 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
if (this->hidden->audio_fd < 0) {
QSA_CloseDevice(this);
QSA_SetError("snd_pcm_file_descriptor", status);
return 0;
return QSA_SetError("snd_pcm_file_descriptor", status);
}
/* Prepare an audio channel */
@ -642,12 +632,11 @@ QSA_OpenDevice(_THIS, const char *devname, int iscapture)
if (status < 0) {
QSA_CloseDevice(this);
QSA_SetError("snd_pcm_plugin_prepare", status);
return 0;
return QSA_SetError("snd_pcm_plugin_prepare", status);
}
/* We're really ready to rock and roll. :-) */
return 1;
return 0;
}
static void

View file

@ -213,8 +213,7 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
if (devname == NULL) {
devname = SDL_GetAudioDeviceName(0, iscapture);
if (devname == NULL) {
SDL_SetError("No such audio device");
return 0;
return SDL_SetError("No such audio device");
}
}
@ -222,16 +221,14 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Open the audio device */
this->hidden->audio_fd = open(devname, flags, 0);
if (this->hidden->audio_fd < 0) {
SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
return 0;
return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
}
#ifdef AUDIO_SETINFO
@ -263,8 +260,7 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
default:
{
/* !!! FIXME: fallback to conversion on unsupported types! */
SDL_SetError("Unsupported audio format");
return (-1);
return SDL_SetError("Unsupported audio format");
}
}
this->hidden->audio_fmt = this->spec.format;
@ -285,9 +281,8 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
/* Check to be sure we got what we wanted */
if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
SDL_SetError("Error getting audio parameters: %s",
strerror(errno));
return -1;
return SDL_SetError("Error getting audio parameters: %s",
strerror(errno));
}
if (info.play.encoding == enc
&& info.play.precision == (this->spec.format & 0xff)
@ -316,9 +311,8 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
default:
/* oh well... */
SDL_SetError("Error setting audio parameters: %s",
strerror(errno));
return -1;
return SDL_SetError("Error setting audio parameters: %s",
strerror(errno));
}
}
#endif /* AUDIO_SETINFO */
@ -357,7 +351,7 @@ SUNAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
/* We're ready to rock and roll. :-) */
return (1);
return 0;
}
/************************************************************************/

View file

@ -91,7 +91,7 @@ FillSound(HWAVEOUT hwo, UINT uMsg, DWORD_PTR dwInstance,
ReleaseSemaphore(this->hidden->audio_sem, 1, NULL);
}
static void
static int
SetMMerror(char *function, MMRESULT code)
{
size_t len;
@ -105,7 +105,7 @@ SetMMerror(char *function, MMRESULT code)
WideCharToMultiByte(CP_ACP, 0, werrbuf, -1, errbuf + len,
MAXERRORLENGTH - len, NULL, NULL);
SDL_SetError("%s", errbuf);
return SDL_SetError("%s", errbuf);
}
static void
@ -234,8 +234,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture)
}
if (devId == WAVE_MAPPER) {
SDL_SetError("Requested device not found");
return 0;
return SDL_SetError("Requested device not found");
}
}
@ -243,8 +242,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -270,8 +268,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture)
if (!valid_datatype) {
WINMM_CloseDevice(this);
SDL_SetError("Unsupported audio format");
return 0;
return SDL_SetError("Unsupported audio format");
}
/* Set basic WAVE format parameters */
@ -309,8 +306,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture)
if (result != MMSYSERR_NOERROR) {
WINMM_CloseDevice(this);
SetMMerror("waveOutOpen()", result);
return 0;
return SetMMerror("waveOutOpen()", result);
}
#ifdef SOUND_DEBUG
/* Check the sound device we retrieved */
@ -321,8 +317,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture)
&caps, sizeof(caps));
if (result != MMSYSERR_NOERROR) {
WINMM_CloseDevice(this);
SetMMerror("waveOutGetDevCaps()", result);
return 0;
return SetMMerror("waveOutGetDevCaps()", result);
}
printf("Audio device: %s\n", caps.szPname);
}
@ -333,8 +328,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture)
CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL);
if (this->hidden->audio_sem == NULL) {
WINMM_CloseDevice(this);
SDL_SetError("Couldn't create semaphore");
return 0;
return SDL_SetError("Couldn't create semaphore");
}
/* Create the sound buffers */
@ -342,8 +336,7 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture)
(Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
if (this->hidden->mixbuf == NULL) {
WINMM_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
for (i = 0; i < NUM_BUFFERS; ++i) {
SDL_memset(&this->hidden->wavebuf[i], 0,
@ -357,12 +350,11 @@ WINMM_OpenDevice(_THIS, const char *devname, int iscapture)
sizeof(this->hidden->wavebuf[i]));
if (result != MMSYSERR_NOERROR) {
WINMM_CloseDevice(this);
SetMMerror("waveOutPrepareHeader()", result);
return 0;
return SetMMerror("waveOutPrepareHeader()", result);
}
}
return 1; /* Ready to go! */
return 0; /* Ready to go! */
}

View file

@ -245,11 +245,9 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
static IXAudio2VoiceCallback callbacks = { &callbacks_vtable };
if (iscapture) {
SDL_SetError("XAudio2: capture devices unsupported.");
return 0;
return SDL_SetError("XAudio2: capture devices unsupported.");
} else if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
SDL_SetError("XAudio2: XAudio2Create() failed.");
return 0;
return SDL_SetError("XAudio2: XAudio2Create() failed.");
}
if (devname != NULL) {
@ -258,8 +256,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
if (IXAudio2_GetDeviceCount(ixa2, &devcount) != S_OK) {
IXAudio2_Release(ixa2);
SDL_SetError("XAudio2: IXAudio2_GetDeviceCount() failed.");
return 0;
return SDL_SetError("XAudio2: IXAudio2_GetDeviceCount() failed.");
}
for (i = 0; i < devcount; i++) {
XAUDIO2_DEVICE_DETAILS details;
@ -278,8 +275,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
if (i == devcount) {
IXAudio2_Release(ixa2);
SDL_SetError("XAudio2: Requested device not found.");
return 0;
return SDL_SetError("XAudio2: Requested device not found.");
}
}
@ -288,8 +284,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
IXAudio2_Release(ixa2);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
@ -297,8 +292,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->semaphore = CreateSemaphore(NULL, 1, 2, NULL);
if (this->hidden->semaphore == NULL) {
XAUDIO2_CloseDevice(this);
SDL_SetError("XAudio2: CreateSemaphore() failed!");
return 0;
return SDL_SetError("XAudio2: CreateSemaphore() failed!");
}
while ((!valid_format) && (test_format)) {
@ -316,8 +310,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
if (!valid_format) {
XAUDIO2_CloseDevice(this);
SDL_SetError("XAudio2: Unsupported audio format");
return 0;
return SDL_SetError("XAudio2: Unsupported audio format");
}
/* Update the fragment size as size in bytes */
@ -328,8 +321,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->mixbuf = (Uint8 *) SDL_malloc(2 * this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
XAUDIO2_CloseDevice(this);
SDL_OutOfMemory();
return 0;
return SDL_OutOfMemory();
}
this->hidden->nextbuf = this->hidden->mixbuf;
SDL_memset(this->hidden->mixbuf, 0, 2 * this->hidden->mixlen);
@ -345,8 +337,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
this->spec.freq, 0, devId, NULL);
if (result != S_OK) {
XAUDIO2_CloseDevice(this);
SDL_SetError("XAudio2: Couldn't create mastering voice");
return 0;
return SDL_SetError("XAudio2: Couldn't create mastering voice");
}
SDL_zero(waveformat);
@ -369,8 +360,7 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
1.0f, &callbacks, NULL, NULL);
if (result != S_OK) {
XAUDIO2_CloseDevice(this);
SDL_SetError("XAudio2: Couldn't create source voice");
return 0;
return SDL_SetError("XAudio2: Couldn't create source voice");
}
this->hidden->source = source;
@ -378,18 +368,16 @@ XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
result = IXAudio2_StartEngine(ixa2);
if (result != S_OK) {
XAUDIO2_CloseDevice(this);
SDL_SetError("XAudio2: Couldn't start engine");
return 0;
return SDL_SetError("XAudio2: Couldn't start engine");
}
result = IXAudio2SourceVoice_Start(source, 0, XAUDIO2_COMMIT_NOW);
if (result != S_OK) {
XAUDIO2_CloseDevice(this);
SDL_SetError("XAudio2: Couldn't start source voice");
return 0;
return SDL_SetError("XAudio2: Couldn't start source voice");
}
return 1; /* good to go. */
return 0; /* good to go. */
}
static void