mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-02-22 20:52:39 +00:00
(Audio) Indenting/style nits
This commit is contained in:
parent
511f0ab075
commit
4093aeeccf
37
audio/alsa.c
37
audio/alsa.c
@ -71,23 +71,28 @@ static void *alsa_init(const char *device, unsigned rate, unsigned latency)
|
||||
|
||||
snd_pcm_uframes_t buffer_size;
|
||||
|
||||
TRY_ALSA(snd_pcm_open(&alsa->pcm, alsa_dev, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK));
|
||||
TRY_ALSA(snd_pcm_open(
|
||||
&alsa->pcm, alsa_dev, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK));
|
||||
TRY_ALSA(snd_pcm_hw_params_malloc(¶ms));
|
||||
alsa->has_float = find_float_format(alsa->pcm, params);
|
||||
format = alsa->has_float ? SND_PCM_FORMAT_FLOAT : SND_PCM_FORMAT_S16;
|
||||
|
||||
TRY_ALSA(snd_pcm_hw_params_any(alsa->pcm, params));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_access(alsa->pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_access(
|
||||
alsa->pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_format(alsa->pcm, params, format));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_channels(alsa->pcm, params, channels));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_rate(alsa->pcm, params, rate, 0));
|
||||
|
||||
TRY_ALSA(snd_pcm_hw_params_set_buffer_time_near(alsa->pcm, params, &latency_usec, NULL));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_periods_near(alsa->pcm, params, &periods, NULL));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_buffer_time_near(
|
||||
alsa->pcm, params, &latency_usec, NULL));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_periods_near(
|
||||
alsa->pcm, params, &periods, NULL));
|
||||
|
||||
TRY_ALSA(snd_pcm_hw_params(alsa->pcm, params));
|
||||
|
||||
// Shouldn't have to bother with this, but some drivers are apparently broken.
|
||||
/* Shouldn't have to bother with this,
|
||||
* but some drivers are apparently broken. */
|
||||
if (snd_pcm_hw_params_get_period_size(params, &buffer_size, NULL))
|
||||
snd_pcm_hw_params_get_period_size_min(params, &buffer_size, NULL);
|
||||
RARCH_LOG("ALSA: Period size: %d frames\n", (int)buffer_size);
|
||||
@ -100,7 +105,8 @@ static void *alsa_init(const char *device, unsigned rate, unsigned latency)
|
||||
|
||||
TRY_ALSA(snd_pcm_sw_params_malloc(&sw_params));
|
||||
TRY_ALSA(snd_pcm_sw_params_current(alsa->pcm, sw_params));
|
||||
TRY_ALSA(snd_pcm_sw_params_set_start_threshold(alsa->pcm, sw_params, buffer_size / 2));
|
||||
TRY_ALSA(snd_pcm_sw_params_set_start_threshold(
|
||||
alsa->pcm, sw_params, buffer_size / 2));
|
||||
TRY_ALSA(snd_pcm_sw_params(alsa->pcm, sw_params));
|
||||
|
||||
snd_pcm_hw_params_free(params);
|
||||
@ -165,8 +171,9 @@ static ssize_t alsa_write(void *data, const void *buf_, size_t size_)
|
||||
|
||||
break;
|
||||
}
|
||||
else if (frames == -EAGAIN && !alsa->nonblock) // Definitely not supposed to happen.
|
||||
else if (frames == -EAGAIN && !alsa->nonblock)
|
||||
{
|
||||
/* Definitely not supposed to happen. */
|
||||
RARCH_WARN("[ALSA]: poll() was signaled, but EAGAIN returned from write.\n"
|
||||
"Your ALSA driver might be subtly broken.\n");
|
||||
|
||||
@ -177,16 +184,18 @@ static ssize_t alsa_write(void *data, const void *buf_, size_t size_)
|
||||
}
|
||||
return written;
|
||||
}
|
||||
else if (frames == -EAGAIN) // Expected if we're running nonblock.
|
||||
else if (frames == -EAGAIN) /* Expected if we're running nonblock. */
|
||||
return written;
|
||||
else if (frames < 0)
|
||||
{
|
||||
RARCH_ERR("[ALSA]: Unknown error occured (%s).\n", snd_strerror(frames));
|
||||
RARCH_ERR("[ALSA]: Unknown error occured (%s).\n",
|
||||
snd_strerror(frames));
|
||||
return -1;
|
||||
}
|
||||
|
||||
written += frames;
|
||||
buf += (frames << 1) * (alsa->has_float ? sizeof(float) : sizeof(int16_t));
|
||||
buf += (frames << 1) *
|
||||
(alsa->has_float ? sizeof(float) : sizeof(int16_t));
|
||||
size -= frames;
|
||||
}
|
||||
|
||||
@ -224,7 +233,8 @@ static bool alsa_start(void *data)
|
||||
int ret = snd_pcm_pause(alsa->pcm, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
RARCH_ERR("[ALSA]: Failed to unpause: %s.\n", snd_strerror(ret));
|
||||
RARCH_ERR("[ALSA]: Failed to unpause: %s.\n",
|
||||
snd_strerror(ret));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@ -258,7 +268,10 @@ static size_t alsa_write_avail(void *data)
|
||||
snd_pcm_sframes_t avail = snd_pcm_avail(alsa->pcm);
|
||||
if (avail < 0)
|
||||
{
|
||||
//RARCH_WARN("[ALSA]: snd_pcm_avail() failed: %s\n", snd_strerror(avail));
|
||||
#if 0
|
||||
RARCH_WARN("[ALSA]: snd_pcm_avail() failed: %s\n",
|
||||
snd_strerror(avail));
|
||||
#endif
|
||||
return alsa->buffer_size;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,8 @@ typedef struct alsa
|
||||
|
||||
typedef long snd_pcm_sframes_t;
|
||||
|
||||
static void *alsa_qsa_init(const char *device, unsigned rate, unsigned latency)
|
||||
static void *alsa_qsa_init(const char *device,
|
||||
unsigned rate, unsigned latency)
|
||||
{
|
||||
int err, card, dev, i;
|
||||
snd_pcm_channel_params_t params = {0};
|
||||
@ -64,13 +65,15 @@ static void *alsa_qsa_init(const char *device, unsigned rate, unsigned latency)
|
||||
if ((err = snd_pcm_open_preferred(&alsa->pcm, &card, &dev,
|
||||
SND_PCM_OPEN_PLAYBACK)) < 0)
|
||||
{
|
||||
RARCH_ERR("[ALSA QSA]: Audio open error: %s\n", snd_strerror(err));
|
||||
RARCH_ERR("[ALSA QSA]: Audio open error: %s\n",
|
||||
snd_strerror(err));
|
||||
goto error;
|
||||
}
|
||||
|
||||
if((err = snd_pcm_nonblock_mode(alsa->pcm, 1)) < 0)
|
||||
{
|
||||
RARCH_ERR("[ALSA QSA]: Can't set blocking mode: %s\n", snd_strerror(err));
|
||||
RARCH_ERR("[ALSA QSA]: Can't set blocking mode: %s\n",
|
||||
snd_strerror(err));
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -106,7 +109,8 @@ static void *alsa_qsa_init(const char *device, unsigned rate, unsigned latency)
|
||||
|
||||
if ((err = snd_pcm_channel_params(alsa->pcm, ¶ms)) < 0)
|
||||
{
|
||||
RARCH_ERR("[ALSA QSA]: Channel Parameter Error: %s\n", snd_strerror(err));
|
||||
RARCH_ERR("[ALSA QSA]: Channel Parameter Error: %s\n",
|
||||
snd_strerror(err));
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -114,7 +118,8 @@ static void *alsa_qsa_init(const char *device, unsigned rate, unsigned latency)
|
||||
|
||||
if ((err = snd_pcm_channel_setup(alsa->pcm, &setup)) < 0)
|
||||
{
|
||||
RARCH_ERR("[ALSA QSA]: Channel Parameter Read Back Error: %s\n", snd_strerror(err));
|
||||
RARCH_ERR("[ALSA QSA]: Channel Parameter Read Back Error: %s\n",
|
||||
snd_strerror(err));
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -128,9 +133,11 @@ static void *alsa_qsa_init(const char *device, unsigned rate, unsigned latency)
|
||||
alsa->buf_count = (latency * 4 * rate + 500) / 1000;
|
||||
alsa->buf_count = (alsa->buf_count + alsa->buf_size / 2) / alsa->buf_size;
|
||||
|
||||
if ((err = snd_pcm_channel_prepare(alsa->pcm, SND_PCM_CHANNEL_PLAYBACK)) < 0)
|
||||
if ((err = snd_pcm_channel_prepare(alsa->pcm,
|
||||
SND_PCM_CHANNEL_PLAYBACK)) < 0)
|
||||
{
|
||||
RARCH_ERR("[ALSA QSA]: Channel Prepare Error: %s\n", snd_strerror(err));
|
||||
RARCH_ERR("[ALSA QSA]: Channel Prepare Error: %s\n",
|
||||
snd_strerror(err));
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -147,7 +154,8 @@ static void *alsa_qsa_init(const char *device, unsigned rate, unsigned latency)
|
||||
|
||||
alsa->has_float = false;
|
||||
alsa->can_pause = true;
|
||||
RARCH_LOG("[ALSA QSA]: Can pause: %s.\n", alsa->can_pause ? "yes" : "no");
|
||||
RARCH_LOG("[ALSA QSA]: Can pause: %s.\n",
|
||||
alsa->can_pause ? "yes" : "no");
|
||||
|
||||
return alsa;
|
||||
|
||||
@ -176,7 +184,8 @@ static int check_pcm_status(void *data, int channel_type)
|
||||
RARCH_LOG("check_pcm_status: SNDP_CM_STATUS_UNDERRUN.\n");
|
||||
if ((ret = snd_pcm_channel_prepare(alsa->pcm, channel_type)) < 0)
|
||||
{
|
||||
RARCH_ERR("Invalid state detected for underrun on snd_pcm_channel_prepare: %s\n", snd_strerror(ret));
|
||||
RARCH_ERR("Invalid state detected for underrun on snd_pcm_channel_prepare: %s\n",
|
||||
snd_strerror(ret));
|
||||
ret = -EPROTO;
|
||||
}
|
||||
}
|
||||
@ -185,7 +194,8 @@ static int check_pcm_status(void *data, int channel_type)
|
||||
RARCH_LOG("check_pcm_status: SNDP_CM_STATUS_OVERRUN.\n");
|
||||
if ((ret = snd_pcm_channel_prepare(alsa->pcm, channel_type)) < 0)
|
||||
{
|
||||
RARCH_ERR("Invalid state detected for overrun on snd_pcm_channel_prepare: %s\n", snd_strerror(ret));
|
||||
RARCH_ERR("Invalid state detected for overrun on snd_pcm_channel_prepare: %s\n",
|
||||
snd_strerror(ret));
|
||||
ret = -EPROTO;
|
||||
}
|
||||
}
|
||||
@ -194,7 +204,8 @@ static int check_pcm_status(void *data, int channel_type)
|
||||
RARCH_LOG("check_pcm_status: SNDP_CM_STATUS_CHANGE.\n");
|
||||
if ((ret = snd_pcm_channel_prepare(alsa->pcm, channel_type)) < 0)
|
||||
{
|
||||
RARCH_ERR("Invalid state detected for change on snd_pcm_channel_prepare: %s\n", snd_strerror(ret));
|
||||
RARCH_ERR("Invalid state detected for change on snd_pcm_channel_prepare: %s\n",
|
||||
snd_strerror(ret));
|
||||
ret = -EPROTO;
|
||||
}
|
||||
}
|
||||
@ -216,13 +227,13 @@ static ssize_t alsa_qsa_write(void *data, const void *buf, size_t size)
|
||||
snd_pcm_channel_status_t cstatus = {0};
|
||||
snd_pcm_sframes_t written = 0;
|
||||
|
||||
|
||||
while (size)
|
||||
{
|
||||
size_t avail_write = min(alsa->buf_size - alsa->buffer_ptr, size);
|
||||
if (avail_write)
|
||||
{
|
||||
memcpy(alsa->buffer[alsa->buffer_index] + alsa->buffer_ptr, buf, avail_write);
|
||||
memcpy(alsa->buffer[alsa->buffer_index] +
|
||||
alsa->buffer_ptr, buf, avail_write);
|
||||
alsa->buffer_ptr += avail_write;
|
||||
buf += avail_write;
|
||||
size -= avail_write;
|
||||
@ -231,7 +242,8 @@ static ssize_t alsa_qsa_write(void *data, const void *buf, size_t size)
|
||||
|
||||
if (alsa->buffer_ptr >= alsa->buf_size)
|
||||
{
|
||||
snd_pcm_sframes_t frames = snd_pcm_write(alsa->pcm, alsa->buffer[alsa->buffer_index], alsa->buf_size);
|
||||
snd_pcm_sframes_t frames = snd_pcm_write(alsa->pcm,
|
||||
alsa->buffer[alsa->buffer_index], alsa->buf_size);
|
||||
|
||||
alsa->buffer_index = (alsa->buffer_index + 1) % alsa->buf_count;
|
||||
alsa->buffer_ptr = 0;
|
||||
@ -297,7 +309,8 @@ static bool alsa_qsa_start(void *data)
|
||||
int ret = snd_pcm_playback_resume(alsa->pcm);
|
||||
if (ret < 0)
|
||||
{
|
||||
RARCH_ERR("[ALSA QSA]: Failed to unpause: %s.\n", snd_strerror(ret));
|
||||
RARCH_ERR("[ALSA QSA]: Failed to unpause: %s.\n",
|
||||
snd_strerror(ret));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
@ -336,7 +349,9 @@ static void alsa_qsa_free(void *data)
|
||||
static size_t alsa_qsa_write_avail(void *data)
|
||||
{
|
||||
alsa_t *alsa = (alsa_t*)data;
|
||||
size_t avail = (alsa->buf_count - (int)alsa->buffered_blocks - 1) * alsa->buf_size + (alsa->buf_size - (int)alsa->buffer_ptr);
|
||||
size_t avail = (alsa->buf_count -
|
||||
(int)alsa->buffered_blocks - 1) * alsa->buf_size +
|
||||
(alsa->buf_size - (int)alsa->buffer_ptr);
|
||||
return avail;
|
||||
}
|
||||
|
||||
|
@ -64,12 +64,14 @@ static void alsa_worker_thread(void *data)
|
||||
scond_signal(alsa->cond);
|
||||
slock_unlock(alsa->fifo_lock);
|
||||
|
||||
// If underrun, fill rest with silence.
|
||||
/* If underrun, fill rest with silence. */
|
||||
memset(buf + fifo_size, 0, alsa->period_size - fifo_size);
|
||||
|
||||
snd_pcm_sframes_t frames = snd_pcm_writei(alsa->pcm, buf, alsa->period_frames);
|
||||
snd_pcm_sframes_t frames = snd_pcm_writei(
|
||||
alsa->pcm, buf, alsa->period_frames);
|
||||
|
||||
if (frames == -EPIPE || frames == -EINTR || frames == -ESTRPIPE)
|
||||
if (frames == -EPIPE || frames == -EINTR ||
|
||||
frames == -ESTRPIPE)
|
||||
{
|
||||
if (snd_pcm_recover(alsa->pcm, frames, 1) < 0)
|
||||
{
|
||||
@ -82,7 +84,8 @@ static void alsa_worker_thread(void *data)
|
||||
}
|
||||
else if (frames < 0)
|
||||
{
|
||||
RARCH_ERR("[ALSA]: Unknown error occured (%s).\n", snd_strerror(frames));
|
||||
RARCH_ERR("[ALSA]: Unknown error occured (%s).\n",
|
||||
snd_strerror(frames));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -101,7 +104,8 @@ static bool alsa_thread_use_float(void *data)
|
||||
return alsa->has_float;
|
||||
}
|
||||
|
||||
static bool alsathread_find_float_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
||||
static bool alsathread_find_float_format(snd_pcm_t *pcm,
|
||||
snd_pcm_hw_params_t *params)
|
||||
{
|
||||
if (snd_pcm_hw_params_test_format(pcm, params, SND_PCM_FORMAT_FLOAT) == 0)
|
||||
{
|
||||
@ -140,7 +144,8 @@ static void alsa_thread_free(void *data)
|
||||
}
|
||||
}
|
||||
|
||||
static void *alsa_thread_init(const char *device, unsigned rate, unsigned latency)
|
||||
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));
|
||||
if (!alsa)
|
||||
@ -167,19 +172,24 @@ static void *alsa_thread_init(const char *device, unsigned rate, unsigned latenc
|
||||
format = alsa->has_float ? SND_PCM_FORMAT_FLOAT : SND_PCM_FORMAT_S16;
|
||||
|
||||
TRY_ALSA(snd_pcm_hw_params_any(alsa->pcm, params));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_access(alsa->pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_access(
|
||||
alsa->pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_format(alsa->pcm, params, format));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_channels(alsa->pcm, params, channels));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_rate(alsa->pcm, params, rate, 0));
|
||||
|
||||
TRY_ALSA(snd_pcm_hw_params_set_buffer_time_near(alsa->pcm, params, &latency_usec, NULL));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_periods_near(alsa->pcm, params, &periods, NULL));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_buffer_time_near(
|
||||
alsa->pcm, params, &latency_usec, NULL));
|
||||
TRY_ALSA(snd_pcm_hw_params_set_periods_near(
|
||||
alsa->pcm, params, &periods, NULL));
|
||||
|
||||
TRY_ALSA(snd_pcm_hw_params(alsa->pcm, params));
|
||||
|
||||
// Shouldn't have to bother with this, but some drivers are apparently broken.
|
||||
/* Shouldn't have to bother with this,
|
||||
* but some drivers are apparently broken. */
|
||||
if (snd_pcm_hw_params_get_period_size(params, &alsa->period_frames, NULL))
|
||||
snd_pcm_hw_params_get_period_size_min(params, &alsa->period_frames, NULL);
|
||||
snd_pcm_hw_params_get_period_size_min(
|
||||
params, &alsa->period_frames, NULL);
|
||||
RARCH_LOG("ALSA: Period size: %d frames\n", (int)alsa->period_frames);
|
||||
if (snd_pcm_hw_params_get_buffer_size(params, &buffer_size))
|
||||
snd_pcm_hw_params_get_buffer_size_max(params, &buffer_size);
|
||||
@ -190,7 +200,8 @@ static void *alsa_thread_init(const char *device, unsigned rate, unsigned latenc
|
||||
|
||||
TRY_ALSA(snd_pcm_sw_params_malloc(&sw_params));
|
||||
TRY_ALSA(snd_pcm_sw_params_current(alsa->pcm, sw_params));
|
||||
TRY_ALSA(snd_pcm_sw_params_set_start_threshold(alsa->pcm, sw_params, buffer_size / 2));
|
||||
TRY_ALSA(snd_pcm_sw_params_set_start_threshold(
|
||||
alsa->pcm, sw_params, buffer_size / 2));
|
||||
TRY_ALSA(snd_pcm_sw_params(alsa->pcm, sw_params));
|
||||
|
||||
snd_pcm_hw_params_free(params);
|
||||
|
@ -76,7 +76,8 @@ static void coreaudio_free(void *data)
|
||||
free(dev);
|
||||
}
|
||||
|
||||
static OSStatus audio_write_cb(void *userdata, AudioUnitRenderActionFlags *action_flags,
|
||||
static OSStatus audio_write_cb(void *userdata,
|
||||
AudioUnitRenderActionFlags *action_flags,
|
||||
const AudioTimeStamp *time_stamp, UInt32 bus_number,
|
||||
UInt32 number_frames, AudioBufferList *io_data)
|
||||
{
|
||||
@ -97,9 +98,14 @@ static OSStatus audio_write_cb(void *userdata, AudioUnitRenderActionFlags *actio
|
||||
if (fifo_read_avail(dev->buffer) < write_avail)
|
||||
{
|
||||
*action_flags = kAudioUnitRenderAction_OutputIsSilence;
|
||||
memset(outbuf, 0, write_avail); // Seems to be needed.
|
||||
|
||||
/* Seems to be needed. */
|
||||
memset(outbuf, 0, write_avail);
|
||||
|
||||
pthread_mutex_unlock(&dev->lock);
|
||||
pthread_cond_signal(&dev->cond); // Technically possible to deadlock without.
|
||||
|
||||
/* Technically possible to deadlock without. */
|
||||
pthread_cond_signal(&dev->cond);
|
||||
return noErr;
|
||||
}
|
||||
|
||||
@ -121,13 +127,15 @@ static void choose_output_device(coreaudio_t *dev, const char* device)
|
||||
|
||||
UInt32 size = 0;
|
||||
|
||||
if (AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propaddr, 0, 0, &size) != noErr)
|
||||
if (AudioObjectGetPropertyDataSize(kAudioObjectSystemObject,
|
||||
&propaddr, 0, 0, &size) != noErr)
|
||||
return;
|
||||
|
||||
UInt32 deviceCount = size / sizeof(AudioDeviceID);
|
||||
AudioDeviceID *devices = malloc(size);
|
||||
|
||||
if (!devices || AudioObjectGetPropertyData(kAudioObjectSystemObject, &propaddr, 0, 0, &size, devices) != noErr)
|
||||
if (!devices || AudioObjectGetPropertyData(kAudioObjectSystemObject,
|
||||
&propaddr, 0, 0, &size, devices) != noErr)
|
||||
goto done;
|
||||
|
||||
propaddr.mScope = kAudioDevicePropertyScopeOutput;
|
||||
@ -139,9 +147,12 @@ static void choose_output_device(coreaudio_t *dev, const char* device)
|
||||
char device_name[1024];
|
||||
device_name[0] = 0;
|
||||
|
||||
if (AudioObjectGetPropertyData(devices[i], &propaddr, 0, 0, &size, device_name) == noErr && strcmp(device_name, device) == 0)
|
||||
if (AudioObjectGetPropertyData(devices[i],
|
||||
&propaddr, 0, 0, &size, device_name) == noErr
|
||||
&& !strcmp(device_name, device))
|
||||
{
|
||||
AudioUnitSetProperty(dev->dev, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &devices[i], sizeof(AudioDeviceID));
|
||||
AudioUnitSetProperty(dev->dev, kAudioOutputUnitProperty_CurrentDevice,
|
||||
kAudioUnitScope_Global, 0, &devices[i], sizeof(AudioDeviceID));
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
@ -159,7 +170,8 @@ static void coreaudio_interrupt_listener(void *data, UInt32 interrupt_state)
|
||||
}
|
||||
#endif
|
||||
|
||||
static void *coreaudio_init(const char *device, unsigned rate, unsigned latency)
|
||||
static void *coreaudio_init(const char *device,
|
||||
unsigned rate, unsigned latency)
|
||||
{
|
||||
(void)device;
|
||||
|
||||
@ -227,15 +239,18 @@ static void *coreaudio_init(const char *device, unsigned rate, unsigned latency)
|
||||
stream_desc.mBytesPerFrame = 2 * sizeof(float);
|
||||
stream_desc.mFramesPerPacket = 1;
|
||||
stream_desc.mFormatID = kAudioFormatLinearPCM;
|
||||
stream_desc.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked | (is_little_endian() ? 0 : kAudioFormatFlagIsBigEndian);
|
||||
stream_desc.mFormatFlags = kAudioFormatFlagIsFloat |
|
||||
kAudioFormatFlagIsPacked | (is_little_endian() ?
|
||||
0 : kAudioFormatFlagIsBigEndian);
|
||||
|
||||
if (AudioUnitSetProperty(dev->dev, kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Input, 0, &stream_desc, sizeof(stream_desc)) != noErr)
|
||||
goto error;
|
||||
|
||||
// Check returned audio format
|
||||
/* Check returned audio format. */
|
||||
UInt32 i_size = sizeof(real_desc);;
|
||||
if (AudioUnitGetProperty(dev->dev, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &real_desc, &i_size) != noErr)
|
||||
if (AudioUnitGetProperty(dev->dev, kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Input, 0, &real_desc, &i_size) != noErr)
|
||||
goto error;
|
||||
|
||||
if (real_desc.mChannelsPerFrame != stream_desc.mChannelsPerFrame)
|
||||
@ -247,11 +262,12 @@ static void *coreaudio_init(const char *device, unsigned rate, unsigned latency)
|
||||
if (real_desc.mFormatID != stream_desc.mFormatID)
|
||||
goto error;
|
||||
|
||||
RARCH_LOG("[CoreAudio]: Using output sample rate of %.1f Hz\n", (float)real_desc.mSampleRate);
|
||||
RARCH_LOG("[CoreAudio]: Using output sample rate of %.1f Hz\n",
|
||||
(float)real_desc.mSampleRate);
|
||||
g_settings.audio.out_rate = real_desc.mSampleRate;
|
||||
|
||||
|
||||
// Set channel layout (fails on iOS)
|
||||
/* Set channel layout (fails on iOS). */
|
||||
#ifndef IOS
|
||||
AudioChannelLayout layout = {0};
|
||||
|
||||
@ -261,7 +277,7 @@ static void *coreaudio_init(const char *device, unsigned rate, unsigned latency)
|
||||
goto error;
|
||||
#endif
|
||||
|
||||
// Set callbacks and finish up
|
||||
/* Set callbacks and finish up. */
|
||||
AURenderCallbackStruct cb = {0};
|
||||
cb.inputProc = audio_write_cb;
|
||||
cb.inputProcRefCon = dev;
|
||||
@ -283,7 +299,8 @@ static void *coreaudio_init(const char *device, unsigned rate, unsigned latency)
|
||||
if (!dev->buffer)
|
||||
goto error;
|
||||
|
||||
RARCH_LOG("[CoreAudio]: Using buffer size of %u bytes: (latency = %u ms)\n", (unsigned)fifo_size, latency);
|
||||
RARCH_LOG("[CoreAudio]: Using buffer size of %u bytes: (latency = %u ms)\n",
|
||||
(unsigned)fifo_size, latency);
|
||||
|
||||
if (AudioOutputUnitStart(dev->dev) != noErr)
|
||||
goto error;
|
||||
@ -333,7 +350,8 @@ static ssize_t coreaudio_write(void *data, const void *buf_, size_t size)
|
||||
}
|
||||
|
||||
#ifdef IOS
|
||||
if (write_avail == 0 && pthread_cond_timedwait(&dev->cond, &dev->lock, &timeout) == ETIMEDOUT)
|
||||
if (write_avail == 0 && pthread_cond_timedwait(
|
||||
&dev->cond, &dev->lock, &timeout) == ETIMEDOUT)
|
||||
g_interrupted = true;
|
||||
#else
|
||||
if (write_avail == 0)
|
||||
|
@ -60,7 +60,8 @@ static volatile gx_audio_t *gx_audio_data;
|
||||
static void dma_callback(void)
|
||||
{
|
||||
gx_audio_t *wa = (gx_audio_t*)gx_audio_data;
|
||||
// erase last chunk to avoid repeating audio
|
||||
|
||||
/* Erase last chunk to avoid repeating audio. */
|
||||
memset(wa->data[wa->dma_busy], 0, CHUNK_SIZE);
|
||||
|
||||
wa->dma_busy = wa->dma_next;
|
||||
@ -72,7 +73,8 @@ static void dma_callback(void)
|
||||
OSSignalCond(wa->cond);
|
||||
}
|
||||
|
||||
static void *gx_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||
static void *gx_audio_init(const char *device,
|
||||
unsigned rate, unsigned latency)
|
||||
{
|
||||
gx_audio_t *wa = (gx_audio_t*)memalign(32, sizeof(*wa));
|
||||
if (!wa)
|
||||
@ -106,8 +108,9 @@ static void *gx_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||
return wa;
|
||||
}
|
||||
|
||||
// Wii uses silly R, L, R, L interleaving ...
|
||||
static inline void copy_swapped(uint32_t * restrict dst, const uint32_t * restrict src, size_t size)
|
||||
/* Wii uses silly R, L, R, L interleaving. */
|
||||
static inline void copy_swapped(uint32_t * restrict dst,
|
||||
const uint32_t * restrict src, size_t size)
|
||||
{
|
||||
do
|
||||
{
|
||||
@ -128,8 +131,10 @@ static ssize_t gx_audio_write(void *data, const void *buf_, size_t size)
|
||||
if (frames < to_write)
|
||||
to_write = frames;
|
||||
|
||||
// FIXME: Nonblocking audio should break out of loop when it has nothing to write.
|
||||
while ((wa->dma_write == wa->dma_next || wa->dma_write == wa->dma_busy) && !wa->nonblock)
|
||||
/* FIXME: Nonblocking audio should break out of loop
|
||||
* when it has nothing to write. */
|
||||
while ((wa->dma_write == wa->dma_next ||
|
||||
wa->dma_write == wa->dma_busy) && !wa->nonblock)
|
||||
OSSleepThread(wa->cond);
|
||||
|
||||
copy_swapped(wa->data[wa->dma_write] + wa->write_ptr, buf, to_write);
|
||||
@ -198,7 +203,8 @@ static void gx_audio_free(void *data)
|
||||
static size_t gx_audio_write_avail(void *data)
|
||||
{
|
||||
gx_audio_t *wa = (gx_audio_t*)data;
|
||||
return ((wa->dma_busy - wa->dma_write + BLOCKS) & (BLOCKS - 1)) * CHUNK_SIZE;
|
||||
return ((wa->dma_busy - wa->dma_write + BLOCKS)
|
||||
& (BLOCKS - 1)) * CHUNK_SIZE;
|
||||
}
|
||||
|
||||
static size_t gx_audio_buffer_size(void *data)
|
||||
|
@ -23,8 +23,8 @@
|
||||
|
||||
#include "../ps3/sdk_defines.h"
|
||||
|
||||
#define AUDIO_BLOCKS 8 // 8 or 16. Guess what we choose? :)
|
||||
#define AUDIO_CHANNELS 2 // All hail glorious stereo!
|
||||
#define AUDIO_BLOCKS 8
|
||||
#define AUDIO_CHANNELS 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -54,7 +54,8 @@ static void event_loop(uint64_t data)
|
||||
cellAudioCreateNotifyEventQueue(&id, &key);
|
||||
cellAudioSetNotifyEventQueue(key);
|
||||
|
||||
float out_tmp[CELL_AUDIO_BLOCK_SAMPLES * AUDIO_CHANNELS] __attribute__((aligned(16)));
|
||||
float out_tmp[CELL_AUDIO_BLOCK_SAMPLES * AUDIO_CHANNELS]
|
||||
__attribute__((aligned(16)));
|
||||
|
||||
while (!aud->quit_thread)
|
||||
{
|
||||
@ -68,14 +69,16 @@ static void event_loop(uint64_t data)
|
||||
sys_lwmutex_unlock(&aud->lock);
|
||||
sys_lwcond_signal(&aud->cond);
|
||||
|
||||
cellAudioAddData(aud->audio_port, out_tmp, CELL_AUDIO_BLOCK_SAMPLES, 1.0);
|
||||
cellAudioAddData(aud->audio_port, out_tmp,
|
||||
CELL_AUDIO_BLOCK_SAMPLES, 1.0);
|
||||
}
|
||||
|
||||
cellAudioRemoveNotifyEventQueue(key);
|
||||
sys_ppu_thread_exit(0);
|
||||
}
|
||||
|
||||
static void *ps3_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||
static void *ps3_audio_init(const char *device,
|
||||
unsigned rate, unsigned latency)
|
||||
{
|
||||
(void)latency;
|
||||
(void)device;
|
||||
@ -103,11 +106,14 @@ static void *ps3_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data->buffer = fifo_new(CELL_AUDIO_BLOCK_SAMPLES * AUDIO_CHANNELS * AUDIO_BLOCKS * sizeof(float));
|
||||
data->buffer = fifo_new(CELL_AUDIO_BLOCK_SAMPLES *
|
||||
AUDIO_CHANNELS * AUDIO_BLOCKS * sizeof(float));
|
||||
|
||||
#ifdef __PSL1GHT__
|
||||
sys_lwmutex_attr_t lock_attr = {SYS_LWMUTEX_ATTR_PROTOCOL, SYS_LWMUTEX_ATTR_RECURSIVE, "\0"};
|
||||
sys_lwmutex_attr_t cond_lock_attr = {SYS_LWMUTEX_ATTR_PROTOCOL, SYS_LWMUTEX_ATTR_RECURSIVE, "\0"};
|
||||
sys_lwmutex_attr_t lock_attr =
|
||||
{SYS_LWMUTEX_ATTR_PROTOCOL, SYS_LWMUTEX_ATTR_RECURSIVE, "\0"};
|
||||
sys_lwmutex_attr_t cond_lock_attr =
|
||||
{SYS_LWMUTEX_ATTR_PROTOCOL, SYS_LWMUTEX_ATTR_RECURSIVE, "\0"};
|
||||
sys_lwcond_attribute_t cond_attr = {"\0"};
|
||||
#else
|
||||
sys_lwmutex_attribute_t lock_attr;
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include <pspaudio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
//ToDO
|
||||
typedef struct psp1_audio
|
||||
{
|
||||
bool nonblocking;
|
||||
@ -48,13 +47,16 @@ static int audioMainLoop(SceSize args, void* argp)
|
||||
|
||||
while (psp->running)
|
||||
{
|
||||
uint16_t readPos = psp->readPos; // get a non volatile copy
|
||||
/* Get a non-volatile copy. */
|
||||
uint16_t readPos = psp->readPos;
|
||||
|
||||
if (((uint16_t)(psp->writePos - readPos) & AUDIO_BUFFER_SIZE_MASK) < (AUDIO_OUT_COUNT * 2))
|
||||
if (((uint16_t)(psp->writePos - readPos) & AUDIO_BUFFER_SIZE_MASK)
|
||||
< (AUDIO_OUT_COUNT * 2))
|
||||
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->zeroBuffer);
|
||||
else
|
||||
{
|
||||
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->buffer + readPos);
|
||||
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX,
|
||||
psp->buffer + readPos);
|
||||
readPos += AUDIO_OUT_COUNT;
|
||||
readPos &= AUDIO_BUFFER_SIZE_MASK;
|
||||
psp->readPos = readPos;
|
||||
@ -66,7 +68,8 @@ static int audioMainLoop(SceSize args, void* argp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *psp_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||
static void *psp_audio_init(const char *device,
|
||||
unsigned rate, unsigned latency)
|
||||
{
|
||||
(void)device;
|
||||
(void)latency;
|
||||
@ -76,16 +79,20 @@ static void *psp_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||
if (!psp)
|
||||
return NULL;
|
||||
|
||||
psp->buffer = (uint32_t*)memalign(64, AUDIO_BUFFER_SIZE * sizeof(uint32_t)); // cache aligned, not necessary but helpful
|
||||
/* Cache aligned, not necessary but helpful. */
|
||||
psp->buffer = (uint32_t*)
|
||||
memalign(64, AUDIO_BUFFER_SIZE * sizeof(uint32_t));
|
||||
memset(psp->buffer, 0, AUDIO_BUFFER_SIZE * sizeof(uint32_t));
|
||||
|
||||
psp->zeroBuffer = (uint32_t*)memalign(64, AUDIO_OUT_COUNT * sizeof(uint32_t));
|
||||
psp->zeroBuffer = (uint32_t*)
|
||||
memalign(64, AUDIO_OUT_COUNT * sizeof(uint32_t));
|
||||
memset(psp->zeroBuffer, 0, AUDIO_OUT_COUNT * sizeof(uint32_t));
|
||||
|
||||
psp->readPos = 0;
|
||||
psp->writePos = 0;
|
||||
psp->rate = rate;
|
||||
psp->thread = sceKernelCreateThread ("audioMainLoop", audioMainLoop, 0x08, 0x10000, 0, NULL);
|
||||
psp->thread = sceKernelCreateThread
|
||||
("audioMainLoop", audioMainLoop, 0x08, 0x10000, 0, NULL);
|
||||
psp->nonblocking = false;
|
||||
|
||||
psp->running = true;
|
||||
@ -118,15 +125,20 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
|
||||
|
||||
sampleCount= size / sizeof(uint32_t);
|
||||
|
||||
// if (psp->nonblocking)
|
||||
// {
|
||||
// /* TODO */
|
||||
// }
|
||||
#if 0
|
||||
if (psp->nonblocking)
|
||||
{
|
||||
/* TODO */
|
||||
}
|
||||
#endif
|
||||
|
||||
if((writePos + sampleCount) > AUDIO_BUFFER_SIZE)
|
||||
{
|
||||
memcpy(psp->buffer + writePos, buf, (AUDIO_BUFFER_SIZE - writePos) * sizeof(uint32_t));
|
||||
memcpy(psp->buffer, (uint32_t*) buf + (AUDIO_BUFFER_SIZE - writePos), (writePos + sampleCount - AUDIO_BUFFER_SIZE) * sizeof(uint32_t));
|
||||
memcpy(psp->buffer + writePos, buf,
|
||||
(AUDIO_BUFFER_SIZE - writePos) * sizeof(uint32_t));
|
||||
memcpy(psp->buffer, (uint32_t*) buf +
|
||||
(AUDIO_BUFFER_SIZE - writePos),
|
||||
(writePos + sampleCount - AUDIO_BUFFER_SIZE) * sizeof(uint32_t));
|
||||
}
|
||||
else
|
||||
memcpy(psp->buffer + writePos, buf, size);
|
||||
@ -145,7 +157,8 @@ static bool psp_audio_stop(void *data)
|
||||
|
||||
runStatus.size = sizeof(SceKernelThreadRunStatus);
|
||||
|
||||
if (sceKernelReferThreadRunStatus(psp->thread, &runStatus) < 0) // error
|
||||
if (sceKernelReferThreadRunStatus(
|
||||
psp->thread, &runStatus) < 0) /* Error */
|
||||
return false;
|
||||
if (runStatus.status == PSP_THREAD_STOPPED)
|
||||
return false;
|
||||
@ -164,7 +177,8 @@ static bool psp_audio_start(void *data)
|
||||
|
||||
runStatus.size = sizeof(SceKernelThreadRunStatus);
|
||||
|
||||
if (sceKernelReferThreadRunStatus(psp->thread, &runStatus) < 0) // error
|
||||
if (sceKernelReferThreadRunStatus(
|
||||
psp->thread, &runStatus) < 0) /* Error */
|
||||
return false;
|
||||
if (runStatus.status != PSP_THREAD_STOPPED)
|
||||
return false;
|
||||
@ -192,7 +206,8 @@ static size_t psp_write_avail(void *data)
|
||||
{
|
||||
/* TODO */
|
||||
psp1_audio_t* psp = (psp1_audio_t*)data;
|
||||
return AUDIO_BUFFER_SIZE - ((uint16_t)(psp->writePos - psp->readPos) & AUDIO_BUFFER_SIZE_MASK);
|
||||
return AUDIO_BUFFER_SIZE - ((uint16_t)
|
||||
(psp->writePos - psp->readPos) & AUDIO_BUFFER_SIZE_MASK);
|
||||
}
|
||||
|
||||
static size_t psp_buffer_size(void *data)
|
||||
|
@ -30,7 +30,8 @@ typedef struct
|
||||
bool nonblock;
|
||||
} xenon_audio_t;
|
||||
|
||||
static void *xenon360_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||
static void *xenon360_audio_init(const char *device,
|
||||
unsigned rate, unsigned latency)
|
||||
{
|
||||
static bool inited = false;
|
||||
if (!inited)
|
||||
@ -45,7 +46,8 @@ static void *xenon360_audio_init(const char *device, unsigned rate, unsigned lat
|
||||
|
||||
static inline uint32_t bswap_32(uint32_t val)
|
||||
{
|
||||
return (val >> 24) | (val << 24) | ((val >> 8) & 0xff00) | ((val << 8) & 0xff0000);
|
||||
return (val >> 24) | (val << 24) |
|
||||
((val >> 8) & 0xff00) | ((val << 8) & 0xff0000);
|
||||
}
|
||||
|
||||
static ssize_t xenon360_audio_write(void *data, const void *buf, size_t size)
|
||||
@ -62,7 +64,8 @@ static ssize_t xenon360_audio_write(void *data, const void *buf, size_t size)
|
||||
{
|
||||
while (xenon_sound_get_unplayed() >= MAX_BUFFER)
|
||||
{
|
||||
// libxenon doesn't have proper synchronization primitives for this :(
|
||||
/* libxenon doesn't have proper
|
||||
* synchronization primitives for this... */
|
||||
udelay(50);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user