audio: changed some SDL_memset() calls to SDL_zero(), other minor corrections.

This commit is contained in:
Ryan C. Gordon 2016-08-05 01:59:06 -04:00
parent 979de761c9
commit 761a79788c
21 changed files with 34 additions and 39 deletions

View File

@ -504,7 +504,7 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
was_error = 1; was_error = 1;
goto done; goto done;
} }
SDL_memset(spec, 0, (sizeof *spec)); SDL_zerop(spec);
spec->freq = SDL_SwapLE32(format->frequency); spec->freq = SDL_SwapLE32(format->frequency);
if (IEEE_float_encoded) { if (IEEE_float_encoded) {

View File

@ -539,7 +539,7 @@ ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* Open the audio device */ /* Open the audio device */
/* Name of device should depend on # channels in spec */ /* Name of device should depend on # channels in spec */

View File

@ -235,7 +235,7 @@ ARTS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* Try for a closest match on audio format */ /* Try for a closest match on audio format */
for (test_format = SDL_FirstAudioFormat(this->spec.format); for (test_format = SDL_FirstAudioFormat(this->spec.format);

View File

@ -297,7 +297,7 @@ BSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* Open the audio device */ /* Open the audio device */
this->hidden->audio_fd = open(devname, flags, 0); this->hidden->audio_fd = open(devname, flags, 0);

View File

@ -431,7 +431,7 @@ DSOUND_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* Open the audio device */ /* Open the audio device */
result = pDirectSoundCreate8(guid, &this->hidden->sound, NULL); result = pDirectSoundCreate8(guid, &this->hidden->sound, NULL);

View File

@ -105,7 +105,7 @@ DISKAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, sizeof(*this->hidden)); SDL_zerop(this->hidden);
this->hidden->mixlen = this->spec.size; this->hidden->mixlen = this->spec.size;
this->hidden->write_delay = this->hidden->write_delay =

View File

@ -100,7 +100,7 @@ DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* Open the audio device */ /* Open the audio device */
this->hidden->audio_fd = open(devname, flags, 0); this->hidden->audio_fd = open(devname, flags, 0);

View File

@ -171,7 +171,7 @@ Emscripten_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* based on parts of library_sdl.js */ /* based on parts of library_sdl.js */

View File

@ -220,7 +220,7 @@ ESD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
this->hidden->audio_fd = -1; this->hidden->audio_fd = -1;
/* Convert audio spec to the ESD audio format */ /* Convert audio spec to the ESD audio format */

View File

@ -195,7 +195,7 @@ SDL_FS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* Try for a closest match on audio format */ /* Try for a closest match on audio format */
for (test_format = SDL_FirstAudioFormat(this->spec.format); for (test_format = SDL_FirstAudioFormat(this->spec.format);

View File

@ -118,10 +118,10 @@ HAIKUAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (_this->hidden == NULL) { if (_this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(_this->hidden, 0, (sizeof *_this->hidden)); SDL_zerop(this->hidden);
/* Parse the audio format and fill the Be raw audio format */ /* Parse the audio format and fill the Be raw audio format */
SDL_memset(&format, '\0', sizeof(media_raw_audio_format)); SDL_zero(format);
format.byte_order = B_MEDIA_LITTLE_ENDIAN; format.byte_order = B_MEDIA_LITTLE_ENDIAN;
format.frame_rate = (float) _this->spec.freq; format.frame_rate = (float) _this->spec.freq;
format.channel_count = _this->spec.channels; /* !!! FIXME: support > 2? */ format.channel_count = _this->spec.channels; /* !!! FIXME: support > 2? */

View File

@ -65,7 +65,7 @@ static void nacl_audio_callback(void* samples, uint32_t buffer_size, PP_TimeDelt
SDL_UnlockMutex(_this->mixer_lock); SDL_UnlockMutex(_this->mixer_lock);
} }
} else { } else {
SDL_memset(samples, 0, buffer_size); SDL_memset(samples, _this->spec.silence, buffer_size);
} }
SDL_UnlockMutex(private->mutex); SDL_UnlockMutex(private->mutex);

View File

@ -282,7 +282,7 @@ NAS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* Try for a closest match on audio format */ /* Try for a closest match on audio format */
format = 0; format = 0;

View File

@ -256,7 +256,7 @@ PAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* Open the audio device */ /* Open the audio device */
fd = OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0); fd = OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);

View File

@ -50,7 +50,7 @@ PSPAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, sizeof(*this->hidden)); SDL_zerop(this->hidden);
switch (this->spec.format & 0xff) { switch (this->spec.format & 0xff) {
case 8: case 8:
case 16: case 16:

View File

@ -529,13 +529,12 @@ PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
int rc = 0; int rc = 0;
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *) h = this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden)); SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
h = this->hidden;
paspec.format = PA_SAMPLE_INVALID; paspec.format = PA_SAMPLE_INVALID;

View File

@ -137,8 +137,7 @@ QSA_ThreadInit(_THIS)
static void static void
QSA_InitAudioParams(snd_pcm_channel_params_t * cpars) QSA_InitAudioParams(snd_pcm_channel_params_t * cpars)
{ {
SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t)); SDL_zerop(cpars);
cpars->channel = SND_PCM_CHANNEL_PLAYBACK; cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
cpars->mode = SND_PCM_MODE_BLOCK; cpars->mode = SND_PCM_MODE_BLOCK;
cpars->start_mode = SND_PCM_START_DATA; cpars->start_mode = SND_PCM_START_DATA;
@ -261,7 +260,7 @@ QSA_PlayDevice(_THIS)
continue; continue;
} else { } else {
if ((errno == EINVAL) || (errno == EIO)) { if ((errno == EINVAL) || (errno == EIO)) {
SDL_memset(&cstatus, 0, sizeof(cstatus)); SDL_zero(cstatus);
if (!this->hidden->iscapture) { if (!this->hidden->iscapture) {
cstatus.channel = SND_PCM_CHANNEL_PLAYBACK; cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
} else { } else {
@ -358,7 +357,7 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData)); SDL_zerop(this->hidden);
/* Initialize channel transfer parameters to default */ /* Initialize channel transfer parameters to default */
QSA_InitAudioParams(&cparams); QSA_InitAudioParams(&cparams);
@ -499,7 +498,7 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
} }
/* Make sure channel is setup right one last time */ /* Make sure channel is setup right one last time */
SDL_memset(&csetup, 0, sizeof(csetup)); SDL_zero(csetup);
if (!this->hidden->iscapture) { if (!this->hidden->iscapture) {
csetup.channel = SND_PCM_CHANNEL_PLAYBACK; csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
} else { } else {
@ -731,10 +730,9 @@ static void
QSA_Deinitialize(void) QSA_Deinitialize(void)
{ {
/* Clear devices array on shutdown */ /* Clear devices array on shutdown */
SDL_memset(qsa_playback_device, 0x00, /* !!! FIXME: we zero these on init...any reason to do it here? */
sizeof(QSA_Device) * QSA_MAX_DEVICES); SDL_zero(qsa_playback_device);
SDL_memset(qsa_capture_device, 0x00, SDL_zero(qsa_capture_device);
sizeof(QSA_Device) * QSA_MAX_DEVICES);
qsa_playback_devices = 0; qsa_playback_devices = 0;
qsa_capture_devices = 0; qsa_capture_devices = 0;
} }
@ -746,10 +744,8 @@ QSA_Init(SDL_AudioDriverImpl * impl)
int32_t status = 0; int32_t status = 0;
/* Clear devices array */ /* Clear devices array */
SDL_memset(qsa_playback_device, 0x00, SDL_zero(qsa_playback_device);
sizeof(QSA_Device) * QSA_MAX_DEVICES); SDL_zero(qsa_capture_device);
SDL_memset(qsa_capture_device, 0x00,
sizeof(QSA_Device) * QSA_MAX_DEVICES);
qsa_playback_devices = 0; qsa_playback_devices = 0;
qsa_capture_devices = 0; qsa_capture_devices = 0;

View File

@ -198,7 +198,7 @@ SNDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, sizeof(*this->hidden)); SDL_zerop(this->hidden);
this->hidden->mixlen = this->spec.size; this->hidden->mixlen = this->spec.size;

View File

@ -212,7 +212,7 @@ SUNAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* Open the audio device */ /* Open the audio device */
this->hidden->audio_fd = open(devname, flags, 0); this->hidden->audio_fd = open(devname, flags, 0);

View File

@ -228,7 +228,7 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden == NULL) { if (this->hidden == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
/* Initialize the wavebuf structures for closing */ /* Initialize the wavebuf structures for closing */
for (i = 0; i < NUM_BUFFERS; ++i) for (i = 0; i < NUM_BUFFERS; ++i)
@ -305,9 +305,9 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
if (this->hidden->mixbuf == NULL) { if (this->hidden->mixbuf == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_zero(this->hidden->wavebuf);
for (i = 0; i < NUM_BUFFERS; ++i) { for (i = 0; i < NUM_BUFFERS; ++i) {
SDL_memset(&this->hidden->wavebuf[i], 0,
sizeof(this->hidden->wavebuf[i]));
this->hidden->wavebuf[i].dwBufferLength = this->spec.size; this->hidden->wavebuf[i].dwBufferLength = this->spec.size;
this->hidden->wavebuf[i].dwFlags = WHDR_DONE; this->hidden->wavebuf[i].dwFlags = WHDR_DONE;
this->hidden->wavebuf[i].lpData = this->hidden->wavebuf[i].lpData =

View File

@ -342,7 +342,7 @@ XAUDIO2_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
IXAudio2_Release(ixa2); IXAudio2_Release(ixa2);
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
SDL_memset(this->hidden, 0, (sizeof *this->hidden)); SDL_zerop(this->hidden);
this->hidden->ixa2 = ixa2; this->hidden->ixa2 = ixa2;
this->hidden->semaphore = SDL_CreateSemaphore(1); this->hidden->semaphore = SDL_CreateSemaphore(1);
@ -377,7 +377,7 @@ XAUDIO2_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }
this->hidden->nextbuf = this->hidden->mixbuf; this->hidden->nextbuf = this->hidden->mixbuf;
SDL_memset(this->hidden->mixbuf, 0, 2 * this->hidden->mixlen); SDL_memset(this->hidden->mixbuf, this->spec.silence, 2 * this->hidden->mixlen);
/* We use XAUDIO2_DEFAULT_CHANNELS instead of this->spec.channels. On /* We use XAUDIO2_DEFAULT_CHANNELS instead of this->spec.channels. On
Xbox360, this means 5.1 output, but on Windows, it means "figure out Xbox360, this means 5.1 output, but on Windows, it means "figure out