mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 09:40:06 +00:00
(ALSA) Some simplifications
This commit is contained in:
parent
9817555200
commit
27d9441ffa
34
audio/alsa.c
34
audio/alsa.c
@ -42,35 +42,37 @@ static bool alsa_use_float(void *data)
|
|||||||
static bool find_float_format(snd_pcm_t *pcm, void *data)
|
static bool find_float_format(snd_pcm_t *pcm, void *data)
|
||||||
{
|
{
|
||||||
snd_pcm_hw_params_t *params = (snd_pcm_hw_params_t*)data;
|
snd_pcm_hw_params_t *params = (snd_pcm_hw_params_t*)data;
|
||||||
|
|
||||||
if (snd_pcm_hw_params_test_format(pcm, params, SND_PCM_FORMAT_FLOAT) == 0)
|
if (snd_pcm_hw_params_test_format(pcm, params, SND_PCM_FORMAT_FLOAT) == 0)
|
||||||
{
|
{
|
||||||
RARCH_LOG("ALSA: Using floating point format.\n");
|
RARCH_LOG("ALSA: Using floating point format.\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RARCH_LOG("ALSA: Using signed 16-bit format.\n");
|
RARCH_LOG("ALSA: Using signed 16-bit format.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *alsa_init(const char *device, unsigned rate, unsigned latency)
|
static void *alsa_init(const char *device, unsigned rate, unsigned latency)
|
||||||
{
|
{
|
||||||
alsa_t *alsa = (alsa_t*)calloc(1, sizeof(alsa_t));
|
snd_pcm_format_t format;
|
||||||
if (!alsa)
|
snd_pcm_uframes_t buffer_size;
|
||||||
return NULL;
|
|
||||||
|
|
||||||
snd_pcm_hw_params_t *params = NULL;
|
snd_pcm_hw_params_t *params = NULL;
|
||||||
snd_pcm_sw_params_t *sw_params = NULL;
|
snd_pcm_sw_params_t *sw_params = NULL;
|
||||||
|
|
||||||
unsigned latency_usec = latency * 1000;
|
unsigned latency_usec = latency * 1000;
|
||||||
unsigned channels = 2;
|
unsigned channels = 2;
|
||||||
unsigned periods = 4;
|
unsigned periods = 4;
|
||||||
snd_pcm_format_t format;
|
|
||||||
|
|
||||||
const char *alsa_dev = "default";
|
const char *alsa_dev = "default";
|
||||||
|
alsa_t *alsa = (alsa_t*)calloc(1, sizeof(alsa_t));
|
||||||
|
|
||||||
|
if (!alsa)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (device)
|
if (device)
|
||||||
alsa_dev = device;
|
alsa_dev = device;
|
||||||
|
|
||||||
snd_pcm_uframes_t buffer_size;
|
|
||||||
|
|
||||||
TRY_ALSA(snd_pcm_open(
|
TRY_ALSA(snd_pcm_open(
|
||||||
&alsa->pcm, alsa_dev, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK));
|
&alsa->pcm, alsa_dev, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK));
|
||||||
TRY_ALSA(snd_pcm_hw_params_malloc(¶ms));
|
TRY_ALSA(snd_pcm_hw_params_malloc(¶ms));
|
||||||
@ -134,18 +136,20 @@ error:
|
|||||||
|
|
||||||
static ssize_t alsa_write(void *data, const void *buf_, size_t size_)
|
static ssize_t alsa_write(void *data, const void *buf_, size_t size_)
|
||||||
{
|
{
|
||||||
alsa_t *alsa = (alsa_t*)data;
|
alsa_t *alsa = (alsa_t*)data;
|
||||||
const uint8_t *buf = (const uint8_t*)buf_;
|
const uint8_t *buf = (const uint8_t*)buf_;
|
||||||
|
|
||||||
bool eagain_retry = true;
|
bool eagain_retry = true;
|
||||||
snd_pcm_sframes_t written = 0;
|
snd_pcm_sframes_t written = 0;
|
||||||
snd_pcm_sframes_t size = snd_pcm_bytes_to_frames(alsa->pcm, size_);
|
snd_pcm_sframes_t size = snd_pcm_bytes_to_frames(alsa->pcm, size_);
|
||||||
|
|
||||||
while (size)
|
while (size)
|
||||||
{
|
{
|
||||||
|
snd_pcm_sframes_t frames;
|
||||||
|
|
||||||
if (!alsa->nonblock)
|
if (!alsa->nonblock)
|
||||||
{
|
{
|
||||||
int rc = snd_pcm_wait(alsa->pcm, -1);
|
int rc = snd_pcm_wait(alsa->pcm, -1);
|
||||||
|
|
||||||
if (rc == -EPIPE || rc == -ESTRPIPE || rc == -EINTR)
|
if (rc == -EPIPE || rc == -ESTRPIPE || rc == -EINTR)
|
||||||
{
|
{
|
||||||
if (snd_pcm_recover(alsa->pcm, rc, 1) < 0)
|
if (snd_pcm_recover(alsa->pcm, rc, 1) < 0)
|
||||||
@ -158,7 +162,7 @@ static ssize_t alsa_write(void *data, const void *buf_, size_t size_)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_pcm_sframes_t frames = snd_pcm_writei(alsa->pcm, buf, size);
|
frames = snd_pcm_writei(alsa->pcm, buf, size);
|
||||||
|
|
||||||
if (frames == -EPIPE || frames == -EINTR || frames == -ESTRPIPE)
|
if (frames == -EPIPE || frames == -EINTR || frames == -ESTRPIPE)
|
||||||
{
|
{
|
||||||
@ -205,9 +209,9 @@ static ssize_t alsa_write(void *data, const void *buf_, size_t size_)
|
|||||||
static bool alsa_alive(void *data)
|
static bool alsa_alive(void *data)
|
||||||
{
|
{
|
||||||
alsa_t *alsa = (alsa_t*)data;
|
alsa_t *alsa = (alsa_t*)data;
|
||||||
if (alsa)
|
if (!alsa)
|
||||||
return !alsa->is_paused;
|
return false;
|
||||||
return false;
|
return !alsa->is_paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool alsa_stop(void *data)
|
static bool alsa_stop(void *data)
|
||||||
@ -273,8 +277,8 @@ static void alsa_free(void *data)
|
|||||||
static size_t alsa_write_avail(void *data)
|
static size_t alsa_write_avail(void *data)
|
||||||
{
|
{
|
||||||
alsa_t *alsa = (alsa_t*)data;
|
alsa_t *alsa = (alsa_t*)data;
|
||||||
|
|
||||||
snd_pcm_sframes_t avail = snd_pcm_avail(alsa->pcm);
|
snd_pcm_sframes_t avail = snd_pcm_avail(alsa->pcm);
|
||||||
|
|
||||||
if (avail < 0)
|
if (avail < 0)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user