Added ALSA audio backend
This adds the OSS audio backend, which is basically a slightly modified version of core/oslib/alsa_audiostream.cpp from the skmp/linux-x64 branch (as of commit cdf9f3dc971506c2efd979275c2869f064e1027c). The ALSA backend will be included during compilation if HOST_OS is OS_LINUX and neither TARGET_NACL32 nor ANDROID are defined. This should be changed to a USE_ALSA flag in the future (for constistency and and simplicity reasons), but i didn't want to put too much stuff into this commit.
This commit is contained in:
parent
f6d2e3fa7e
commit
167fba4c9f
|
@ -1,81 +1,13 @@
|
||||||
|
#include "oslib/audiobackend_alsa.h"
|
||||||
#include "audiostream.h"
|
// FIXME: We should definitely change this to "#if SUPPORT_ALSA" and set SUPPORT_ALSA to 0 or 1 in the Makefile
|
||||||
#include "oslib/oslib.h"
|
|
||||||
|
|
||||||
#include "cfg/cfg.h"
|
|
||||||
|
|
||||||
#if HOST_OS==OS_LINUX && !defined(TARGET_NACL32) && !defined(ANDROID)
|
#if HOST_OS==OS_LINUX && !defined(TARGET_NACL32) && !defined(ANDROID)
|
||||||
|
|
||||||
#if 1
|
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
snd_pcm_t *handle;
|
snd_pcm_t *handle;
|
||||||
|
|
||||||
u32 alsa_Push(void* frame, u32 samples, bool wait) {
|
// We're making these functions static - there's no need to pollute the global namespace
|
||||||
|
static void alsa_init()
|
||||||
snd_pcm_nonblock(handle, wait ? 0 : 1);
|
|
||||||
|
|
||||||
int rc = snd_pcm_writei(handle, frame, samples);
|
|
||||||
if (rc == -EPIPE)
|
|
||||||
{
|
|
||||||
/* EPIPE means underrun */
|
|
||||||
fprintf(stderr, "ALSA: underrun occurred\n");
|
|
||||||
snd_pcm_prepare(handle);
|
|
||||||
alsa_Push(frame, samples * 8, wait);
|
|
||||||
}
|
|
||||||
else if (rc < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ALSA: error from writei: %s\n", snd_strerror(rc));
|
|
||||||
}
|
|
||||||
else if (rc != samples)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ALSA: short write, wrote %d frames of %d\n", rc, samples);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
u8 Tempbuffer[8192*4];
|
|
||||||
void* AudioThread(void*)
|
|
||||||
{
|
{
|
||||||
sched_param sched;
|
|
||||||
int policy;
|
|
||||||
|
|
||||||
pthread_getschedparam(pthread_self(),&policy,&sched);
|
|
||||||
sched.sched_priority++;//policy=SCHED_RR;
|
|
||||||
pthread_setschedparam(pthread_self(),policy,&sched);
|
|
||||||
|
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
UpdateBuff(Tempbuffer);
|
|
||||||
int rc = snd_pcm_writei(handle, Tempbuffer, settings.aica.BufferSize);
|
|
||||||
if (rc == -EPIPE)
|
|
||||||
{
|
|
||||||
/* EPIPE means underrun */
|
|
||||||
fprintf(stderr, "underrun occurred\n");
|
|
||||||
snd_pcm_prepare(handle);
|
|
||||||
}
|
|
||||||
else if (rc < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "error from writei: %s\n", snd_strerror(rc));
|
|
||||||
}
|
|
||||||
else if (rc != (int)settings.aica.BufferSize)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "short write, write %d frames\n", rc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cThread aud_thread(AudioThread,0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void os_InitAudio()
|
|
||||||
{
|
|
||||||
|
|
||||||
if (cfgLoadInt("audio","disable",0))
|
|
||||||
return;
|
|
||||||
|
|
||||||
cfgSaveInt("audio","disable",0);
|
|
||||||
|
|
||||||
long loops;
|
long loops;
|
||||||
int size;
|
int size;
|
||||||
|
@ -171,12 +103,40 @@ void os_InitAudio()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void os_TermAudio()
|
static u32 alsa_push(void* frame, u32 samples, bool wait)
|
||||||
|
{
|
||||||
|
snd_pcm_nonblock(handle, wait ? 0 : 1);
|
||||||
|
|
||||||
|
int rc = snd_pcm_writei(handle, frame, samples);
|
||||||
|
if (rc == -EPIPE)
|
||||||
|
{
|
||||||
|
/* EPIPE means underrun */
|
||||||
|
fprintf(stderr, "ALSA: underrun occurred\n");
|
||||||
|
snd_pcm_prepare(handle);
|
||||||
|
alsa_push(frame, samples * 8, wait);
|
||||||
|
}
|
||||||
|
else if (rc < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ALSA: error from writei: %s\n", snd_strerror(rc));
|
||||||
|
}
|
||||||
|
else if (rc != samples)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ALSA: short write, wrote %d frames of %d\n", rc, samples);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void alsa_term()
|
||||||
{
|
{
|
||||||
snd_pcm_drain(handle);
|
snd_pcm_drain(handle);
|
||||||
snd_pcm_close(handle);
|
snd_pcm_close(handle);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
|
||||||
#endif
|
audiobackend_t audiobackend_alsa = {
|
||||||
|
"alsa", // Slug
|
||||||
|
"Advanced Linux Sound Architecture", // Name
|
||||||
|
&alsa_init,
|
||||||
|
&alsa_push,
|
||||||
|
&alsa_term
|
||||||
|
};
|
||||||
#endif
|
#endif
|
|
@ -0,0 +1,4 @@
|
||||||
|
#pragma once
|
||||||
|
#include "oslib/audiostream.h"
|
||||||
|
|
||||||
|
extern audiobackend_t audiobackend_alsa;
|
|
@ -72,6 +72,10 @@ void RegisterAllAudioBackends() {
|
||||||
#if USE_OSS
|
#if USE_OSS
|
||||||
RegisterAudioBackend(&audiobackend_oss);
|
RegisterAudioBackend(&audiobackend_oss);
|
||||||
#endif
|
#endif
|
||||||
|
// FIXME: We should definitely change this to "#if SUPPORT_ALSA" and set SUPPORT_ALSA to 0 or 1 in the Makefile
|
||||||
|
#if HOST_OS==OS_LINUX && !defined(TARGET_NACL32) && !defined(ANDROID)
|
||||||
|
RegisterAudioBackend(&audiobackend_alsa);
|
||||||
|
#endif
|
||||||
audiobackends_registered = true;
|
audiobackends_registered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue