diff --git a/audio/drivers/alsa.c b/audio/drivers/alsa.c index d6a6b2c798..6ee8336386 100644 --- a/audio/drivers/alsa.c +++ b/audio/drivers/alsa.c @@ -59,15 +59,13 @@ static void *alsa_init(const char *device, unsigned rate, unsigned latency) { snd_pcm_format_t format; snd_pcm_uframes_t buffer_size; - snd_pcm_hw_params_t *params = NULL; + snd_pcm_hw_params_t *params = NULL; snd_pcm_sw_params_t *sw_params = NULL; - - unsigned latency_usec = latency * 1000; - unsigned channels = 2; - unsigned periods = 4; - - const char *alsa_dev = "default"; - alsa_t *alsa = (alsa_t*)calloc(1, sizeof(alsa_t)); + unsigned latency_usec = latency * 1000; + unsigned channels = 2; + unsigned periods = 4; + const char *alsa_dev = "default"; + alsa_t *alsa = (alsa_t*)calloc(1, sizeof(alsa_t)); if (!alsa) return NULL; diff --git a/audio/drivers/alsa_qsa.c b/audio/drivers/alsa_qsa.c index 4724cce92a..a2a3743f40 100644 --- a/audio/drivers/alsa_qsa.c +++ b/audio/drivers/alsa_qsa.c @@ -49,11 +49,11 @@ static void *alsa_qsa_init(const char *device, unsigned rate, unsigned latency) { int err, card, dev, i; - snd_pcm_channel_params_t params = {0}; snd_pcm_channel_info_t pi; - snd_pcm_channel_setup_t setup = {0}; - settings_t *settings = config_get_ptr(); - alsa_t *alsa = (alsa_t*)calloc(1, sizeof(alsa_t)); + snd_pcm_channel_params_t params = {0}; + snd_pcm_channel_setup_t setup = {0}; + settings_t *settings = config_get_ptr(); + alsa_t *alsa = (alsa_t*)calloc(1, sizeof(alsa_t)); if (!alsa) return NULL; @@ -164,9 +164,9 @@ error: static int check_pcm_status(void *data, int channel_type) { - alsa_t *alsa = (alsa_t*)data; snd_pcm_channel_status_t status; - int ret = EOK; + alsa_t *alsa = (alsa_t*)data; + int ret = EOK; memset(&status, 0, sizeof (status)); status.channel = channel_type; diff --git a/audio/drivers/alsathread.c b/audio/drivers/alsathread.c index 1f638f63c6..7dd8c6ebb5 100644 --- a/audio/drivers/alsathread.c +++ b/audio/drivers/alsathread.c @@ -54,8 +54,8 @@ typedef struct alsa_thread static void alsa_worker_thread(void *data) { alsa_thread_t *alsa = (alsa_thread_t*)data; + uint8_t *buf = (uint8_t *)calloc(1, alsa->period_size); - uint8_t *buf = (uint8_t *)calloc(1, alsa->period_size); if (!buf) { RARCH_ERR("failed to allocate audio buffer"); @@ -158,19 +158,16 @@ static void alsa_thread_free(void *data) static void *alsa_thread_init(const char *device, unsigned rate, unsigned latency) { - alsa_thread_t *alsa = (alsa_thread_t*)calloc(1, sizeof(alsa_thread_t)); - - snd_pcm_hw_params_t *params = NULL; - snd_pcm_sw_params_t *sw_params = NULL; - - const char *alsa_dev = device ? device : "default"; - - unsigned latency_usec = latency * 1000 / 2; - - unsigned channels = 2; - unsigned periods = 4; snd_pcm_uframes_t buffer_size; snd_pcm_format_t format; + snd_pcm_hw_params_t *params = NULL; + snd_pcm_sw_params_t *sw_params = NULL; + const char *alsa_dev = device ? device : "default"; + unsigned latency_usec = latency * 1000 / 2; + unsigned channels = 2; + unsigned periods = 4; + alsa_thread_t *alsa = (alsa_thread_t*) + calloc(1, sizeof(alsa_thread_t)); if (!alsa) return NULL; @@ -287,7 +284,8 @@ static ssize_t alsa_thread_write(void *data, const void *buf, size_t size) else { size_t write_amt = MIN(size - written, avail); - fifo_write(alsa->buffer, (const char*)buf + written, write_amt); + fifo_write(alsa->buffer, + (const char*)buf + written, write_amt); slock_unlock(alsa->fifo_lock); written += write_amt; } diff --git a/audio/drivers/coreaudio.c b/audio/drivers/coreaudio.c index 2a49e9885d..d257875f40 100644 --- a/audio/drivers/coreaudio.c +++ b/audio/drivers/coreaudio.c @@ -95,8 +95,8 @@ static OSStatus audio_write_cb(void *userdata, const AudioTimeStamp *time_stamp, UInt32 bus_number, UInt32 number_frames, AudioBufferList *io_data) { - void *outbuf; unsigned write_avail; + void *outbuf = NULL; coreaudio_t *dev = (coreaudio_t*)userdata; (void)time_stamp; @@ -143,30 +143,30 @@ static void coreaudio_interrupt_listener(void *data, UInt32 interrupt_state) static void choose_output_device(coreaudio_t *dev, const char* device) { unsigned i; - AudioDeviceID *devices; + UInt32 deviceCount; + AudioDeviceID *devices = NULL; AudioObjectPropertyAddress propaddr = { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; - - UInt32 size = 0, deviceCount; + UInt32 size = 0; if (AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propaddr, 0, 0, &size) != noErr) return; deviceCount = size / sizeof(AudioDeviceID); - devices = (AudioDeviceID*)malloc(size); + devices = (AudioDeviceID*)malloc(size); if (!devices || AudioObjectGetPropertyData(kAudioObjectSystemObject, &propaddr, 0, 0, &size, devices) != noErr) goto done; - propaddr.mScope = kAudioDevicePropertyScopeOutput; + propaddr.mScope = kAudioDevicePropertyScopeOutput; propaddr.mSelector = kAudioDevicePropertyDeviceName; - size = 1024; + size = 1024; for (i = 0; i < deviceCount; i ++) { @@ -206,21 +206,20 @@ static void *coreaudio_init(const char *device, AudioStreamBasicDescription stream_desc = {0}; bool component_unavailable = false; static bool session_initialized = false; - coreaudio_t *dev = NULL; #ifdef OSX_PPC ComponentDescription desc = {0}; #else AudioComponentDescription desc = {0}; #endif settings_t *settings = config_get_ptr(); + coreaudio_t *dev = (coreaudio_t*) + calloc(1, sizeof(*dev)); + if (!dev) + return NULL; (void)session_initialized; (void)device; - dev = (coreaudio_t*)calloc(1, sizeof(*dev)); - if (!dev) - return NULL; - dev->lock = slock_new(); dev->cond = scond_new(); @@ -344,9 +343,9 @@ error: static ssize_t coreaudio_write(void *data, const void *buf_, size_t size) { - coreaudio_t *dev = (coreaudio_t*)data; + coreaudio_t *dev = (coreaudio_t*)data; const uint8_t *buf = (const uint8_t*)buf_; - size_t written = 0; + size_t written = 0; while (!g_interrupted && size > 0) { diff --git a/audio/drivers/ctr_csnd_audio.c b/audio/drivers/ctr_csnd_audio.c index d71a85f7b4..a1bc9e3bad 100644 --- a/audio/drivers/ctr_csnd_audio.c +++ b/audio/drivers/ctr_csnd_audio.c @@ -48,37 +48,40 @@ typedef struct static void ctr_csnd_audio_update_playpos(ctr_csnd_audio_t* ctr) { - uint32_t samples_played; - uint64_t current_tick; + uint64_t current_tick = svcGetSystemTick(); + uint32_t samples_played = (current_tick - ctr->cpu_ticks_last) + / CTR_CSND_CPU_TICKS_PER_SAMPLE; - current_tick = svcGetSystemTick(); - samples_played = (current_tick - ctr->cpu_ticks_last) / CTR_CSND_CPU_TICKS_PER_SAMPLE; ctr->playpos = (ctr->playpos + samples_played) & CTR_CSND_AUDIO_COUNT_MASK; ctr->cpu_ticks_last += samples_played * CTR_CSND_CPU_TICKS_PER_SAMPLE; } -Result csndPlaySound_custom(int chn, u32 flags, float vol, float pan, void* data0, void* data1, u32 size) +Result csndPlaySound_custom(int chn, u32 flags, float vol, float pan, + void* data0, void* data1, u32 size) { - if (!(csndChannels & BIT(chn))) - return 1; - - u32 paddr0 = 0, paddr1 = 0; - + u32 paddr0 = 0; + u32 paddr1 = 0; int encoding = (flags >> 12) & 3; int loopMode = (flags >> 10) & 3; - if (!loopMode) flags |= SOUND_ONE_SHOT; + if (!(csndChannels & BIT(chn))) + return 1; + + if (!loopMode) + flags |= SOUND_ONE_SHOT; if (encoding != CSND_ENCODING_PSG) { - if (data0) paddr0 = osConvertVirtToPhys(data0); - if (data1) paddr1 = osConvertVirtToPhys(data1); + if (data0) + paddr0 = osConvertVirtToPhys(data0); + if (data1) + paddr1 = osConvertVirtToPhys(data1); if (data0 && encoding == CSND_ENCODING_ADPCM) { int adpcmSample = ((s16*)data0)[-2]; - int adpcmIndex = ((u8*)data0)[-2]; + int adpcmIndex = ((u8*)data0)[-2]; CSND_SetAdpcmState(chn, 0, adpcmSample, adpcmIndex); } } @@ -102,7 +105,7 @@ Result csndPlaySound_custom(int chn, u32 flags, float vol, float pan, void* data static void *ctr_csnd_audio_init(const char *device, unsigned rate, unsigned latency) { ctr_csnd_audio_t *ctr = (ctr_csnd_audio_t*)calloc(1, sizeof(ctr_csnd_audio_t)); - settings_t *settings = config_get_ptr(); + settings_t *settings = config_get_ptr(); if (!ctr) return NULL; @@ -158,11 +161,11 @@ static void ctr_csnd_audio_free(void *data) static ssize_t ctr_csnd_audio_write(void *data, const void *buf, size_t size) { int i; - uint32_t samples_played = 0; - uint64_t current_tick = 0; + uint32_t samples_played = 0; + uint64_t current_tick = 0; static struct retro_perf_counter ctraudio_f = {0}; - const uint16_t *src = buf; - ctr_csnd_audio_t *ctr = (ctr_csnd_audio_t*)data; + const uint16_t *src = buf; + ctr_csnd_audio_t *ctr = (ctr_csnd_audio_t*)data; (void)data; (void)buf; diff --git a/audio/drivers/ctr_dsp_audio.c b/audio/drivers/ctr_dsp_audio.c index 3b93e23736..67df567226 100644 --- a/audio/drivers/ctr_dsp_audio.c +++ b/audio/drivers/ctr_dsp_audio.c @@ -39,7 +39,7 @@ typedef struct static void *ctr_dsp_audio_init(const char *device, unsigned rate, unsigned latency) { - ctr_dsp_audio_t *ctr; + ctr_dsp_audio_t *ctr = NULL; settings_t *settings = config_get_ptr(); (void)device; @@ -95,10 +95,10 @@ static void ctr_dsp_audio_free(void *data) static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t size) { - static struct retro_perf_counter ctraudio_dsp_f = {0}; - ctr_dsp_audio_t* ctr = (ctr_dsp_audio_t*)data; u32 pos; - uint32_t sample_pos = ndspChnGetSamplePos(ctr->channel); + static struct retro_perf_counter ctraudio_dsp_f = {0}; + ctr_dsp_audio_t * ctr = (ctr_dsp_audio_t*)data; + uint32_t sample_pos = ndspChnGetSamplePos(ctr->channel); if((((sample_pos - ctr->pos) & CTR_DSP_AUDIO_COUNT_MASK) < (CTR_DSP_AUDIO_COUNT >> 2)) || (((ctr->pos - sample_pos ) & CTR_DSP_AUDIO_COUNT_MASK) < (CTR_DSP_AUDIO_COUNT >> 4)) || diff --git a/audio/drivers/dsound.c b/audio/drivers/dsound.c index 34c136857a..2cdcf4d234 100644 --- a/audio/drivers/dsound.c +++ b/audio/drivers/dsound.c @@ -68,7 +68,8 @@ typedef struct dsound volatile bool thread_alive; } dsound_t; -static INLINE unsigned write_avail(unsigned read_ptr, unsigned write_ptr, unsigned buffer_size) +static INLINE unsigned write_avail(unsigned read_ptr, + unsigned write_ptr, unsigned buffer_size) { return (read_ptr + buffer_size - write_ptr) % buffer_size; } @@ -91,8 +92,8 @@ struct audio_lock static INLINE bool grab_region(dsound_t *ds, uint32_t write_ptr, struct audio_lock *region) { - const char *err; - HRESULT res = IDirectSoundBuffer_Lock(ds->dsb, write_ptr, CHUNK_SIZE, + const char *err = NULL; + HRESULT res = IDirectSoundBuffer_Lock(ds->dsb, write_ptr, CHUNK_SIZE, ®ion->chunk1, ®ion->size1, ®ion->chunk2, ®ion->size2, 0); if (res == DSERR_BUFFERLOST) @@ -132,7 +133,8 @@ static INLINE bool grab_region(dsound_t *ds, uint32_t write_ptr, static INLINE void release_region(dsound_t *ds, const struct audio_lock *region) { - IDirectSoundBuffer_Unlock(ds->dsb, region->chunk1, region->size1, region->chunk2, region->size2); + IDirectSoundBuffer_Unlock(ds->dsb, region->chunk1, + region->size1, region->chunk2, region->size2); } static void dsound_thread(void *data) @@ -236,8 +238,9 @@ static bool dsound_start_thread(dsound_t *ds) static void dsound_clear_buffer(dsound_t *ds) { - void *ptr; DWORD size; + void *ptr = NULL; + IDirectSoundBuffer_SetCurrentPosition(ds->dsb, 0); if (IDirectSoundBuffer_Lock(ds->dsb, 0, 0, &ptr, &size, @@ -424,8 +427,8 @@ static void dsound_set_nonblock_state(void *data, bool state) static ssize_t dsound_write(void *data, const void *buf_, size_t size) { - size_t written = 0; - dsound_t *ds = (dsound_t*)data; + size_t written = 0; + dsound_t *ds = (dsound_t*)data; const uint8_t *buf = (const uint8_t*)buf_; if (!ds->thread_alive) diff --git a/audio/drivers/gx_audio.c b/audio/drivers/gx_audio.c index ac53fb3929..28006d97da 100644 --- a/audio/drivers/gx_audio.c +++ b/audio/drivers/gx_audio.c @@ -118,9 +118,9 @@ static INLINE void copy_swapped(uint32_t * restrict dst, static ssize_t gx_audio_write(void *data, const void *buf_, size_t size) { - size_t frames = size >> 2; + size_t frames = size >> 2; const uint32_t *buf = buf_; - gx_audio_t *wa = data; + gx_audio_t *wa = data; while (frames) { diff --git a/audio/drivers/jack.c b/audio/drivers/jack.c index d8d218a949..e36b3fb54b 100644 --- a/audio/drivers/jack.c +++ b/audio/drivers/jack.c @@ -100,10 +100,10 @@ static void shutdown_cb(void *data) static int parse_ports(char **dest_ports, const char **jports) { int i; - char *save = NULL; - int parsed = 0; + char *save = NULL; + int parsed = 0; settings_t *settings = config_get_ptr(); - const char *con = strtok_r(settings->audio.device, ",", &save); + const char *con = strtok_r(settings->audio.device, ",", &save); if (con) dest_ports[parsed++] = strdup(con); @@ -120,9 +120,10 @@ static int parse_ports(char **dest_ports, const char **jports) static size_t find_buffersize(jack_t *jd, int latency) { jack_latency_range_t range; - int i, buffer_frames, min_buffer_frames, jack_latency = 0; + int i, buffer_frames, min_buffer_frames; + int jack_latency = 0; settings_t *settings = config_get_ptr(); - int frames = latency * settings->audio.out_rate / 1000; + int frames = latency * settings->audio.out_rate / 1000; for (i = 0; i < 2; i++) { @@ -147,12 +148,12 @@ static size_t find_buffersize(jack_t *jd, int latency) static void *ja_init(const char *device, unsigned rate, unsigned latency) { int i; - const char **jports = NULL; char *dest_ports[2]; - size_t bufsize = 0; - int parsed = 0; + const char **jports = NULL; + size_t bufsize = 0; + int parsed = 0; settings_t *settings = config_get_ptr(); - jack_t *jd = (jack_t*)calloc(1, sizeof(jack_t)); + jack_t *jd = (jack_t*)calloc(1, sizeof(jack_t)); if (!jd) return NULL; @@ -233,10 +234,9 @@ error: static size_t write_buffer(jack_t *jd, const float *buf, size_t size) { int i; - size_t j, frames, written = 0; + size_t j, written = 0; jack_default_audio_sample_t out_deinterleaved_buffer[2][AUDIO_CHUNK_SIZE_NONBLOCKING * AUDIO_MAX_RATIO]; - - frames = FRAMES(size); + size_t frames = FRAMES(size); /* Avoid buffer overflow if a DSP plugin generated a huge number of frames. */ if (frames > AUDIO_CHUNK_SIZE_NONBLOCKING * AUDIO_MAX_RATIO) diff --git a/audio/drivers/openal.c b/audio/drivers/openal.c index 34ee8c5503..41dd9b4cac 100644 --- a/audio/drivers/openal.c +++ b/audio/drivers/openal.c @@ -171,9 +171,9 @@ static size_t al_fill_internal_buf(al_t *al, const void *buf, size_t size) static ssize_t al_write(void *data, const void *buf_, size_t size) { - al_t *al = (al_t*)data; + al_t *al = (al_t*)data; const uint8_t *buf = (const uint8_t*)buf_; - size_t written = 0; + size_t written = 0; while (size) { diff --git a/audio/drivers/opensl.c b/audio/drivers/opensl.c index 2ae03a0532..530d0d8e99 100644 --- a/audio/drivers/opensl.c +++ b/audio/drivers/opensl.c @@ -101,24 +101,18 @@ static void sl_free(void *data) static void *sl_init(const char *device, unsigned rate, unsigned latency) { unsigned i; - SLInterfaceID id; - SLboolean req; - SLresult res; - sl_t *sl; - SLDataFormat_PCM fmt_pcm = {0}; - SLDataSource audio_src = {0}; - SLDataSink audio_sink = {0}; + SLDataFormat_PCM fmt_pcm = {0}; + SLDataSource audio_src = {0}; + SLDataSink audio_sink = {0}; SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {0}; SLDataLocator_OutputMix loc_outmix = {0}; - settings_t *settings = config_get_ptr(); + settings_t *settings = config_get_ptr(); + SLresult res = 0; + SLInterfaceID id = SL_IID_ANDROIDSIMPLEBUFFERQUEUE; + SLboolean req = SL_BOOLEAN_TRUE; + sl_t *sl = (sl_t*)calloc(1, sizeof(sl_t)); (void)device; - - id = SL_IID_ANDROIDSIMPLEBUFFERQUEUE; - req = SL_BOOLEAN_TRUE; - - res = 0; - sl = (sl_t*)calloc(1, sizeof(sl_t)); if (!sl) goto error; @@ -132,14 +126,14 @@ static void *sl_init(const char *device, unsigned rate, unsigned latency) GOTO_IF_FAIL(SLObjectItf_Realize(sl->output_mix, SL_BOOLEAN_FALSE)); if (settings->audio.block_frames) - sl->buf_size = settings->audio.block_frames * 4; + sl->buf_size = settings->audio.block_frames * 4; else - sl->buf_size = next_pow2(32 * latency); + sl->buf_size = next_pow2(32 * latency); - sl->buf_count = (latency * 4 * rate + 500) / 1000; - sl->buf_count = (sl->buf_count + sl->buf_size / 2) / sl->buf_size; + sl->buf_count = (latency * 4 * rate + 500) / 1000; + sl->buf_count = (sl->buf_count + sl->buf_size / 2) / sl->buf_size; - sl->buffer = (uint8_t**)calloc(sizeof(uint8_t*), sl->buf_count); + sl->buffer = (uint8_t**)calloc(sizeof(uint8_t*), sl->buf_count); if (!sl->buffer) goto error; @@ -153,24 +147,24 @@ static void *sl_init(const char *device, unsigned rate, unsigned latency) RARCH_LOG("[SLES]: Setting audio latency: Block size = %u, Blocks = %u, Total = %u ...\n", sl->buf_size, sl->buf_count, sl->buf_size * sl->buf_count); - fmt_pcm.formatType = SL_DATAFORMAT_PCM; - fmt_pcm.numChannels = 2; - fmt_pcm.samplesPerSec = rate * 1000; // Samplerate is in milli-Hz. - fmt_pcm.bitsPerSample = 16; - fmt_pcm.containerSize = 16; - fmt_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; - fmt_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; /* Android only. */ + fmt_pcm.formatType = SL_DATAFORMAT_PCM; + fmt_pcm.numChannels = 2; + fmt_pcm.samplesPerSec = rate * 1000; // Samplerate is in milli-Hz. + fmt_pcm.bitsPerSample = 16; + fmt_pcm.containerSize = 16; + fmt_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; + fmt_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; /* Android only. */ - audio_src.pLocator = &loc_bufq; - audio_src.pFormat = &fmt_pcm; + audio_src.pLocator = &loc_bufq; + audio_src.pFormat = &fmt_pcm; - loc_bufq.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE; - loc_bufq.numBuffers = sl->buf_count; + loc_bufq.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE; + loc_bufq.numBuffers = sl->buf_count; loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; loc_outmix.outputMix = sl->output_mix; - audio_sink.pLocator = &loc_outmix; + audio_sink.pLocator = &loc_outmix; GOTO_IF_FAIL(SLEngineItf_CreateAudioPlayer(sl->engine, &sl->buffer_queue_object, &audio_src, &audio_sink, @@ -180,14 +174,15 @@ static void *sl_init(const char *device, unsigned rate, unsigned latency) GOTO_IF_FAIL(SLObjectItf_GetInterface(sl->buffer_queue_object, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &sl->buffer_queue)); - sl->cond = scond_new(); - sl->lock = slock_new(); + sl->cond = scond_new(); + sl->lock = slock_new(); (*sl->buffer_queue)->RegisterCallback(sl->buffer_queue, opensl_callback, sl); /* Enqueue a bit to get stuff rolling. */ - sl->buffered_blocks = sl->buf_count; - sl->buffer_index = 0; + sl->buffered_blocks = sl->buf_count; + sl->buffer_index = 0; + for (i = 0; i < sl->buf_count; i++) (*sl->buffer_queue)->Enqueue(sl->buffer_queue, sl->buffer[i], sl->buf_size); @@ -204,8 +199,10 @@ error: static bool sl_stop(void *data) { - sl_t *sl = (sl_t*)data; - sl->is_paused = (SLPlayItf_SetPlayState(sl->player, SL_PLAYSTATE_STOPPED) == SL_RESULT_SUCCESS) ? true : false; + sl_t *sl = (sl_t*)data; + sl->is_paused = (SLPlayItf_SetPlayState(sl->player, SL_PLAYSTATE_STOPPED) + == SL_RESULT_SUCCESS) ? true : false; + return sl->is_paused ? true : false; } @@ -226,16 +223,17 @@ static void sl_set_nonblock_state(void *data, bool state) static bool sl_start(void *data) { - sl_t *sl = (sl_t*)data; - sl->is_paused = (SLPlayItf_SetPlayState(sl->player, SL_PLAYSTATE_PLAYING) == SL_RESULT_SUCCESS) ? false : true; + sl_t *sl = (sl_t*)data; + sl->is_paused = (SLPlayItf_SetPlayState(sl->player, SL_PLAYSTATE_PLAYING) + == SL_RESULT_SUCCESS) ? false : true; return sl->is_paused ? false : true; } static ssize_t sl_write(void *data, const void *buf_, size_t size) { - sl_t *sl = (sl_t*)data; - size_t written = 0; + sl_t *sl = (sl_t*)data; + size_t written = 0; const uint8_t *buf = (const uint8_t*)buf_; while (size) @@ -268,10 +266,10 @@ static ssize_t sl_write(void *data, const void *buf_, size_t size) if (sl->buffer_ptr >= sl->buf_size) { - SLresult res = (*sl->buffer_queue)->Enqueue(sl->buffer_queue, sl->buffer[sl->buffer_index], sl->buf_size); + SLresult res = (*sl->buffer_queue)->Enqueue(sl->buffer_queue, sl->buffer[sl->buffer_index], sl->buf_size); sl->buffer_index = (sl->buffer_index + 1) % sl->buf_count; __sync_fetch_and_add(&sl->buffered_blocks, 1); - sl->buffer_ptr = 0; + sl->buffer_ptr = 0; if (res != SL_RESULT_SUCCESS) { diff --git a/audio/drivers/oss.c b/audio/drivers/oss.c index 72a73abf76..5cbe358b65 100644 --- a/audio/drivers/oss.c +++ b/audio/drivers/oss.c @@ -46,12 +46,11 @@ static bool oss_is_paused; static void *oss_init(const char *device, unsigned rate, unsigned latency) { int frags, frag, channels, format, new_rate; - int *fd = (int*)calloc(1, sizeof(int)); - settings_t *settings = config_get_ptr(); - + int *fd = (int*)calloc(1, sizeof(int)); + settings_t *settings = config_get_ptr(); const char *oss_device = device ? device : DEFAULT_OSS_DEV; - if (fd == NULL) + if (!fd) return NULL; if ((*fd = open(oss_device, O_WRONLY)) < 0) @@ -62,39 +61,24 @@ static void *oss_init(const char *device, unsigned rate, unsigned latency) } frags = (latency * rate * 4) / (1000 * (1 << 10)); - frag = (frags << 16) | 10; + frag = (frags << 16) | 10; if (ioctl(*fd, SNDCTL_DSP_SETFRAGMENT, &frag) < 0) RARCH_WARN("Cannot set fragment sizes. Latency might not be as expected ...\n"); channels = 2; - format = is_little_endian() ? AFMT_S16_LE : AFMT_S16_BE; + format = is_little_endian() ? AFMT_S16_LE : AFMT_S16_BE; if (ioctl(*fd, SNDCTL_DSP_CHANNELS, &channels) < 0) - { - close(*fd); - free(fd); - perror("ioctl"); - return NULL; - } + goto error; if (ioctl(*fd, SNDCTL_DSP_SETFMT, &format) < 0) - { - close(*fd); - free(fd); - perror("ioctl"); - return NULL; - } + goto error; new_rate = rate; if (ioctl(*fd, SNDCTL_DSP_SPEED, &new_rate) < 0) - { - close(*fd); - free(fd); - perror("ioctl"); - return NULL; - } + goto error; if (new_rate != (int)rate) { @@ -103,6 +87,12 @@ static void *oss_init(const char *device, unsigned rate, unsigned latency) } return fd; + +error: + close(*fd); + free(fd); + perror("ioctl"); + return NULL; } static ssize_t oss_write(void *data, const void *buf, size_t size) diff --git a/audio/drivers/ps3_audio.c b/audio/drivers/ps3_audio.c index 2b52de1abf..1b80466e99 100644 --- a/audio/drivers/ps3_audio.c +++ b/audio/drivers/ps3_audio.c @@ -81,20 +81,18 @@ static void *ps3_audio_init(const char *device, unsigned rate, unsigned latency) { CellAudioPortParam params; - ps3_audio_t *data = NULL; + ps3_audio_t *data = calloc(1, sizeof(*data)); + if (!data) + return NULL; (void)latency; (void)device; (void)rate; - data = calloc(1, sizeof(*data)); - if (!data) - return NULL; - cellAudioInit(); params.numChannels = AUDIO_CHANNELS; - params.numBlocks = AUDIO_BLOCKS; + params.numBlocks = AUDIO_BLOCKS; #if 0 #ifdef HAVE_HEADSET if(global->console.sound.mode == SOUND_MODE_HEADSET) diff --git a/audio/drivers/pulse.c b/audio/drivers/pulse.c index df59b6bdc7..928da3f0ab 100644 --- a/audio/drivers/pulse.c +++ b/audio/drivers/pulse.c @@ -146,14 +146,11 @@ static void buffer_attr_cb(pa_stream *s, void *data) static void *pulse_init(const char *device, unsigned rate, unsigned latency) { - pa_sample_spec spec; - pa_t *pa; - pa_buffer_attr buffer_attr = {0}; + pa_sample_spec spec = {0}; + pa_buffer_attr buffer_attr = {0}; const pa_buffer_attr *server_attr = NULL; + pa_t *pa = (pa_t*)calloc(1, sizeof(*pa)); - memset(&spec, 0, sizeof(spec)); - - pa = (pa_t*)calloc(1, sizeof(*pa)); if (!pa) goto error; @@ -179,11 +176,11 @@ static void *pulse_init(const char *device, unsigned rate, unsigned latency) if (pa_context_get_state(pa->context) != PA_CONTEXT_READY) goto unlock_error; - spec.format = is_little_endian() ? PA_SAMPLE_FLOAT32LE : PA_SAMPLE_FLOAT32BE; + spec.format = is_little_endian() ? PA_SAMPLE_FLOAT32LE : PA_SAMPLE_FLOAT32BE; spec.channels = 2; - spec.rate = rate; + spec.rate = rate; - pa->stream = pa_stream_new(pa->context, "audio", &spec, NULL); + pa->stream = pa_stream_new(pa->context, "audio", &spec, NULL); if (!pa->stream) goto unlock_error; @@ -194,12 +191,13 @@ static void *pulse_init(const char *device, unsigned rate, unsigned latency) pa_stream_set_buffer_attr_callback(pa->stream, buffer_attr_cb, pa); buffer_attr.maxlength = -1; - buffer_attr.tlength = pa_usec_to_bytes(latency * PA_USEC_PER_MSEC, &spec); - buffer_attr.prebuf = -1; - buffer_attr.minreq = -1; - buffer_attr.fragsize = -1; + buffer_attr.tlength = pa_usec_to_bytes(latency * PA_USEC_PER_MSEC, &spec); + buffer_attr.prebuf = -1; + buffer_attr.minreq = -1; + buffer_attr.fragsize = -1; - if (pa_stream_connect_playback(pa->stream, NULL, &buffer_attr, PA_STREAM_ADJUST_LATENCY, NULL, NULL) < 0) + if (pa_stream_connect_playback(pa->stream, NULL, + &buffer_attr, PA_STREAM_ADJUST_LATENCY, NULL, NULL) < 0) goto error; pa_threaded_mainloop_wait(pa->mainloop); @@ -231,9 +229,9 @@ error: static ssize_t pulse_write(void *data, const void *buf_, size_t size) { - pa_t *pa = (pa_t*)data; + pa_t *pa = (pa_t*)data; const uint8_t *buf = (const uint8_t*)buf_; - size_t written = 0; + size_t written = 0; pa_threaded_mainloop_lock(pa->mainloop); while (size) diff --git a/audio/drivers/roar.c b/audio/drivers/roar.c index 7821732b09..89d94db193 100644 --- a/audio/drivers/roar.c +++ b/audio/drivers/roar.c @@ -36,8 +36,8 @@ typedef struct static void *ra_init(const char *device, unsigned rate, unsigned latency) { int err; - roar_vs_t *vss; - roar_t *roar = (roar_t*)calloc(1, sizeof(roar_t)); + roar_vs_t *vss = NULL; + roar_t *roar = (roar_t*)calloc(1, sizeof(roar_t)); if (!roar) return NULL; @@ -61,7 +61,7 @@ static ssize_t ra_write(void *data, const void *buf, size_t size) { int err; size_t written = 0; - roar_t *roar = (roar_t*)data; + roar_t *roar = (roar_t*)data; if (size == 0) return 0; diff --git a/audio/drivers/rsound.c b/audio/drivers/rsound.c index 7c7584c4e8..0b35705974 100644 --- a/audio/drivers/rsound.c +++ b/audio/drivers/rsound.c @@ -71,12 +71,12 @@ static void *rs_init(const char *device, unsigned rate, unsigned latency) } rsd->cond_lock = slock_new(); - rsd->cond = scond_new(); + rsd->cond = scond_new(); - rsd->buffer = fifo_new(1024 * 4); + rsd->buffer = fifo_new(1024 * 4); - channels = 2; - format = RSD_S16_NE; + channels = 2; + format = RSD_S16_NE; rsd_set_param(rd, RSD_CHANNELS, &channels); rsd_set_param(rd, RSD_SAMPLERATE, &rate); @@ -201,12 +201,13 @@ static void rs_free(void *data) static size_t rs_write_avail(void *data) { + size_t val; rsd_t *rsd = (rsd_t*)data; if (rsd->has_error) return 0; rsd_callback_lock(rsd->rd); - size_t val = fifo_write_avail(rsd->buffer); + val = fifo_write_avail(rsd->buffer); rsd_callback_unlock(rsd->rd); return val; } diff --git a/audio/drivers/sdl_audio.c b/audio/drivers/sdl_audio.c index 181d60f105..9e4975dccf 100644 --- a/audio/drivers/sdl_audio.c +++ b/audio/drivers/sdl_audio.c @@ -44,8 +44,8 @@ typedef struct sdl_audio static void sdl_audio_cb(void *data, Uint8 *stream, int len) { - sdl_audio_t *sdl = (sdl_audio_t*)data; - size_t avail = fifo_read_avail(sdl->buffer); + sdl_audio_t *sdl = (sdl_audio_t*)data; + size_t avail = fifo_read_avail(sdl->buffer); size_t write_size = len > (int)avail ? avail : len; fifo_read(sdl->buffer, stream, write_size); @@ -71,9 +71,9 @@ static void *sdl_audio_init(const char *device, { int frames; size_t bufsize; - void *tmp; SDL_AudioSpec out; - SDL_AudioSpec spec = {0}; + SDL_AudioSpec spec = {0}; + void *tmp = NULL; settings_t *settings = config_get_ptr(); sdl_audio_t *sdl = NULL; @@ -97,10 +97,10 @@ static void *sdl_audio_init(const char *device, * SDL double buffers audio and we do as well. */ frames = find_num_frames(rate, latency / 4); - spec.freq = rate; - spec.format = AUDIO_S16SYS; + spec.freq = rate; + spec.format = AUDIO_S16SYS; spec.channels = 2; - spec.samples = frames; /* This is in audio frames, not samples ... :( */ + spec.samples = frames; /* This is in audio frames, not samples ... :( */ spec.callback = sdl_audio_cb; spec.userdata = sdl; @@ -114,16 +114,16 @@ static void *sdl_audio_init(const char *device, settings->audio.out_rate = out.freq; #ifdef HAVE_THREADS - sdl->lock = slock_new(); - sdl->cond = scond_new(); + sdl->lock = slock_new(); + sdl->cond = scond_new(); #endif RARCH_LOG("SDL audio: Requested %u ms latency, got %d ms\n", latency, (int)(out.samples * 4 * 1000 / settings->audio.out_rate)); /* Create a buffer twice as big as needed and prefill the buffer. */ - bufsize = out.samples * 4 * sizeof(int16_t); - tmp = calloc(1, bufsize); + bufsize = out.samples * 4 * sizeof(int16_t); + tmp = calloc(1, bufsize); sdl->buffer = fifo_new(bufsize); if (tmp)