Skip to content

Commit

Permalink
* Naming convention changes for variable names/function arguments
Browse files Browse the repository at this point in the history
* Try to fit lines within ANSI 80-char limit
  • Loading branch information
LibretroAdmin committed Jan 19, 2025
1 parent 274cd41 commit cde82f5
Show file tree
Hide file tree
Showing 55 changed files with 1,212 additions and 1,497 deletions.
59 changes: 29 additions & 30 deletions audio/drivers/alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,36 @@ static void *alsa_init(const char *device, unsigned rate, unsigned latency,
#define BYTES_TO_FRAMES(bytes, frame_bits) ((bytes) * 8 / frame_bits)
#define FRAMES_TO_BYTES(frames, frame_bits) ((frames) * frame_bits / 8)

static bool alsa_start(void *data, bool is_shutdown);
static ssize_t alsa_write(void *data, const void *buf_, size_t size_)
static bool alsa_start(void *data, bool is_shutdown)
{
alsa_t *alsa = (alsa_t*)data;
const uint8_t *buf = (const uint8_t*)buf_;
snd_pcm_sframes_t written = 0;
snd_pcm_sframes_t size = BYTES_TO_FRAMES(size_, alsa->stream_info.frame_bits);
size_t frames_size = alsa->stream_info.has_float ? sizeof(float) : sizeof(int16_t);
alsa_t *alsa = (alsa_t*)data;
if (!alsa->is_paused)
return true;

if ( alsa->stream_info.can_pause
&& alsa->is_paused)
{
int ret = snd_pcm_pause(alsa->pcm, 0);

if (ret < 0)
{
RARCH_ERR("[ALSA]: Failed to unpause: %s.\n",
snd_strerror(ret));
return false;
}

alsa->is_paused = false;
}
return true;
}

static ssize_t alsa_write(void *data, const void *buf_, size_t len)
{
ssize_t written = 0;
alsa_t *alsa = (alsa_t*)data;
const uint8_t *buf = (const uint8_t*)buf_;
snd_pcm_sframes_t size = BYTES_TO_FRAMES(len, alsa->stream_info.frame_bits);
size_t frames_size = alsa->stream_info.has_float ? sizeof(float) : sizeof(int16_t);

/* Workaround buggy menu code.
* If a write happens while we're paused, we might never progress. */
Expand Down Expand Up @@ -192,29 +214,6 @@ static void alsa_set_nonblock_state(void *data, bool state)
alsa->nonblock = state;
}

static bool alsa_start(void *data, bool is_shutdown)
{
alsa_t *alsa = (alsa_t*)data;
if (!alsa->is_paused)
return true;

if (alsa->stream_info.can_pause
&& alsa->is_paused)
{
int ret = snd_pcm_pause(alsa->pcm, 0);

if (ret < 0)
{
RARCH_ERR("[ALSA]: Failed to unpause: %s.\n",
snd_strerror(ret));
return false;
}

alsa->is_paused = false;
}
return true;
}

static void alsa_free(void *data)
{
alsa_t *alsa = (alsa_t*)data;
Expand Down
11 changes: 5 additions & 6 deletions audio/drivers/alsa_qsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,14 @@ static int check_pcm_status(void *data, int channel_type)
return ret;
}

static ssize_t alsa_qsa_write(void *data, const void *buf, size_t size)
static ssize_t alsa_qsa_write(void *data, const void *buf, size_t len)
{
alsa_qsa_t *alsa = (alsa_qsa_t*)data;
snd_pcm_sframes_t written = 0;
alsa_qsa_t *alsa = (alsa_qsa_t*)data;
ssize_t written = 0;

while (size)
{
size_t avail_write = MIN(alsa->buf_size - alsa->buffer_ptr, size);
size_t avail_write = MIN(alsa->buf_size - alsa->buffer_ptr, len);

if (avail_write)
{
Expand All @@ -235,7 +235,7 @@ static ssize_t alsa_qsa_write(void *data, const void *buf, size_t size)

alsa->buffer_ptr += avail_write;
buf = (void*)((uint8_t*)buf + avail_write);
size -= avail_write;
len -= avail_write;
written += avail_write;
}

Expand All @@ -260,7 +260,6 @@ static ssize_t alsa_qsa_write(void *data, const void *buf, size_t size)
return -1;
}
}

}

return written;
Expand Down
17 changes: 7 additions & 10 deletions audio/drivers/alsathread.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ static void *alsa_thread_init(const char *device,
return NULL;
}

static ssize_t alsa_thread_write(void *data, const void *buf, size_t size)
static ssize_t alsa_thread_write(void *data, const void *buf, size_t len)
{
ssize_t written = 0;
alsa_thread_t *alsa = (alsa_thread_t*)data;

if (alsa->info.thread_dead)
Expand All @@ -167,21 +168,17 @@ static ssize_t alsa_thread_write(void *data, const void *buf, size_t size)
if (alsa->nonblock)
{
size_t avail;
size_t write_amt;

slock_lock(alsa->info.fifo_lock);
avail = FIFO_WRITE_AVAIL(alsa->info.buffer);
write_amt = MIN(avail, size);
written = MIN(avail, len);

fifo_write(alsa->info.buffer, buf, write_amt);
fifo_write(alsa->info.buffer, buf, written);
slock_unlock(alsa->info.fifo_lock);

return write_amt;
}
else
{
size_t written = 0;
while (written < size && !alsa->info.thread_dead)
while (written < len && !alsa->info.thread_dead)
{
size_t avail;
slock_lock(alsa->info.fifo_lock);
Expand All @@ -197,15 +194,15 @@ static ssize_t alsa_thread_write(void *data, const void *buf, size_t size)
}
else
{
size_t write_amt = MIN(size - written, avail);
size_t write_amt = MIN(len - written, avail);
fifo_write(alsa->info.buffer,
(const char*)buf + written, write_amt);
slock_unlock(alsa->info.fifo_lock);
written += write_amt;
}
}
return written;
}
return written;
}

static bool alsa_thread_alive(void *data)
Expand Down
10 changes: 5 additions & 5 deletions audio/drivers/audioio.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ static void *audioio_init(const char *device, unsigned rate, unsigned latency,
return NULL;
}

static ssize_t audioio_write(void *data, const void *buf, size_t size)
static ssize_t audioio_write(void *data, const void *buf, size_t len)
{
ssize_t ret;
ssize_t written;
int *fd = (int*)data;

if (size == 0)
if (len == 0)
return 0;

if ((ret = write(*fd, buf, size)) < 0)
if ((written = write(*fd, buf, len)) < 0)
{
if (errno == EAGAIN && (fcntl(*fd, F_GETFL) & O_NONBLOCK))
return 0;

return -1;
}

return ret;
return written;
}

static bool audioio_stop(void *data)
Expand Down
23 changes: 8 additions & 15 deletions audio/drivers/coreaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,26 +312,26 @@ static void *coreaudio_init(const char *device,
return NULL;
}

static ssize_t coreaudio_write(void *data, const void *buf_, size_t size)
static ssize_t coreaudio_write(void *data, const void *buf_, size_t len)
{
coreaudio_t *dev = (coreaudio_t*)data;
const uint8_t *buf = (const uint8_t*)buf_;
size_t written = 0;

while (!dev->is_paused && size > 0)
while (!dev->is_paused && len > 0)
{
size_t write_avail;

slock_lock(dev->lock);

write_avail = FIFO_WRITE_AVAIL(dev->buffer);
if (write_avail > size)
write_avail = size;
if (write_avail > len)
write_avail = len;

fifo_write(dev->buffer, buf, write_avail);
buf += write_avail;
written += write_avail;
size -= write_avail;
len -= write_avail;

if (dev->nonblock)
{
Expand Down Expand Up @@ -409,16 +409,9 @@ static size_t coreaudio_buffer_size(void *data)
return dev->buffer_size;
}

static void *coreaudio_device_list_new(void *data)
{
/* TODO/FIXME */
return NULL;
}

static void coreaudio_device_list_free(void *data, void *array_list_data)
{
/* TODO/FIXME */
}
/* TODO/FIXME - implement */
static void *coreaudio_device_list_new(void *data) { return NULL; }
static void coreaudio_device_list_free(void *data, void *array_list_data) { }

audio_driver_t audio_coreaudio = {
coreaudio_init,
Expand Down
5 changes: 2 additions & 3 deletions audio/drivers/coreaudio3.m
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,11 @@ static void coreaudio3_free(void *data)
return (__bridge_retained void *)dev;
}

static ssize_t coreaudio3_write(void *data,
const void *buf_, size_t size)
static ssize_t coreaudio3_write(void *data, const void *buf_, size_t len)
{
CoreAudio3 *dev = (__bridge CoreAudio3 *)data;
return [dev writeFloat:(const float *)
buf_ samples:size/sizeof(float)] * sizeof(float);
buf_ samples:len / sizeof(float)] * sizeof(float);
}

static void coreaudio3_set_nonblock_state(void *data, bool state)
Expand Down
26 changes: 11 additions & 15 deletions audio/drivers/ctr_csnd_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,19 @@ static void ctr_csnd_audio_free(void *data)
free(ctr);
}

static ssize_t ctr_csnd_audio_write(void *data, const void *buf, size_t size)
static ssize_t ctr_csnd_audio_write(void *data, const void *buf, size_t len)
{
int i;
uint32_t samples_played = 0;
uint64_t current_tick = 0;
const uint16_t *src = buf;
ctr_csnd_audio_t *ctr = (ctr_csnd_audio_t*)data;
uint32_t samples_played = 0;
uint64_t current_tick = 0;
const uint16_t *src = buf;
ctr_csnd_audio_t *ctr = (ctr_csnd_audio_t*)data;

ctr_csnd_audio_update_playpos(ctr);

if ((((ctr->playpos - ctr->pos) & CTR_CSND_AUDIO_COUNT_MASK) < (CTR_CSND_AUDIO_COUNT >> 2)) ||
(((ctr->pos - ctr->playpos ) & CTR_CSND_AUDIO_COUNT_MASK) < (CTR_CSND_AUDIO_COUNT >> 4)) ||
(((ctr->playpos - ctr->pos) & CTR_CSND_AUDIO_COUNT_MASK) < (size >> 2)))
if ( (((ctr->playpos - ctr->pos) & CTR_CSND_AUDIO_COUNT_MASK) < (CTR_CSND_AUDIO_COUNT >> 2))
|| (((ctr->pos - ctr->playpos) & CTR_CSND_AUDIO_COUNT_MASK) < (CTR_CSND_AUDIO_COUNT >> 4))
|| (((ctr->playpos - ctr->pos) & CTR_CSND_AUDIO_COUNT_MASK) < (len >> 2)))
{
if (ctr->nonblock)
ctr->pos = (ctr->playpos + (CTR_CSND_AUDIO_COUNT >> 1)) & CTR_CSND_AUDIO_COUNT_MASK;
Expand All @@ -189,7 +189,7 @@ static ssize_t ctr_csnd_audio_write(void *data, const void *buf, size_t size)
}
}

for (i = 0; i < (size >> 1); i += 2)
for (i = 0; i < (len >> 1); i += 2)
{
ctr->l[ctr->pos] = src[i];
ctr->r[ctr->pos] = src[i + 1];
Expand All @@ -200,7 +200,7 @@ static ssize_t ctr_csnd_audio_write(void *data, const void *buf, size_t size)
GSPGPU_FlushDataCache(ctr->l, CTR_CSND_AUDIO_SIZE);
GSPGPU_FlushDataCache(ctr->r, CTR_CSND_AUDIO_SIZE);

return size;
return len;
}

static bool ctr_csnd_audio_stop(void *data)
Expand Down Expand Up @@ -264,11 +264,7 @@ static void ctr_csnd_audio_set_nonblock_state(void *data, bool state)
ctr->nonblock = state;
}

static bool ctr_csnd_audio_use_float(void *data)
{
(void)data;
return false;
}
static bool ctr_csnd_audio_use_float(void *data) { return false; }

static size_t ctr_csnd_audio_write_avail(void *data)
{
Expand Down
34 changes: 15 additions & 19 deletions audio/drivers/ctr_dsp_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ static void ctr_dsp_audio_free(void *data)
ndspExit();
}

static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t size)
static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t len)
{
u32 pos;
ctr_dsp_audio_t * ctr = (ctr_dsp_audio_t*)data;
uint32_t sample_pos = ndspChnGetSamplePos(ctr->channel);
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)) ||
(((sample_pos - ctr->pos) & CTR_DSP_AUDIO_COUNT_MASK) < (size >> 2)))
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))
|| (((sample_pos - ctr->pos) & CTR_DSP_AUDIO_COUNT_MASK) < (len >> 2)))
{
if (ctr->nonblock)
ctr->pos = (sample_pos + (CTR_DSP_AUDIO_COUNT >> 1)) & CTR_DSP_AUDIO_COUNT_MASK;
Expand All @@ -118,33 +118,33 @@ static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t size)
}

sample_pos = ndspChnGetSamplePos(ctr->channel);
}while ( ((sample_pos - (ctr->pos + (size >>2))) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)
}while ( ((sample_pos - (ctr->pos + (len >>2))) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)
|| (((ctr->pos - (CTR_DSP_AUDIO_COUNT >> 4) - sample_pos) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)));
}
}

pos = ctr->pos << 2;

if ((pos + size) > CTR_DSP_AUDIO_SIZE)
if ((pos + len) > CTR_DSP_AUDIO_SIZE)
{
memcpy(ctr->dsp_buf.data_pcm8 + pos, buf,
(CTR_DSP_AUDIO_SIZE - pos));
DSP_FlushDataCache(ctr->dsp_buf.data_pcm8 + pos, (CTR_DSP_AUDIO_SIZE - pos));

memcpy(ctr->dsp_buf.data_pcm8, (uint8_t*) buf + (CTR_DSP_AUDIO_SIZE - pos),
(pos + size - CTR_DSP_AUDIO_SIZE));
DSP_FlushDataCache(ctr->dsp_buf.data_pcm8, (pos + size - CTR_DSP_AUDIO_SIZE));
(pos + len - CTR_DSP_AUDIO_SIZE));
DSP_FlushDataCache(ctr->dsp_buf.data_pcm8, (pos + len - CTR_DSP_AUDIO_SIZE));
}
else
{
memcpy(ctr->dsp_buf.data_pcm8 + pos, buf, size);
DSP_FlushDataCache(ctr->dsp_buf.data_pcm8 + pos, size);
memcpy(ctr->dsp_buf.data_pcm8 + pos, buf, len);
DSP_FlushDataCache(ctr->dsp_buf.data_pcm8 + pos, len);
}

ctr->pos += size >> 2;
ctr->pos += len >> 2;
ctr->pos &= CTR_DSP_AUDIO_COUNT_MASK;

return size;
return len;
}

static bool ctr_dsp_audio_stop(void *data)
Expand Down Expand Up @@ -185,11 +185,7 @@ static void ctr_dsp_audio_set_nonblock_state(void *data, bool state)
ctr->nonblock = state;
}

static bool ctr_dsp_audio_use_float(void *data)
{
(void)data;
return false;
}
static bool ctr_dsp_audio_use_float(void *data) { return false; }

static size_t ctr_dsp_audio_write_avail(void *data)
{
Expand Down
Loading

0 comments on commit cde82f5

Please sign in to comment.