From 1d6f547e7f20e48843e00ae521eeaa1cf454f8d5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 4 Jan 2020 10:39:33 +0100 Subject: [PATCH] (Audio) Cleanups --- audio/drivers/alsa.c | 2 +- audio/drivers/alsathread.c | 2 +- audio/drivers/jack.c | 14 +++++++------- audio/drivers/openal.c | 2 +- audio/drivers/tinyalsa.c | 12 ++++++------ audio/drivers/xaudio29.h | 15 ++++++++------- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/audio/drivers/alsa.c b/audio/drivers/alsa.c index f0d7b139a6..dbdc935e69 100644 --- a/audio/drivers/alsa.c +++ b/audio/drivers/alsa.c @@ -372,7 +372,7 @@ static void *alsa_device_list_new(void *data) n = hints; - while (*n != NULL) + while (*n) { char *name = snd_device_name_get_hint(*n, "NAME"); char *io = snd_device_name_get_hint(*n, "IOID"); diff --git a/audio/drivers/alsathread.c b/audio/drivers/alsathread.c index 33cfe02af4..c58dcc0515 100644 --- a/audio/drivers/alsathread.c +++ b/audio/drivers/alsathread.c @@ -361,7 +361,7 @@ static void *alsa_thread_device_list_new(void *data) n = hints; - while (*n != NULL) + while (*n) { char *name = snd_device_name_get_hint(*n, "NAME"); char *io = snd_device_name_get_hint(*n, "IOID"); diff --git a/audio/drivers/jack.c b/audio/drivers/jack.c index ede8c1a370..3275b3d62f 100644 --- a/audio/drivers/jack.c +++ b/audio/drivers/jack.c @@ -166,7 +166,7 @@ static void *ja_init(const char *device, unsigned rate, unsigned latency, #endif jd->client = jack_client_open("RetroArch", JackNullOption, NULL); - if (jd->client == NULL) + if (!jd->client) goto error; *new_rate = jack_get_sample_rate(jd->client); @@ -176,14 +176,14 @@ static void *ja_init(const char *device, unsigned rate, unsigned latency, jd->ports[0] = jack_port_register(jd->client, "left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); jd->ports[1] = jack_port_register(jd->client, "right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - if (jd->ports[0] == NULL || jd->ports[1] == NULL) + if (!jd->ports[0] || !jd->ports[1]) { RARCH_ERR("[JACK]: Failed to register ports.\n"); goto error; } jports = jack_get_ports(jd->client, NULL, NULL, JackPortIsPhysical | JackPortIsInput); - if (jports == NULL) + if (!jports) { RARCH_ERR("[JACK]: Failed to get ports.\n"); goto error; @@ -196,7 +196,7 @@ static void *ja_init(const char *device, unsigned rate, unsigned latency, for (i = 0; i < 2; i++) { jd->buffer[i] = jack_ringbuffer_create(bufsize); - if (jd->buffer[i] == NULL) + if (!jd->buffer[i]) { RARCH_ERR("[JACK]: Failed to create buffers.\n"); goto error; @@ -229,7 +229,7 @@ static void *ja_init(const char *device, unsigned rate, unsigned latency, error: for (i = 0; i < parsed; i++) free(dest_ports[i]); - if (jports != NULL) + if (jports) jack_free(jports); free(jd); return NULL; @@ -334,14 +334,14 @@ static void ja_free(void *data) jd->shutdown = true; - if (jd->client != NULL) + if (jd->client) { jack_deactivate(jd->client); jack_client_close(jd->client); } for (i = 0; i < 2; i++) - if (jd->buffer[i] != NULL) + if (jd->buffer[i]) jack_ringbuffer_free(jd->buffer[i]); #ifdef HAVE_THREADS diff --git a/audio/drivers/openal.c b/audio/drivers/openal.c index 1c9cfc6575..109edb83ee 100644 --- a/audio/drivers/openal.c +++ b/audio/drivers/openal.c @@ -115,7 +115,7 @@ static void *al_init(const char *device, unsigned rate, unsigned latency, al->buffers = (ALuint*)calloc(al->num_buffers, sizeof(ALuint)); al->res_buf = (ALuint*)calloc(al->num_buffers, sizeof(ALuint)); - if (al->buffers == NULL || al->res_buf == NULL) + if (!al->buffers || !al->res_buf) goto error; alGenSources(1, &al->source); diff --git a/audio/drivers/tinyalsa.c b/audio/drivers/tinyalsa.c index 1aea14ceaf..4344d7a7c8 100644 --- a/audio/drivers/tinyalsa.c +++ b/audio/drivers/tinyalsa.c @@ -808,7 +808,7 @@ static unsigned int pcm_get_channels(const struct pcm *pcm) * */ static const struct pcm_config * pcm_get_config(const struct pcm *pcm) { - if (pcm == NULL) + if (!pcm) return NULL; return &pcm->config; } @@ -929,7 +929,7 @@ static int pcm_set_config(struct pcm *pcm, const struct pcm_config *config) struct snd_pcm_sw_params sparams; struct snd_pcm_hw_params params; - if (pcm == NULL) + if (!pcm) return -EFAULT; if (config) @@ -1293,7 +1293,7 @@ static int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail, */ static int pcm_is_ready(const struct pcm *pcm) { - if (pcm != NULL) + if (pcm) return pcm->fd >= 0; return 0; } @@ -1582,7 +1582,7 @@ static const struct pcm_mask *pcm_params_get_mask(const struct pcm_params *pcm_p { int p; struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params; - if (params == NULL) + if (!params) return NULL; p = pcm_param_to_alsa(param); @@ -2185,7 +2185,7 @@ static void * tinyalsa_init(const char *devicestr, unsigned rate, RARCH_LOG("[TINYALSA]: Using card: %u, device: %u.\n", card, device); tinyalsa->params = pcm_params_get(card, device, PCM_OUT); - if (tinyalsa->params == NULL) + if (!tinyalsa->params) { RARCH_ERR("[TINYALSA]: params: Cannot open audio device.\n"); goto error; @@ -2224,7 +2224,7 @@ static void * tinyalsa_init(const char *devicestr, unsigned rate, tinyalsa->pcm = pcm_open(card, device, PCM_OUT, &config); - if (tinyalsa->pcm == NULL) + if (!tinyalsa->pcm) { RARCH_ERR("[TINYALSA]: Failed to allocate memory for pcm.\n"); goto error; diff --git a/audio/drivers/xaudio29.h b/audio/drivers/xaudio29.h index 4e542c1cca..d05cb8f67d 100644 --- a/audio/drivers/xaudio29.h +++ b/audio/drivers/xaudio29.h @@ -869,26 +869,27 @@ static INLINE HRESULT XAudio2Create(_Outptr_ IXAudio2** ppXAudio2, typedef HRESULT(__stdcall *XAudio2CreateWithVersionInfoFunc)(_Outptr_ IXAudio2**, UINT32, XAUDIO2_PROCESSOR, DWORD); typedef HRESULT(__stdcall *XAudio2CreateInfoFunc)(_Outptr_ IXAudio2**, UINT32, XAUDIO2_PROCESSOR); - static HMODULE s_dllInstance = NULL; - static XAudio2CreateWithVersionInfoFunc s_pfnAudio2CreateWithVersion = NULL; + static XAudio2CreateWithVersionInfoFunc + s_pfnAudio2CreateWithVersion = NULL; static XAudio2CreateInfoFunc s_pfnAudio2Create = NULL; + static HMODULE s_dllInstance = NULL; - if (s_dllInstance == NULL) + if (!s_dllInstance) { s_dllInstance = LoadLibraryEx(XAUDIO2_DLL, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); - if (s_dllInstance == NULL) + if (!s_dllInstance) return HRESULT_FROM_WIN32(GetLastError()); s_pfnAudio2CreateWithVersion = (XAudio2CreateWithVersionInfoFunc)(void*)GetProcAddress(s_dllInstance, "XAudio2CreateWithVersionInfo"); - if (s_pfnAudio2CreateWithVersion == NULL) + if (!s_pfnAudio2CreateWithVersion) { s_pfnAudio2Create = (XAudio2CreateInfoFunc)(void*)GetProcAddress(s_dllInstance, "XAudio2Create"); - if (s_pfnAudio2Create == NULL) + if (!s_pfnAudio2Create) return HRESULT_FROM_WIN32(GetLastError()); } } - if (s_pfnAudio2CreateWithVersion != NULL) + if (s_pfnAudio2CreateWithVersion) return (*s_pfnAudio2CreateWithVersion)(ppXAudio2, Flags, XAudio2Processor, NTDDI_VERSION); return (*s_pfnAudio2Create)(ppXAudio2, Flags, XAudio2Processor); }