mirror of https://github.com/encounter/SDL.git
audio: Clean up some CloseDevice() interface details.
- It's now always called if device->hidden isn't NULL, even if OpenDevice() failed halfway through. This lets implementation code not have to clean up itself on every possible failure point; just return an error and SDL will handle it for you. - Implementations can assume this->hidden != NULL and not check for it. - implementations don't have to set this->hidden = NULL when done, because the caller is always about to free(this). - Don't reset other fields that are in a block of memory about to be free()'d. - Implementations all now free things like internal mix buffers last, after closing devices and such, to guarantee they definitely aren't in use anymore at the point of deallocation.
This commit is contained in:
parent
30a9139bc3
commit
9b64772775
|
@ -982,9 +982,8 @@ close_audio_device(SDL_AudioDevice * device)
|
||||||
if (device->convert.needed) {
|
if (device->convert.needed) {
|
||||||
SDL_FreeAudioMem(device->convert.buf);
|
SDL_FreeAudioMem(device->convert.buf);
|
||||||
}
|
}
|
||||||
if (device->opened) {
|
if (device->hidden != NULL) {
|
||||||
current_audio.impl.CloseDevice(device);
|
current_audio.impl.CloseDevice(device);
|
||||||
device->opened = SDL_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free_audio_queue(device->buffer_queue_head);
|
free_audio_queue(device->buffer_queue_head);
|
||||||
|
@ -1193,7 +1192,10 @@ open_audio_device(const char *devname, int iscapture,
|
||||||
close_audio_device(device);
|
close_audio_device(device);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
device->opened = SDL_TRUE;
|
|
||||||
|
/* if your target really doesn't need it, set it to 0x1 or something. */
|
||||||
|
/* otherwise, close_audio_device() won't call impl.CloseDevice(). */
|
||||||
|
SDL_assert(device->hidden != NULL);
|
||||||
|
|
||||||
/* See if we need to do any conversion */
|
/* See if we need to do any conversion */
|
||||||
build_cvt = SDL_FALSE;
|
build_cvt = SDL_FALSE;
|
||||||
|
|
|
@ -162,7 +162,6 @@ struct SDL_AudioDevice
|
||||||
SDL_atomic_t shutdown; /* true if we are signaling the play thread to end. */
|
SDL_atomic_t shutdown; /* true if we are signaling the play thread to end. */
|
||||||
SDL_atomic_t enabled; /* true if device is functioning and connected. */
|
SDL_atomic_t enabled; /* true if device is functioning and connected. */
|
||||||
SDL_atomic_t paused;
|
SDL_atomic_t paused;
|
||||||
SDL_bool opened;
|
|
||||||
SDL_bool iscapture;
|
SDL_bool iscapture;
|
||||||
|
|
||||||
/* Fake audio buffer for when the audio hardware is busy */
|
/* Fake audio buffer for when the audio hardware is busy */
|
||||||
|
|
|
@ -402,17 +402,12 @@ ALSA_FlushCapture(_THIS)
|
||||||
static void
|
static void
|
||||||
ALSA_CloseDevice(_THIS)
|
ALSA_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->pcm_handle) {
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
ALSA_snd_pcm_drain(this->hidden->pcm_handle);
|
||||||
this->hidden->mixbuf = NULL;
|
ALSA_snd_pcm_close(this->hidden->pcm_handle);
|
||||||
if (this->hidden->pcm_handle) {
|
|
||||||
ALSA_snd_pcm_drain(this->hidden->pcm_handle);
|
|
||||||
ALSA_snd_pcm_close(this->hidden->pcm_handle);
|
|
||||||
this->hidden->pcm_handle = NULL;
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -555,7 +550,6 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
SND_PCM_NONBLOCK);
|
SND_PCM_NONBLOCK);
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("ALSA: Couldn't open audio device: %s",
|
return SDL_SetError("ALSA: Couldn't open audio device: %s",
|
||||||
ALSA_snd_strerror(status));
|
ALSA_snd_strerror(status));
|
||||||
}
|
}
|
||||||
|
@ -566,7 +560,6 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
snd_pcm_hw_params_alloca(&hwparams);
|
snd_pcm_hw_params_alloca(&hwparams);
|
||||||
status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
|
status = ALSA_snd_pcm_hw_params_any(pcm_handle, hwparams);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("ALSA: Couldn't get hardware config: %s",
|
return SDL_SetError("ALSA: Couldn't get hardware config: %s",
|
||||||
ALSA_snd_strerror(status));
|
ALSA_snd_strerror(status));
|
||||||
}
|
}
|
||||||
|
@ -575,7 +568,6 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
|
status = ALSA_snd_pcm_hw_params_set_access(pcm_handle, hwparams,
|
||||||
SND_PCM_ACCESS_RW_INTERLEAVED);
|
SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("ALSA: Couldn't set interleaved access: %s",
|
return SDL_SetError("ALSA: Couldn't set interleaved access: %s",
|
||||||
ALSA_snd_strerror(status));
|
ALSA_snd_strerror(status));
|
||||||
}
|
}
|
||||||
|
@ -629,7 +621,6 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("ALSA: Couldn't find any hardware audio formats");
|
return SDL_SetError("ALSA: Couldn't find any hardware audio formats");
|
||||||
}
|
}
|
||||||
this->spec.format = test_format;
|
this->spec.format = test_format;
|
||||||
|
@ -641,7 +632,6 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels);
|
status = ALSA_snd_pcm_hw_params_get_channels(hwparams, &channels);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("ALSA: Couldn't set audio channels");
|
return SDL_SetError("ALSA: Couldn't set audio channels");
|
||||||
}
|
}
|
||||||
this->spec.channels = channels;
|
this->spec.channels = channels;
|
||||||
|
@ -652,7 +642,6 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
|
status = ALSA_snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams,
|
||||||
&rate, NULL);
|
&rate, NULL);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("ALSA: Couldn't set audio frequency: %s",
|
return SDL_SetError("ALSA: Couldn't set audio frequency: %s",
|
||||||
ALSA_snd_strerror(status));
|
ALSA_snd_strerror(status));
|
||||||
}
|
}
|
||||||
|
@ -664,7 +653,6 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Failed to set desired buffer size, do the best you can... */
|
/* Failed to set desired buffer size, do the best you can... */
|
||||||
status = ALSA_set_period_size(this, hwparams, 1);
|
status = ALSA_set_period_size(this, hwparams, 1);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status));
|
return SDL_SetError("Couldn't set hardware audio parameters: %s", ALSA_snd_strerror(status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -672,26 +660,22 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
snd_pcm_sw_params_alloca(&swparams);
|
snd_pcm_sw_params_alloca(&swparams);
|
||||||
status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
|
status = ALSA_snd_pcm_sw_params_current(pcm_handle, swparams);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("ALSA: Couldn't get software config: %s",
|
return SDL_SetError("ALSA: Couldn't get software config: %s",
|
||||||
ALSA_snd_strerror(status));
|
ALSA_snd_strerror(status));
|
||||||
}
|
}
|
||||||
status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
|
status = ALSA_snd_pcm_sw_params_set_avail_min(pcm_handle, swparams, this->spec.samples);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't set minimum available samples: %s",
|
return SDL_SetError("Couldn't set minimum available samples: %s",
|
||||||
ALSA_snd_strerror(status));
|
ALSA_snd_strerror(status));
|
||||||
}
|
}
|
||||||
status =
|
status =
|
||||||
ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
|
ALSA_snd_pcm_sw_params_set_start_threshold(pcm_handle, swparams, 1);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("ALSA: Couldn't set start threshold: %s",
|
return SDL_SetError("ALSA: Couldn't set start threshold: %s",
|
||||||
ALSA_snd_strerror(status));
|
ALSA_snd_strerror(status));
|
||||||
}
|
}
|
||||||
status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
|
status = ALSA_snd_pcm_sw_params(pcm_handle, swparams);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't set software audio parameters: %s",
|
return SDL_SetError("Couldn't set software audio parameters: %s",
|
||||||
ALSA_snd_strerror(status));
|
ALSA_snd_strerror(status));
|
||||||
}
|
}
|
||||||
|
@ -704,7 +688,6 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixlen = this->spec.size;
|
this->hidden->mixlen = this->spec.size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
ALSA_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->hidden->mixlen);
|
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->hidden->mixlen);
|
||||||
|
|
|
@ -44,6 +44,7 @@ AndroidAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
return SDL_SetError("Capture not supported on Android");
|
return SDL_SetError("Capture not supported on Android");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* !!! FIXME: higher level will prevent this now. Lose this check (and global?). */
|
||||||
if (audioDevice != NULL) {
|
if (audioDevice != NULL) {
|
||||||
return SDL_SetError("Only one audio device at a time please!");
|
return SDL_SetError("Only one audio device at a time please!");
|
||||||
}
|
}
|
||||||
|
@ -115,10 +116,7 @@ AndroidAUD_CloseDevice(_THIS)
|
||||||
Android_JNI_CloseAudioDevice();
|
Android_JNI_CloseAudioDevice();
|
||||||
|
|
||||||
if (audioDevice == this) {
|
if (audioDevice == this) {
|
||||||
if (audioDevice->hidden != NULL) {
|
SDL_free(this->hidden);
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
|
||||||
audioDevice = NULL;
|
audioDevice = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,17 +203,12 @@ ARTS_GetDeviceBuf(_THIS)
|
||||||
static void
|
static void
|
||||||
ARTS_CloseDevice(_THIS)
|
ARTS_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->stream) {
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
SDL_NAME(arts_close_stream) (this->hidden->stream);
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
if (this->hidden->stream) {
|
|
||||||
SDL_NAME(arts_close_stream) (this->hidden->stream);
|
|
||||||
this->hidden->stream = 0;
|
|
||||||
}
|
|
||||||
SDL_NAME(arts_free) ();
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
SDL_NAME(arts_free) ();
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -267,19 +262,16 @@ ARTS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (format == 0) {
|
if (format == 0) {
|
||||||
ARTS_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't find any hardware audio formats");
|
return SDL_SetError("Couldn't find any hardware audio formats");
|
||||||
}
|
}
|
||||||
this->spec.format = test_format;
|
this->spec.format = test_format;
|
||||||
|
|
||||||
if ((rc = SDL_NAME(arts_init) ()) != 0) {
|
if ((rc = SDL_NAME(arts_init) ()) != 0) {
|
||||||
ARTS_CloseDevice(this);
|
|
||||||
return SDL_SetError("Unable to initialize ARTS: %s",
|
return SDL_SetError("Unable to initialize ARTS: %s",
|
||||||
SDL_NAME(arts_error_text) (rc));
|
SDL_NAME(arts_error_text) (rc));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ARTS_Suspend()) {
|
if (!ARTS_Suspend()) {
|
||||||
ARTS_CloseDevice(this);
|
|
||||||
return SDL_SetError("ARTS can not open audio device");
|
return SDL_SetError("ARTS can not open audio device");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +289,6 @@ ARTS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Determine the power of two of the fragment size */
|
/* Determine the power of two of the fragment size */
|
||||||
for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec);
|
for (frag_spec = 0; (0x01 << frag_spec) < this->spec.size; ++frag_spec);
|
||||||
if ((0x01 << frag_spec) != this->spec.size) {
|
if ((0x01 << frag_spec) != this->spec.size) {
|
||||||
ARTS_CloseDevice(this);
|
|
||||||
return SDL_SetError("Fragment size must be a power of two");
|
return SDL_SetError("Fragment size must be a power of two");
|
||||||
}
|
}
|
||||||
frag_spec |= 0x00020000; /* two fragments, for low latency */
|
frag_spec |= 0x00020000; /* two fragments, for low latency */
|
||||||
|
@ -318,7 +309,6 @@ ARTS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixlen = this->spec.size;
|
this->hidden->mixlen = this->spec.size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
ARTS_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||||
|
|
|
@ -268,16 +268,11 @@ BSDAUDIO_FlushCapture(_THIS)
|
||||||
static void
|
static void
|
||||||
BSDAUDIO_CloseDevice(_THIS)
|
BSDAUDIO_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->audio_fd >= 0) {
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
close(this->hidden->audio_fd);
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
if (this->hidden->audio_fd >= 0) {
|
|
||||||
close(this->hidden->audio_fd);
|
|
||||||
this->hidden->audio_fd = -1;
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -319,7 +314,6 @@ BSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Set to play mode */
|
/* Set to play mode */
|
||||||
info.mode = iscapture ? AUMODE_RECORD : AUMODE_PLAY;
|
info.mode = iscapture ? AUMODE_RECORD : AUMODE_PLAY;
|
||||||
if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
|
if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
|
||||||
BSDAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't put device into play mode");
|
return SDL_SetError("Couldn't put device into play mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +355,6 @@ BSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!format) {
|
if (!format) {
|
||||||
BSDAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("No supported encoding for 0x%x", this->spec.format);
|
return SDL_SetError("No supported encoding for 0x%x", this->spec.format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +379,6 @@ BSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixlen = this->spec.size;
|
this->hidden->mixlen = this->spec.size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
BSDAUDIO_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
#if SDL_AUDIO_DRIVER_COREAUDIO
|
#if SDL_AUDIO_DRIVER_COREAUDIO
|
||||||
|
|
||||||
|
/* !!! FIXME: clean out some of the macro salsa in here. */
|
||||||
|
|
||||||
#include "SDL_audio.h"
|
#include "SDL_audio.h"
|
||||||
#include "../SDL_audio_c.h"
|
#include "../SDL_audio_c.h"
|
||||||
#include "../SDL_sysaudio.h"
|
#include "../SDL_sysaudio.h"
|
||||||
|
@ -30,11 +32,8 @@
|
||||||
|
|
||||||
#define DEBUG_COREAUDIO 0
|
#define DEBUG_COREAUDIO 0
|
||||||
|
|
||||||
static void COREAUDIO_CloseDevice(_THIS);
|
|
||||||
|
|
||||||
#define CHECK_RESULT(msg) \
|
#define CHECK_RESULT(msg) \
|
||||||
if (result != noErr) { \
|
if (result != noErr) { \
|
||||||
COREAUDIO_CloseDevice(this); \
|
|
||||||
SDL_SetError("CoreAudio error (%s): %d", msg, (int) result); \
|
SDL_SetError("CoreAudio error (%s): %d", msg, (int) result); \
|
||||||
return 0; \
|
return 0; \
|
||||||
}
|
}
|
||||||
|
@ -436,45 +435,39 @@ device_unplugged(AudioObjectID devid, UInt32 num_addr, const AudioObjectProperty
|
||||||
static void
|
static void
|
||||||
COREAUDIO_CloseDevice(_THIS)
|
COREAUDIO_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
const int iscapture = this->iscapture;
|
||||||
const int iscapture = this->iscapture;
|
if (this->hidden->audioUnitOpened) {
|
||||||
if (this->hidden->audioUnitOpened) {
|
#if MACOSX_COREAUDIO
|
||||||
#if MACOSX_COREAUDIO
|
/* Unregister our disconnect callback. */
|
||||||
/* Unregister our disconnect callback. */
|
AudioObjectRemovePropertyListener(this->hidden->deviceID, &alive_address, device_unplugged, this);
|
||||||
AudioObjectRemovePropertyListener(this->hidden->deviceID, &alive_address, device_unplugged, this);
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
AURenderCallbackStruct callback;
|
AURenderCallbackStruct callback;
|
||||||
const AudioUnitElement output_bus = 0;
|
const AudioUnitElement output_bus = 0;
|
||||||
const AudioUnitElement input_bus = 1;
|
const AudioUnitElement input_bus = 1;
|
||||||
const AudioUnitElement bus =
|
const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus);
|
||||||
((iscapture) ? input_bus : output_bus);
|
|
||||||
|
|
||||||
/* stop processing the audio unit */
|
/* stop processing the audio unit */
|
||||||
AudioOutputUnitStop(this->hidden->audioUnit);
|
AudioOutputUnitStop(this->hidden->audioUnit);
|
||||||
|
|
||||||
/* Remove the input callback */
|
/* Remove the input callback */
|
||||||
SDL_zero(callback);
|
SDL_zero(callback);
|
||||||
AudioUnitSetProperty(this->hidden->audioUnit,
|
AudioUnitSetProperty(this->hidden->audioUnit,
|
||||||
iscapture ? kAudioOutputUnitProperty_SetInputCallback : kAudioUnitProperty_SetRenderCallback,
|
iscapture ? kAudioOutputUnitProperty_SetInputCallback : kAudioUnitProperty_SetRenderCallback,
|
||||||
kAudioUnitScope_Global, bus, &callback, sizeof(callback));
|
kAudioUnitScope_Global, bus, &callback, sizeof(callback));
|
||||||
AudioComponentInstanceDispose(this->hidden->audioUnit);
|
AudioComponentInstanceDispose(this->hidden->audioUnit);
|
||||||
this->hidden->audioUnitOpened = 0;
|
|
||||||
|
|
||||||
SDL_free(this->hidden->captureBufferList.mBuffers[0].mData);
|
|
||||||
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden->buffer);
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
|
|
||||||
if (iscapture) {
|
|
||||||
open_capture_devices--;
|
|
||||||
} else {
|
|
||||||
open_playback_devices--;
|
|
||||||
}
|
|
||||||
update_audio_session();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_free(this->hidden->captureBufferList.mBuffers[0].mData);
|
||||||
|
SDL_free(this->hidden->buffer);
|
||||||
|
SDL_free(this->hidden);
|
||||||
|
|
||||||
|
if (iscapture) {
|
||||||
|
open_capture_devices--;
|
||||||
|
} else {
|
||||||
|
open_playback_devices--;
|
||||||
|
}
|
||||||
|
update_audio_session();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MACOSX_COREAUDIO
|
#if MACOSX_COREAUDIO
|
||||||
|
@ -623,7 +616,6 @@ prepare_audiounit(_THIS, void *handle, int iscapture,
|
||||||
framesize *= SDL_AUDIO_BITSIZE(this->spec.format) / 8;
|
framesize *= SDL_AUDIO_BITSIZE(this->spec.format) / 8;
|
||||||
ptr = SDL_calloc(1, framesize);
|
ptr = SDL_calloc(1, framesize);
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
COREAUDIO_CloseDevice(this);
|
|
||||||
SDL_OutOfMemory();
|
SDL_OutOfMemory();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -655,7 +647,6 @@ prepare_audiounit(_THIS, void *handle, int iscapture,
|
||||||
|
|
||||||
this->hidden->buffer = SDL_malloc(this->hidden->bufferSize);
|
this->hidden->buffer = SDL_malloc(this->hidden->bufferSize);
|
||||||
if (this->hidden->buffer == NULL) {
|
if (this->hidden->buffer == NULL) {
|
||||||
COREAUDIO_CloseDevice(this);
|
|
||||||
SDL_OutOfMemory();
|
SDL_OutOfMemory();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -737,7 +728,6 @@ COREAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid_datatype) { /* shouldn't happen, but just in case... */
|
if (!valid_datatype) { /* shouldn't happen, but just in case... */
|
||||||
COREAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Unsupported audio format");
|
return SDL_SetError("Unsupported audio format");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -747,7 +737,6 @@ COREAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
|
strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
|
||||||
|
|
||||||
if (!prepare_audiounit(this, handle, iscapture, &strdesc)) {
|
if (!prepare_audiounit(this, handle, iscapture, &strdesc)) {
|
||||||
COREAUDIO_CloseDevice(this);
|
|
||||||
return -1; /* prepare_audiounit() will call SDL_SetError()... */
|
return -1; /* prepare_audiounit() will call SDL_SetError()... */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -322,20 +322,13 @@ DSOUND_WaitDone(_THIS)
|
||||||
static void
|
static void
|
||||||
DSOUND_CloseDevice(_THIS)
|
DSOUND_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->mixbuf != NULL) {
|
||||||
if (this->hidden->sound != NULL) {
|
IDirectSoundBuffer_Release(this->hidden->mixbuf);
|
||||||
if (this->hidden->mixbuf != NULL) {
|
|
||||||
/* Clean up the audio buffer */
|
|
||||||
IDirectSoundBuffer_Release(this->hidden->mixbuf);
|
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
}
|
|
||||||
IDirectSound_Release(this->hidden->sound);
|
|
||||||
this->hidden->sound = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
if (this->hidden->sound != NULL) {
|
||||||
|
IDirectSound_Release(this->hidden->sound);
|
||||||
|
}
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function tries to create a secondary audio buffer, and returns the
|
/* This function tries to create a secondary audio buffer, and returns the
|
||||||
|
@ -443,7 +436,6 @@ DSOUND_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Open the audio device */
|
/* Open the audio device */
|
||||||
result = pDirectSoundCreate8(guid, &this->hidden->sound, NULL);
|
result = pDirectSoundCreate8(guid, &this->hidden->sound, NULL);
|
||||||
if (result != DS_OK) {
|
if (result != DS_OK) {
|
||||||
DSOUND_CloseDevice(this);
|
|
||||||
return SetDSerror("DirectSoundCreate", result);
|
return SetDSerror("DirectSoundCreate", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,7 +457,6 @@ DSOUND_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid_format) {
|
if (!valid_format) {
|
||||||
DSOUND_CloseDevice(this);
|
|
||||||
if (tried_format) {
|
if (tried_format) {
|
||||||
return -1; /* CreateSecondary() should have called SDL_SetError(). */
|
return -1; /* CreateSecondary() should have called SDL_SetError(). */
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,16 +87,11 @@ DISKAUD_GetDeviceBuf(_THIS)
|
||||||
static void
|
static void
|
||||||
DISKAUD_CloseDevice(_THIS)
|
DISKAUD_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->output != NULL) {
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
SDL_RWclose(this->hidden->output);
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
if (this->hidden->output != NULL) {
|
|
||||||
SDL_RWclose(this->hidden->output);
|
|
||||||
this->hidden->output = NULL;
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -120,14 +115,12 @@ DISKAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Open the audio device */
|
/* Open the audio device */
|
||||||
this->hidden->output = SDL_RWFromFile(fname, "wb");
|
this->hidden->output = SDL_RWFromFile(fname, "wb");
|
||||||
if (this->hidden->output == NULL) {
|
if (this->hidden->output == NULL) {
|
||||||
DISKAUD_CloseDevice(this);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate mixing buffer */
|
/* Allocate mixing buffer */
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
DISKAUD_CloseDevice(this);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||||
|
|
|
@ -60,16 +60,11 @@ DSP_DetectDevices(void)
|
||||||
static void
|
static void
|
||||||
DSP_CloseDevice(_THIS)
|
DSP_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->audio_fd >= 0) {
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
close(this->hidden->audio_fd);
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
if (this->hidden->audio_fd >= 0) {
|
|
||||||
close(this->hidden->audio_fd);
|
|
||||||
this->hidden->audio_fd = -1;
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,7 +106,6 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Open the audio device */
|
/* Open the audio device */
|
||||||
this->hidden->audio_fd = open(devname, flags, 0);
|
this->hidden->audio_fd = open(devname, flags, 0);
|
||||||
if (this->hidden->audio_fd < 0) {
|
if (this->hidden->audio_fd < 0) {
|
||||||
DSP_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
|
return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
|
||||||
}
|
}
|
||||||
this->hidden->mixbuf = NULL;
|
this->hidden->mixbuf = NULL;
|
||||||
|
@ -122,7 +116,6 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
ctlflags = fcntl(this->hidden->audio_fd, F_GETFL);
|
ctlflags = fcntl(this->hidden->audio_fd, F_GETFL);
|
||||||
ctlflags &= ~O_NONBLOCK;
|
ctlflags &= ~O_NONBLOCK;
|
||||||
if (fcntl(this->hidden->audio_fd, F_SETFL, ctlflags) < 0) {
|
if (fcntl(this->hidden->audio_fd, F_SETFL, ctlflags) < 0) {
|
||||||
DSP_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't set audio blocking mode");
|
return SDL_SetError("Couldn't set audio blocking mode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +123,6 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Get a list of supported hardware formats */
|
/* Get a list of supported hardware formats */
|
||||||
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
|
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_GETFMTS, &value) < 0) {
|
||||||
perror("SNDCTL_DSP_GETFMTS");
|
perror("SNDCTL_DSP_GETFMTS");
|
||||||
DSP_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't get audio format list");
|
return SDL_SetError("Couldn't get audio format list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +179,6 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (format == 0) {
|
if (format == 0) {
|
||||||
DSP_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't find any hardware audio formats");
|
return SDL_SetError("Couldn't find any hardware audio formats");
|
||||||
}
|
}
|
||||||
this->spec.format = test_format;
|
this->spec.format = test_format;
|
||||||
|
@ -197,7 +188,6 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
if ((ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
|
if ((ioctl(this->hidden->audio_fd, SNDCTL_DSP_SETFMT, &value) < 0) ||
|
||||||
(value != format)) {
|
(value != format)) {
|
||||||
perror("SNDCTL_DSP_SETFMT");
|
perror("SNDCTL_DSP_SETFMT");
|
||||||
DSP_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't set audio format");
|
return SDL_SetError("Couldn't set audio format");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +195,6 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
value = this->spec.channels;
|
value = this->spec.channels;
|
||||||
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
|
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_CHANNELS, &value) < 0) {
|
||||||
perror("SNDCTL_DSP_CHANNELS");
|
perror("SNDCTL_DSP_CHANNELS");
|
||||||
DSP_CloseDevice(this);
|
|
||||||
return SDL_SetError("Cannot set the number of channels");
|
return SDL_SetError("Cannot set the number of channels");
|
||||||
}
|
}
|
||||||
this->spec.channels = value;
|
this->spec.channels = value;
|
||||||
|
@ -214,7 +203,6 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
value = this->spec.freq;
|
value = this->spec.freq;
|
||||||
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
|
if (ioctl(this->hidden->audio_fd, SNDCTL_DSP_SPEED, &value) < 0) {
|
||||||
perror("SNDCTL_DSP_SPEED");
|
perror("SNDCTL_DSP_SPEED");
|
||||||
DSP_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't set audio frequency");
|
return SDL_SetError("Couldn't set audio frequency");
|
||||||
}
|
}
|
||||||
this->spec.freq = value;
|
this->spec.freq = value;
|
||||||
|
@ -225,7 +213,6 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Determine the power of two of the fragment size */
|
/* Determine the power of two of the fragment size */
|
||||||
for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec);
|
for (frag_spec = 0; (0x01U << frag_spec) < this->spec.size; ++frag_spec);
|
||||||
if ((0x01U << frag_spec) != this->spec.size) {
|
if ((0x01U << frag_spec) != this->spec.size) {
|
||||||
DSP_CloseDevice(this);
|
|
||||||
return SDL_SetError("Fragment size must be a power of two");
|
return SDL_SetError("Fragment size must be a power of two");
|
||||||
}
|
}
|
||||||
frag_spec |= 0x00020000; /* two fragments, for low latency */
|
frag_spec |= 0x00020000; /* two fragments, for low latency */
|
||||||
|
@ -253,7 +240,6 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixlen = this->spec.size;
|
this->hidden->mixlen = this->spec.size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
DSP_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||||
|
|
|
@ -136,16 +136,8 @@ HandleAudioProcess(_THIS)
|
||||||
static void
|
static void
|
||||||
Emscripten_CloseDevice(_THIS)
|
Emscripten_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
SDL_free(this->hidden->mixbuf);
|
||||||
if (this->hidden->mixbuf != NULL) {
|
SDL_free(this->hidden);
|
||||||
/* Clean up the audio buffer */
|
|
||||||
SDL_free(this->hidden->mixbuf);
|
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -174,17 +174,11 @@ ESD_GetDeviceBuf(_THIS)
|
||||||
static void
|
static void
|
||||||
ESD_CloseDevice(_THIS)
|
ESD_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->audio_fd >= 0) {
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
SDL_NAME(esd_close) (this->hidden->audio_fd);
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
if (this->hidden->audio_fd >= 0) {
|
|
||||||
SDL_NAME(esd_close) (this->hidden->audio_fd);
|
|
||||||
this->hidden->audio_fd = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to get the name of the program */
|
/* Try to get the name of the program */
|
||||||
|
@ -252,7 +246,6 @@ ESD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
ESD_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't find any hardware audio formats");
|
return SDL_SetError("Couldn't find any hardware audio formats");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +264,6 @@ ESD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
get_progname());
|
get_progname());
|
||||||
|
|
||||||
if (this->hidden->audio_fd < 0) {
|
if (this->hidden->audio_fd < 0) {
|
||||||
ESD_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't open ESD connection");
|
return SDL_SetError("Couldn't open ESD connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +277,6 @@ ESD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixlen = this->spec.size;
|
this->hidden->mixlen = this->spec.size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
ESD_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
#if SDL_AUDIO_DRIVER_FUSIONSOUND
|
#if SDL_AUDIO_DRIVER_FUSIONSOUND
|
||||||
|
|
||||||
|
/* !!! FIXME: why is this is SDL_FS_* instead of FUSIONSOUND_*? */
|
||||||
|
|
||||||
/* Allow access to a raw mixing buffer */
|
/* Allow access to a raw mixing buffer */
|
||||||
|
|
||||||
#ifdef HAVE_SIGNAL_H
|
#ifdef HAVE_SIGNAL_H
|
||||||
|
@ -168,20 +170,14 @@ SDL_FS_GetDeviceBuf(_THIS)
|
||||||
static void
|
static void
|
||||||
SDL_FS_CloseDevice(_THIS)
|
SDL_FS_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->stream) {
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
this->hidden->stream->Release(this->hidden->stream);
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
if (this->hidden->stream) {
|
|
||||||
this->hidden->stream->Release(this->hidden->stream);
|
|
||||||
this->hidden->stream = NULL;
|
|
||||||
}
|
|
||||||
if (this->hidden->fs) {
|
|
||||||
this->hidden->fs->Release(this->hidden->fs);
|
|
||||||
this->hidden->fs = NULL;
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
if (this->hidden->fs) {
|
||||||
|
this->hidden->fs->Release(this->hidden->fs);
|
||||||
|
}
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -239,7 +235,6 @@ SDL_FS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format == 0) {
|
if (format == 0) {
|
||||||
SDL_FS_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't find any hardware audio formats");
|
return SDL_SetError("Couldn't find any hardware audio formats");
|
||||||
}
|
}
|
||||||
this->spec.format = test_format;
|
this->spec.format = test_format;
|
||||||
|
@ -247,7 +242,6 @@ SDL_FS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Retrieve the main sound interface. */
|
/* Retrieve the main sound interface. */
|
||||||
ret = SDL_NAME(FusionSoundCreate) (&this->hidden->fs);
|
ret = SDL_NAME(FusionSoundCreate) (&this->hidden->fs);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
SDL_FS_CloseDevice(this);
|
|
||||||
return SDL_SetError("Unable to initialize FusionSound: %d", ret);
|
return SDL_SetError("Unable to initialize FusionSound: %d", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +260,6 @@ SDL_FS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->fs->CreateStream(this->hidden->fs, &desc,
|
this->hidden->fs->CreateStream(this->hidden->fs, &desc,
|
||||||
&this->hidden->stream);
|
&this->hidden->stream);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
SDL_FS_CloseDevice(this);
|
|
||||||
return SDL_SetError("Unable to create FusionSoundStream: %d", ret);
|
return SDL_SetError("Unable to create FusionSoundStream: %d", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +280,6 @@ SDL_FS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixlen = this->spec.size;
|
this->hidden->mixlen = this->spec.size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
SDL_FS_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||||
|
|
|
@ -74,16 +74,11 @@ FillSound(void *device, void *stream, size_t len,
|
||||||
static void
|
static void
|
||||||
HAIKUAUDIO_CloseDevice(_THIS)
|
HAIKUAUDIO_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (_this->hidden != NULL) {
|
if (_this->hidden->audio_obj) {
|
||||||
if (_this->hidden->audio_obj) {
|
_this->hidden->audio_obj->Stop();
|
||||||
_this->hidden->audio_obj->Stop();
|
delete _this->hidden->audio_obj;
|
||||||
delete _this->hidden->audio_obj;
|
|
||||||
_this->hidden->audio_obj = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete _this->hidden;
|
|
||||||
_this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
delete _this->hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,7 +172,6 @@ HAIKUAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid_datatype) { /* shouldn't happen, but just in case... */
|
if (!valid_datatype) { /* shouldn't happen, but just in case... */
|
||||||
HAIKUAUDIO_CloseDevice(_this);
|
|
||||||
return SDL_SetError("Unsupported audio format");
|
return SDL_SetError("Unsupported audio format");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +190,6 @@ HAIKUAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
|
if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
|
||||||
_this->hidden->audio_obj->SetHasData(true);
|
_this->hidden->audio_obj->SetHasData(true);
|
||||||
} else {
|
} else {
|
||||||
HAIKUAUDIO_CloseDevice(_this);
|
|
||||||
return SDL_SetError("Unable to start Be audio");
|
return SDL_SetError("Unable to start Be audio");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,6 @@
|
||||||
#define SAMPLE_FRAME_COUNT 4096
|
#define SAMPLE_FRAME_COUNT 4096
|
||||||
|
|
||||||
/* Audio driver functions */
|
/* Audio driver functions */
|
||||||
static int NACLAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture);
|
|
||||||
static void NACLAUD_CloseDevice(_THIS);
|
|
||||||
static void nacl_audio_callback(void* samples, uint32_t buffer_size, PP_TimeDelta latency, void* data);
|
static void nacl_audio_callback(void* samples, uint32_t buffer_size, PP_TimeDelta latency, void* data);
|
||||||
|
|
||||||
/* FIXME: Make use of latency if needed */
|
/* FIXME: Make use of latency if needed */
|
||||||
|
|
|
@ -190,16 +190,11 @@ NAS_GetDeviceBuf(_THIS)
|
||||||
static void
|
static void
|
||||||
NAS_CloseDevice(_THIS)
|
NAS_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->aud) {
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
NAS_AuCloseServer(this->hidden->aud);
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
if (this->hidden->aud) {
|
|
||||||
NAS_AuCloseServer(this->hidden->aud);
|
|
||||||
this->hidden->aud = 0;
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this2 = this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char
|
static unsigned char
|
||||||
|
@ -300,21 +295,18 @@ NAS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (format == 0) {
|
if (format == 0) {
|
||||||
NAS_CloseDevice(this);
|
|
||||||
return SDL_SetError("NAS: Couldn't find any hardware audio formats");
|
return SDL_SetError("NAS: Couldn't find any hardware audio formats");
|
||||||
}
|
}
|
||||||
this->spec.format = test_format;
|
this->spec.format = test_format;
|
||||||
|
|
||||||
this->hidden->aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL);
|
this->hidden->aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL);
|
||||||
if (this->hidden->aud == 0) {
|
if (this->hidden->aud == 0) {
|
||||||
NAS_CloseDevice(this);
|
|
||||||
return SDL_SetError("NAS: Couldn't open connection to NAS server");
|
return SDL_SetError("NAS: Couldn't open connection to NAS server");
|
||||||
}
|
}
|
||||||
|
|
||||||
this->hidden->dev = find_device(this, this->spec.channels);
|
this->hidden->dev = find_device(this, this->spec.channels);
|
||||||
if ((this->hidden->dev == AuNone)
|
if ((this->hidden->dev == AuNone)
|
||||||
|| (!(this->hidden->flow = NAS_AuCreateFlow(this->hidden->aud, 0)))) {
|
|| (!(this->hidden->flow = NAS_AuCreateFlow(this->hidden->aud, 0)))) {
|
||||||
NAS_CloseDevice(this);
|
|
||||||
return SDL_SetError("NAS: Couldn't find a fitting device on NAS server");
|
return SDL_SetError("NAS: Couldn't find a fitting device on NAS server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +339,6 @@ NAS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixlen = this->spec.size;
|
this->hidden->mixlen = this->spec.size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
NAS_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||||
|
|
|
@ -228,16 +228,11 @@ PAUDIO_GetDeviceBuf(_THIS)
|
||||||
static void
|
static void
|
||||||
PAUDIO_CloseDevice(_THIS)
|
PAUDIO_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->audio_fd >= 0) {
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
close(this->hidden->audio_fd);
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
if (this->hidden->audio_fd >= 0) {
|
|
||||||
close(this->hidden->audio_fd);
|
|
||||||
this->hidden->audio_fd = -1;
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -268,7 +263,6 @@ PAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
fd = OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
|
fd = OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
|
||||||
this->hidden->audio_fd = fd;
|
this->hidden->audio_fd = fd;
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
PAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
|
return SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +271,6 @@ PAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
* that we can have.
|
* that we can have.
|
||||||
*/
|
*/
|
||||||
if (ioctl(fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
|
if (ioctl(fd, AUDIO_BUFFER, &paud_bufinfo) < 0) {
|
||||||
PAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't get audio buffer information");
|
return SDL_SetError("Couldn't get audio buffer information");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,7 +384,6 @@ PAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
#ifdef DEBUG_AUDIO
|
#ifdef DEBUG_AUDIO
|
||||||
fprintf(stderr, "Couldn't find any hardware audio formats\n");
|
fprintf(stderr, "Couldn't find any hardware audio formats\n");
|
||||||
#endif
|
#endif
|
||||||
PAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't find any hardware audio formats");
|
return SDL_SetError("Couldn't find any hardware audio formats");
|
||||||
}
|
}
|
||||||
this->spec.format = test_format;
|
this->spec.format = test_format;
|
||||||
|
@ -449,7 +441,6 @@ PAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
PAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Paudio: %s", err);
|
return SDL_SetError("Paudio: %s", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,7 +448,6 @@ PAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixlen = this->spec.size;
|
this->hidden->mixlen = this->spec.size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
PAUDIO_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
|
||||||
|
@ -492,7 +482,6 @@ PAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
paud_control.ioctl_request = AUDIO_START;
|
paud_control.ioctl_request = AUDIO_START;
|
||||||
paud_control.position = 0;
|
paud_control.position = 0;
|
||||||
if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
|
if (ioctl(fd, AUDIO_CONTROL, &paud_control) < 0) {
|
||||||
PAUDIO_CloseDevice(this);
|
|
||||||
#ifdef DEBUG_AUDIO
|
#ifdef DEBUG_AUDIO
|
||||||
fprintf(stderr, "Can't start audio play\n");
|
fprintf(stderr, "Can't start audio play\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -126,14 +126,11 @@ static void PSPAUD_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden->channel >= 0) {
|
if (this->hidden->channel >= 0) {
|
||||||
sceAudioChRelease(this->hidden->channel);
|
sceAudioChRelease(this->hidden->channel);
|
||||||
this->hidden->channel = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->hidden->rawbuf != NULL) {
|
|
||||||
free(this->hidden->rawbuf);
|
|
||||||
this->hidden->rawbuf = NULL;
|
|
||||||
}
|
}
|
||||||
|
free(this->hidden->rawbuf); /* this uses memalign(), not SDL_malloc(). */
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PSPAUD_ThreadInit(_THIS)
|
static void PSPAUD_ThreadInit(_THIS)
|
||||||
{
|
{
|
||||||
/* Increase the priority of this audio thread by 1 to put it
|
/* Increase the priority of this audio thread by 1 to put it
|
||||||
|
@ -151,7 +148,6 @@ static void PSPAUD_ThreadInit(_THIS)
|
||||||
static int
|
static int
|
||||||
PSPAUD_Init(SDL_AudioDriverImpl * impl)
|
PSPAUD_Init(SDL_AudioDriverImpl * impl)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Set the function pointers */
|
/* Set the function pointers */
|
||||||
impl->OpenDevice = PSPAUD_OpenDevice;
|
impl->OpenDevice = PSPAUD_OpenDevice;
|
||||||
impl->PlayDevice = PSPAUD_PlayDevice;
|
impl->PlayDevice = PSPAUD_PlayDevice;
|
||||||
|
|
|
@ -463,20 +463,18 @@ PULSEAUDIO_FlushCapture(_THIS)
|
||||||
static void
|
static void
|
||||||
PULSEAUDIO_CloseDevice(_THIS)
|
PULSEAUDIO_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->stream) {
|
||||||
if (this->hidden->capturebuf != NULL) {
|
if (this->hidden->capturebuf != NULL) {
|
||||||
PULSEAUDIO_pa_stream_drop(this->hidden->stream);
|
PULSEAUDIO_pa_stream_drop(this->hidden->stream);
|
||||||
}
|
}
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
PULSEAUDIO_pa_stream_disconnect(this->hidden->stream);
|
||||||
SDL_free(this->hidden->device_name);
|
PULSEAUDIO_pa_stream_unref(this->hidden->stream);
|
||||||
if (this->hidden->stream) {
|
|
||||||
PULSEAUDIO_pa_stream_disconnect(this->hidden->stream);
|
|
||||||
PULSEAUDIO_pa_stream_unref(this->hidden->stream);
|
|
||||||
}
|
|
||||||
DisconnectFromPulseServer(this->hidden->mainloop, this->hidden->context);
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DisconnectFromPulseServer(this->hidden->mainloop, this->hidden->context);
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden->device_name);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -579,7 +577,6 @@ PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (paspec.format == PA_SAMPLE_INVALID) {
|
if (paspec.format == PA_SAMPLE_INVALID) {
|
||||||
PULSEAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't find any hardware audio formats");
|
return SDL_SetError("Couldn't find any hardware audio formats");
|
||||||
}
|
}
|
||||||
this->spec.format = test_format;
|
this->spec.format = test_format;
|
||||||
|
@ -595,7 +592,6 @@ PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
h->mixlen = this->spec.size;
|
h->mixlen = this->spec.size;
|
||||||
h->mixbuf = (Uint8 *) SDL_AllocAudioMem(h->mixlen);
|
h->mixbuf = (Uint8 *) SDL_AllocAudioMem(h->mixlen);
|
||||||
if (h->mixbuf == NULL) {
|
if (h->mixbuf == NULL) {
|
||||||
PULSEAUDIO_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(h->mixbuf, this->spec.silence, this->spec.size);
|
SDL_memset(h->mixbuf, this->spec.silence, this->spec.size);
|
||||||
|
@ -621,12 +617,10 @@ PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ConnectToPulseServer(&h->mainloop, &h->context) < 0) {
|
if (ConnectToPulseServer(&h->mainloop, &h->context) < 0) {
|
||||||
PULSEAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Could not connect to PulseAudio server");
|
return SDL_SetError("Could not connect to PulseAudio server");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FindDeviceName(h, iscapture, handle)) {
|
if (!FindDeviceName(h, iscapture, handle)) {
|
||||||
PULSEAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Requested PulseAudio sink/source missing?");
|
return SDL_SetError("Requested PulseAudio sink/source missing?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,7 +637,6 @@ PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (h->stream == NULL) {
|
if (h->stream == NULL) {
|
||||||
PULSEAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Could not set up PulseAudio stream");
|
return SDL_SetError("Could not set up PulseAudio stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -660,18 +653,15 @@ PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
PULSEAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Could not connect PulseAudio stream");
|
return SDL_SetError("Could not connect PulseAudio stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
|
if (PULSEAUDIO_pa_mainloop_iterate(h->mainloop, 1, NULL) < 0) {
|
||||||
PULSEAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("pa_mainloop_iterate() failed");
|
return SDL_SetError("pa_mainloop_iterate() failed");
|
||||||
}
|
}
|
||||||
state = PULSEAUDIO_pa_stream_get_state(h->stream);
|
state = PULSEAUDIO_pa_stream_get_state(h->stream);
|
||||||
if (!PA_STREAM_IS_GOOD(state)) {
|
if (!PA_STREAM_IS_GOOD(state)) {
|
||||||
PULSEAUDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("Could not connect PulseAudio stream");
|
return SDL_SetError("Could not connect PulseAudio stream");
|
||||||
}
|
}
|
||||||
} while (state != PA_STREAM_READY);
|
} while (state != PA_STREAM_READY);
|
||||||
|
|
|
@ -322,27 +322,21 @@ QSA_GetDeviceBuf(_THIS)
|
||||||
static void
|
static void
|
||||||
QSA_CloseDevice(_THIS)
|
QSA_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if (this->hidden->audio_handle != NULL) {
|
||||||
if (this->hidden->audio_handle != NULL) {
|
if (!this->hidden->iscapture) {
|
||||||
if (!this->hidden->iscapture) {
|
/* Finish playing available samples */
|
||||||
/* Finish playing available samples */
|
snd_pcm_plugin_flush(this->hidden->audio_handle,
|
||||||
snd_pcm_plugin_flush(this->hidden->audio_handle,
|
SND_PCM_CHANNEL_PLAYBACK);
|
||||||
SND_PCM_CHANNEL_PLAYBACK);
|
} else {
|
||||||
} else {
|
/* Cancel unread samples during capture */
|
||||||
/* Cancel unread samples during capture */
|
snd_pcm_plugin_flush(this->hidden->audio_handle,
|
||||||
snd_pcm_plugin_flush(this->hidden->audio_handle,
|
SND_PCM_CHANNEL_CAPTURE);
|
||||||
SND_PCM_CHANNEL_CAPTURE);
|
|
||||||
}
|
|
||||||
snd_pcm_close(this->hidden->audio_handle);
|
|
||||||
this->hidden->audio_handle = NULL;
|
|
||||||
}
|
}
|
||||||
|
snd_pcm_close(this->hidden->audio_handle);
|
||||||
SDL_FreeAudioMem(this->hidden->pcm_buf);
|
|
||||||
this->hidden->pcm_buf = NULL;
|
|
||||||
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_FreeAudioMem(this->hidden->pcm_buf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -391,7 +385,6 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Check if requested device is opened */
|
/* Check if requested device is opened */
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
this->hidden->audio_handle = NULL;
|
this->hidden->audio_handle = NULL;
|
||||||
QSA_CloseDevice(this);
|
|
||||||
return QSA_SetError("snd_pcm_open", status);
|
return QSA_SetError("snd_pcm_open", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,7 +394,6 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
snd_pcm_plugin_set_disable(this->hidden->audio_handle,
|
snd_pcm_plugin_set_disable(this->hidden->audio_handle,
|
||||||
PLUGIN_DISABLE_MMAP);
|
PLUGIN_DISABLE_MMAP);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
QSA_CloseDevice(this);
|
|
||||||
return QSA_SetError("snd_pcm_plugin_set_disable", status);
|
return QSA_SetError("snd_pcm_plugin_set_disable", status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -487,7 +479,6 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
|
|
||||||
/* assumes test_format not 0 on success */
|
/* assumes test_format not 0 on success */
|
||||||
if (test_format == 0) {
|
if (test_format == 0) {
|
||||||
QSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("QSA: Couldn't find any hardware audio formats");
|
return SDL_SetError("QSA: Couldn't find any hardware audio formats");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,7 +496,6 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Setup the transfer parameters according to cparams */
|
/* Setup the transfer parameters according to cparams */
|
||||||
status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
|
status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
QSA_CloseDevice(this);
|
|
||||||
return QSA_SetError("snd_pcm_channel_params", status);
|
return QSA_SetError("snd_pcm_channel_params", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,7 +509,6 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
|
|
||||||
/* Setup an audio channel */
|
/* Setup an audio channel */
|
||||||
if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
|
if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
|
||||||
QSA_CloseDevice(this);
|
|
||||||
return SDL_SetError("QSA: Unable to setup channel");
|
return SDL_SetError("QSA: Unable to setup channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +531,6 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->pcm_buf =
|
this->hidden->pcm_buf =
|
||||||
(Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len);
|
(Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len);
|
||||||
if (this->hidden->pcm_buf == NULL) {
|
if (this->hidden->pcm_buf == NULL) {
|
||||||
QSA_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->pcm_buf, this->spec.silence,
|
SDL_memset(this->hidden->pcm_buf, this->spec.silence,
|
||||||
|
@ -560,7 +548,6 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->hidden->audio_fd < 0) {
|
if (this->hidden->audio_fd < 0) {
|
||||||
QSA_CloseDevice(this);
|
|
||||||
return QSA_SetError("snd_pcm_file_descriptor", status);
|
return QSA_SetError("snd_pcm_file_descriptor", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,7 +565,6 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
QSA_CloseDevice(this);
|
|
||||||
return QSA_SetError("snd_pcm_plugin_prepare", status);
|
return QSA_SetError("snd_pcm_plugin_prepare", status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,16 +180,11 @@ SNDIO_WaitDone(_THIS)
|
||||||
static void
|
static void
|
||||||
SNDIO_CloseDevice(_THIS)
|
SNDIO_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
if ( this->hidden->dev != NULL ) {
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
SNDIO_sio_close(this->hidden->dev);
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
if ( this->hidden->dev != NULL ) {
|
|
||||||
SNDIO_sio_close(this->hidden->dev);
|
|
||||||
this->hidden->dev = NULL;
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -210,7 +205,6 @@ SNDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
|
|
||||||
/* !!! FIXME: SIO_DEVANY can be a specific device... */
|
/* !!! FIXME: SIO_DEVANY can be a specific device... */
|
||||||
if ((this->hidden->dev = SNDIO_sio_open(SIO_DEVANY, SIO_PLAY, 0)) == NULL) {
|
if ((this->hidden->dev = SNDIO_sio_open(SIO_DEVANY, SIO_PLAY, 0)) == NULL) {
|
||||||
SNDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("sio_open() failed");
|
return SDL_SetError("sio_open() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +227,6 @@ SNDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (SNDIO_sio_getpar(this->hidden->dev, &par) == 0) {
|
if (SNDIO_sio_getpar(this->hidden->dev, &par) == 0) {
|
||||||
SNDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("sio_getpar() failed");
|
return SDL_SetError("sio_getpar() failed");
|
||||||
}
|
}
|
||||||
if (par.bps != SIO_BPS(par.bits)) {
|
if (par.bps != SIO_BPS(par.bits)) {
|
||||||
|
@ -248,7 +241,6 @@ SNDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
SNDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("sndio: Couldn't find any hardware audio formats");
|
return SDL_SetError("sndio: Couldn't find any hardware audio formats");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +261,6 @@ SNDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
else if ((par.bps == 1) && (!par.sig))
|
else if ((par.bps == 1) && (!par.sig))
|
||||||
this->spec.format = AUDIO_U8;
|
this->spec.format = AUDIO_U8;
|
||||||
else {
|
else {
|
||||||
SNDIO_CloseDevice(this);
|
|
||||||
return SDL_SetError("sndio: Got unsupported hardware audio format.");
|
return SDL_SetError("sndio: Got unsupported hardware audio format.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +275,6 @@ SNDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixlen = this->spec.size;
|
this->hidden->mixlen = this->spec.size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
SNDIO_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->hidden->mixlen);
|
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->hidden->mixlen);
|
||||||
|
|
|
@ -183,18 +183,12 @@ SUNAUDIO_GetDeviceBuf(_THIS)
|
||||||
static void
|
static void
|
||||||
SUNAUDIO_CloseDevice(_THIS)
|
SUNAUDIO_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
SDL_free(this->hidden->ulaw_buf);
|
||||||
SDL_FreeAudioMem(this->hidden->mixbuf);
|
if (this->hidden->audio_fd >= 0) {
|
||||||
this->hidden->mixbuf = NULL;
|
close(this->hidden->audio_fd);
|
||||||
SDL_free(this->hidden->ulaw_buf);
|
|
||||||
this->hidden->ulaw_buf = NULL;
|
|
||||||
if (this->hidden->audio_fd >= 0) {
|
|
||||||
close(this->hidden->audio_fd);
|
|
||||||
this->hidden->audio_fd = -1;
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
SDL_FreeAudioMem(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -155,42 +155,31 @@ WINMM_WaitDone(_THIS)
|
||||||
static void
|
static void
|
||||||
WINMM_CloseDevice(_THIS)
|
WINMM_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
/* Close up audio */
|
int i;
|
||||||
if (this->hidden != NULL) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (this->hidden->audio_sem) {
|
if (this->hidden->audio_sem) {
|
||||||
CloseHandle(this->hidden->audio_sem);
|
CloseHandle(this->hidden->audio_sem);
|
||||||
this->hidden->audio_sem = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clean up mixing buffers */
|
|
||||||
for (i = 0; i < NUM_BUFFERS; ++i) {
|
|
||||||
if (this->hidden->wavebuf[i].dwUser != 0xFFFF) {
|
|
||||||
waveOutUnprepareHeader(this->hidden->hout,
|
|
||||||
&this->hidden->wavebuf[i],
|
|
||||||
sizeof(this->hidden->wavebuf[i]));
|
|
||||||
this->hidden->wavebuf[i].dwUser = 0xFFFF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Free raw mixing buffer */
|
|
||||||
SDL_free(this->hidden->mixbuf);
|
|
||||||
this->hidden->mixbuf = NULL;
|
|
||||||
|
|
||||||
if (this->hidden->hin) {
|
|
||||||
waveInClose(this->hidden->hin);
|
|
||||||
this->hidden->hin = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->hidden->hout) {
|
|
||||||
waveOutClose(this->hidden->hout);
|
|
||||||
this->hidden->hout = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clean up mixing buffers */
|
||||||
|
for (i = 0; i < NUM_BUFFERS; ++i) {
|
||||||
|
if (this->hidden->wavebuf[i].dwUser != 0xFFFF) {
|
||||||
|
waveOutUnprepareHeader(this->hidden->hout,
|
||||||
|
&this->hidden->wavebuf[i],
|
||||||
|
sizeof (this->hidden->wavebuf[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->hidden->hin) {
|
||||||
|
waveInClose(this->hidden->hin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->hidden->hout) {
|
||||||
|
waveOutClose(this->hidden->hout);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_free(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_bool
|
static SDL_bool
|
||||||
|
@ -269,7 +258,6 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid_datatype) {
|
if (!valid_datatype) {
|
||||||
WINMM_CloseDevice(this);
|
|
||||||
return SDL_SetError("Unsupported audio format");
|
return SDL_SetError("Unsupported audio format");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +276,6 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != MMSYSERR_NOERROR) {
|
if (result != MMSYSERR_NOERROR) {
|
||||||
WINMM_CloseDevice(this);
|
|
||||||
return SetMMerror("waveOutOpen()", result);
|
return SetMMerror("waveOutOpen()", result);
|
||||||
}
|
}
|
||||||
#ifdef SOUND_DEBUG
|
#ifdef SOUND_DEBUG
|
||||||
|
@ -299,7 +286,6 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
result = waveOutGetDevCaps((UINT) this->hidden->hout,
|
result = waveOutGetDevCaps((UINT) this->hidden->hout,
|
||||||
&caps, sizeof(caps));
|
&caps, sizeof(caps));
|
||||||
if (result != MMSYSERR_NOERROR) {
|
if (result != MMSYSERR_NOERROR) {
|
||||||
WINMM_CloseDevice(this);
|
|
||||||
return SetMMerror("waveOutGetDevCaps()", result);
|
return SetMMerror("waveOutGetDevCaps()", result);
|
||||||
}
|
}
|
||||||
printf("Audio device: %s\n", caps.szPname);
|
printf("Audio device: %s\n", caps.szPname);
|
||||||
|
@ -310,7 +296,6 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->audio_sem =
|
this->hidden->audio_sem =
|
||||||
CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL);
|
CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL);
|
||||||
if (this->hidden->audio_sem == NULL) {
|
if (this->hidden->audio_sem == NULL) {
|
||||||
WINMM_CloseDevice(this);
|
|
||||||
return SDL_SetError("Couldn't create semaphore");
|
return SDL_SetError("Couldn't create semaphore");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,7 +303,6 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixbuf =
|
this->hidden->mixbuf =
|
||||||
(Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
|
(Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
WINMM_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
for (i = 0; i < NUM_BUFFERS; ++i) {
|
for (i = 0; i < NUM_BUFFERS; ++i) {
|
||||||
|
@ -332,7 +316,6 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
&this->hidden->wavebuf[i],
|
&this->hidden->wavebuf[i],
|
||||||
sizeof(this->hidden->wavebuf[i]));
|
sizeof(this->hidden->wavebuf[i]));
|
||||||
if (result != MMSYSERR_NOERROR) {
|
if (result != MMSYSERR_NOERROR) {
|
||||||
WINMM_CloseDevice(this);
|
|
||||||
return SetMMerror("waveOutPrepareHeader()", result);
|
return SetMMerror("waveOutPrepareHeader()", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,33 +257,30 @@ XAUDIO2_WaitDone(_THIS)
|
||||||
static void
|
static void
|
||||||
XAUDIO2_CloseDevice(_THIS)
|
XAUDIO2_CloseDevice(_THIS)
|
||||||
{
|
{
|
||||||
if (this->hidden != NULL) {
|
IXAudio2 *ixa2 = this->hidden->ixa2;
|
||||||
IXAudio2 *ixa2 = this->hidden->ixa2;
|
IXAudio2SourceVoice *source = this->hidden->source;
|
||||||
IXAudio2SourceVoice *source = this->hidden->source;
|
IXAudio2MasteringVoice *mastering = this->hidden->mastering;
|
||||||
IXAudio2MasteringVoice *mastering = this->hidden->mastering;
|
|
||||||
|
|
||||||
if (source != NULL) {
|
if (source != NULL) {
|
||||||
IXAudio2SourceVoice_Stop(source, 0, XAUDIO2_COMMIT_NOW);
|
IXAudio2SourceVoice_Stop(source, 0, XAUDIO2_COMMIT_NOW);
|
||||||
IXAudio2SourceVoice_FlushSourceBuffers(source);
|
IXAudio2SourceVoice_FlushSourceBuffers(source);
|
||||||
IXAudio2SourceVoice_DestroyVoice(source);
|
IXAudio2SourceVoice_DestroyVoice(source);
|
||||||
}
|
|
||||||
if (ixa2 != NULL) {
|
|
||||||
IXAudio2_StopEngine(ixa2);
|
|
||||||
}
|
|
||||||
if (mastering != NULL) {
|
|
||||||
IXAudio2MasteringVoice_DestroyVoice(mastering);
|
|
||||||
}
|
|
||||||
if (ixa2 != NULL) {
|
|
||||||
IXAudio2_Release(ixa2);
|
|
||||||
}
|
|
||||||
SDL_free(this->hidden->mixbuf);
|
|
||||||
if (this->hidden->semaphore != NULL) {
|
|
||||||
SDL_DestroySemaphore(this->hidden->semaphore);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_free(this->hidden);
|
|
||||||
this->hidden = NULL;
|
|
||||||
}
|
}
|
||||||
|
if (ixa2 != NULL) {
|
||||||
|
IXAudio2_StopEngine(ixa2);
|
||||||
|
}
|
||||||
|
if (mastering != NULL) {
|
||||||
|
IXAudio2MasteringVoice_DestroyVoice(mastering);
|
||||||
|
}
|
||||||
|
if (ixa2 != NULL) {
|
||||||
|
IXAudio2_Release(ixa2);
|
||||||
|
}
|
||||||
|
if (this->hidden->semaphore != NULL) {
|
||||||
|
SDL_DestroySemaphore(this->hidden->semaphore);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_free(this->hidden->mixbuf);
|
||||||
|
SDL_free(this->hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -350,7 +347,6 @@ XAUDIO2_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->ixa2 = ixa2;
|
this->hidden->ixa2 = ixa2;
|
||||||
this->hidden->semaphore = SDL_CreateSemaphore(1);
|
this->hidden->semaphore = SDL_CreateSemaphore(1);
|
||||||
if (this->hidden->semaphore == NULL) {
|
if (this->hidden->semaphore == NULL) {
|
||||||
XAUDIO2_CloseDevice(this);
|
|
||||||
return SDL_SetError("XAudio2: CreateSemaphore() failed!");
|
return SDL_SetError("XAudio2: CreateSemaphore() failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +364,6 @@ XAUDIO2_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid_format) {
|
if (!valid_format) {
|
||||||
XAUDIO2_CloseDevice(this);
|
|
||||||
return SDL_SetError("XAudio2: Unsupported audio format");
|
return SDL_SetError("XAudio2: Unsupported audio format");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +374,6 @@ XAUDIO2_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->hidden->mixlen = this->spec.size;
|
this->hidden->mixlen = this->spec.size;
|
||||||
this->hidden->mixbuf = (Uint8 *) SDL_malloc(2 * this->hidden->mixlen);
|
this->hidden->mixbuf = (Uint8 *) SDL_malloc(2 * this->hidden->mixlen);
|
||||||
if (this->hidden->mixbuf == NULL) {
|
if (this->hidden->mixbuf == NULL) {
|
||||||
XAUDIO2_CloseDevice(this);
|
|
||||||
return SDL_OutOfMemory();
|
return SDL_OutOfMemory();
|
||||||
}
|
}
|
||||||
this->hidden->nextbuf = this->hidden->mixbuf;
|
this->hidden->nextbuf = this->hidden->mixbuf;
|
||||||
|
@ -401,7 +395,6 @@ XAUDIO2_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
this->spec.freq, 0, devId, NULL);
|
this->spec.freq, 0, devId, NULL);
|
||||||
#endif
|
#endif
|
||||||
if (result != S_OK) {
|
if (result != S_OK) {
|
||||||
XAUDIO2_CloseDevice(this);
|
|
||||||
return SDL_SetError("XAudio2: Couldn't create mastering voice");
|
return SDL_SetError("XAudio2: Couldn't create mastering voice");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +429,6 @@ XAUDIO2_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if (result != S_OK) {
|
if (result != S_OK) {
|
||||||
XAUDIO2_CloseDevice(this);
|
|
||||||
return SDL_SetError("XAudio2: Couldn't create source voice");
|
return SDL_SetError("XAudio2: Couldn't create source voice");
|
||||||
}
|
}
|
||||||
this->hidden->source = source;
|
this->hidden->source = source;
|
||||||
|
@ -444,13 +436,11 @@ XAUDIO2_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
|
||||||
/* Start everything playing! */
|
/* Start everything playing! */
|
||||||
result = IXAudio2_StartEngine(ixa2);
|
result = IXAudio2_StartEngine(ixa2);
|
||||||
if (result != S_OK) {
|
if (result != S_OK) {
|
||||||
XAUDIO2_CloseDevice(this);
|
|
||||||
return SDL_SetError("XAudio2: Couldn't start engine");
|
return SDL_SetError("XAudio2: Couldn't start engine");
|
||||||
}
|
}
|
||||||
|
|
||||||
result = IXAudio2SourceVoice_Start(source, 0, XAUDIO2_COMMIT_NOW);
|
result = IXAudio2SourceVoice_Start(source, 0, XAUDIO2_COMMIT_NOW);
|
||||||
if (result != S_OK) {
|
if (result != S_OK) {
|
||||||
XAUDIO2_CloseDevice(this);
|
|
||||||
return SDL_SetError("XAudio2: Couldn't start source voice");
|
return SDL_SetError("XAudio2: Couldn't start source voice");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue