diff --git a/audio/alsa.c b/audio/alsa.c index 54ac58379a..b3f6f0b5e5 100644 --- a/audio/alsa.c +++ b/audio/alsa.c @@ -119,21 +119,20 @@ error: return NULL; } -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; + const uint8_t *buf = (const uint8_t*)buf_; - snd_pcm_sframes_t frames; snd_pcm_sframes_t written = 0; - int rc; - size = snd_pcm_bytes_to_frames(alsa->pcm, size); // Frames to write + snd_pcm_sframes_t size = snd_pcm_bytes_to_frames(alsa->pcm, size_); - while (written < (snd_pcm_sframes_t)size) + while (size) { if (!alsa->nonblock) { - rc = snd_pcm_wait(alsa->pcm, -1); - if (rc == -EPIPE || rc == -ESTRPIPE) + int rc = snd_pcm_wait(alsa->pcm, -1); + if (rc == -EPIPE || rc == -ESTRPIPE || rc == -EINTR) { if (snd_pcm_recover(alsa->pcm, rc, 1) < 0) return -1; @@ -141,24 +140,26 @@ static ssize_t alsa_write(void *data, const void *buf, size_t size) } } - frames = snd_pcm_writei(alsa->pcm, (const char*)buf + written * 2 * (alsa->has_float ? sizeof(float) : sizeof(int16_t)), size - written); + snd_pcm_sframes_t frames = snd_pcm_writei(alsa->pcm, buf, size); if (frames == -EPIPE || frames == -EINTR || frames == -ESTRPIPE) { if (snd_pcm_recover(alsa->pcm, frames, 1) < 0) return -1; - return 0; + break; } else if (frames == -EAGAIN && alsa->nonblock) - return 0; + break; else if (frames < 0) return -1; written += frames; + buf += (frames << 1) * (alsa->has_float ? sizeof(float) : sizeof(int16_t)); + size -= frames; } - return snd_pcm_frames_to_bytes(alsa->pcm, size); + return written; } static bool alsa_stop(void *data) @@ -180,6 +181,7 @@ static bool alsa_start(void *data) static void alsa_free(void *data) { alsa_t *alsa = (alsa_t*)data; + if (alsa) { if (alsa->pcm) diff --git a/audio/oss.c b/audio/oss.c index a5cb53491c..f0774dbdee 100644 --- a/audio/oss.c +++ b/audio/oss.c @@ -113,6 +113,7 @@ static ssize_t oss_write(void *data, const void *buf, size_t size) { if ((fcntl(*fd, F_GETFL) & O_NONBLOCK) && errno == EAGAIN) return 0; + return -1; } diff --git a/general.h b/general.h index f86bb9e4fb..37d26931f1 100644 --- a/general.h +++ b/general.h @@ -474,7 +474,7 @@ extern struct console_settings g_console; #ifndef RARCH_LOG #define RARCH_LOG(...) do { \ if (g_extern.verbose) \ - fprintf(stderr, "SSNES: " __VA_ARGS__); \ + fprintf(stderr, "RetroArch: " __VA_ARGS__); \ fflush(stderr); \ } while (0) #endif