AUDIO: make the plugins self-registering
No need anymore for the RegisterAllBackends() function and all plugins in one place. Use a static boolean to register every plugin by itself.
This commit is contained in:
parent
7e11e7aff6
commit
b443fe9b25
|
@ -1,4 +1,4 @@
|
|||
#include "oslib/audiobackend_alsa.h"
|
||||
#include "oslib/audiostream.h"
|
||||
#if USE_ALSA
|
||||
#include <alsa/asoundlib.h>
|
||||
#include "cfg/cfg.h"
|
||||
|
@ -175,11 +175,13 @@ static void alsa_term()
|
|||
snd_pcm_close(handle);
|
||||
}
|
||||
|
||||
audiobackend_t audiobackend_alsa = {
|
||||
static audiobackend_t audiobackend_alsa = {
|
||||
"alsa", // Slug
|
||||
"Advanced Linux Sound Architecture", // Name
|
||||
&alsa_init,
|
||||
&alsa_push,
|
||||
&alsa_term
|
||||
};
|
||||
|
||||
static bool alsa = RegisterAudioBackend(&audiobackend_alsa);
|
||||
#endif
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
#pragma once
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
extern audiobackend_t audiobackend_alsa;
|
|
@ -1,4 +0,0 @@
|
|||
#pragma once
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
extern audiobackend_t audiobackend_android;
|
|
@ -12,7 +12,7 @@
|
|||
It does work on my macmini though
|
||||
*/
|
||||
|
||||
#include "oslib/audiobackend_coreaudio.h"
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
#if HOST_OS == OS_DARWIN
|
||||
#include <atomic>
|
||||
|
@ -161,4 +161,7 @@ audiobackend_t audiobackend_coreaudio = {
|
|||
&coreaudio_push,
|
||||
&coreaudio_term
|
||||
};
|
||||
|
||||
static bool core = RegisterAudioBackend(&audiobackend_coreaudio);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
#pragma once
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
extern audiobackend_t audiobackend_coreaudio;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#include "oslib/audiobackend_directsound.h"
|
||||
#include "oslib/audiostream.h"
|
||||
#if HOST_OS==OS_WINDOWS
|
||||
#include "oslib.h"
|
||||
#include <initguid.h>
|
||||
|
@ -187,4 +187,6 @@ audiobackend_t audiobackend_directsound = {
|
|||
&directsound_push,
|
||||
&directsound_term
|
||||
};
|
||||
|
||||
static bool ds = RegisterAudioBackend(&audiobackend_directsound);
|
||||
#endif
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
#pragma once
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
extern audiobackend_t audiobackend_directsound;
|
|
@ -1,4 +1,4 @@
|
|||
#include "oslib/audiobackend_libao.h"
|
||||
#include "oslib/audiostream.h"
|
||||
#ifdef USE_LIBAO
|
||||
|
||||
#include <ao/ao.h>
|
||||
|
@ -46,4 +46,5 @@ audiobackend_t audiobackend_libao = {
|
|||
&libao_term
|
||||
};
|
||||
|
||||
static bool ao = RegisterAudioBackend(&audiobackend_libao);
|
||||
#endif
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
#pragma once
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
extern audiobackend_t audiobackend_libao;
|
|
@ -1,4 +1,4 @@
|
|||
#include "oslib/audiobackend_omx.h"
|
||||
#include "oslib/audiostream.h"
|
||||
#if USE_OMX
|
||||
|
||||
#include <IL/OMX_Broadcom.h>
|
||||
|
@ -316,4 +316,5 @@ audiobackend_t audiobackend_omx = {
|
|||
&omx_term
|
||||
};
|
||||
|
||||
static bool omx = RegisterAudioBackend(&audiobackend_omx);
|
||||
#endif
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
#pragma once
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
extern audiobackend_t audiobackend_omx;
|
|
@ -1,4 +1,4 @@
|
|||
#include "oslib/audiobackend_oss.h"
|
||||
#include "oslib/audiostream.h"
|
||||
#ifdef USE_OSS
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
@ -51,4 +51,5 @@ audiobackend_t audiobackend_oss = {
|
|||
&oss_term
|
||||
};
|
||||
|
||||
static bool oss = RegisterAudioBackend(&audiobackend_oss);
|
||||
#endif
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
#pragma once
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
extern audiobackend_t audiobackend_oss;
|
|
@ -1,4 +1,4 @@
|
|||
#include "oslib/audiobackend_pulseaudio.h"
|
||||
#include "oslib/audiostream.h"
|
||||
#ifdef USE_PULSEAUDIO
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/fcntl.h>
|
||||
|
@ -45,4 +45,6 @@ audiobackend_t audiobackend_pulseaudio = {
|
|||
&pulseaudio_push,
|
||||
&pulseaudio_term
|
||||
};
|
||||
|
||||
static bool pulse = RegisterAudioBackend(&audiobackend_pulseaudio);
|
||||
#endif
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
#pragma once
|
||||
#include "oslib/audiostream.h"
|
||||
|
||||
extern audiobackend_t audiobackend_pulseaudio;
|
|
@ -2,14 +2,6 @@
|
|||
#include "cfg/cfg.h"
|
||||
#include "oslib/oslib.h"
|
||||
#include "audiostream.h"
|
||||
#include "oslib/audiobackend_directsound.h"
|
||||
#include "oslib/audiobackend_android.h"
|
||||
#include "oslib/audiobackend_alsa.h"
|
||||
#include "oslib/audiobackend_oss.h"
|
||||
#include "oslib/audiobackend_pulseaudio.h"
|
||||
#include "oslib/audiobackend_coreaudio.h"
|
||||
#include "oslib/audiobackend_omx.h"
|
||||
#include "oslib/audiobackend_libao.h"
|
||||
|
||||
struct SoundFrame { s16 l;s16 r; };
|
||||
#define SAMPLE_COUNT 512
|
||||
|
@ -25,18 +17,20 @@ u32 gen_samples=0;
|
|||
|
||||
double time_diff = 128/44100.0;
|
||||
double time_last;
|
||||
|
||||
#ifdef LOG_SOUND
|
||||
// TODO Only works on Windows!
|
||||
WaveWriter rawout("d:\\aica_out.wav");
|
||||
#endif
|
||||
|
||||
static bool audiobackends_registered = false;
|
||||
static unsigned int audiobackends_num_max = 1;
|
||||
static unsigned int audiobackends_num_registered = 0;
|
||||
static audiobackend_t **audiobackends = static_cast<audiobackend_t**>(calloc(audiobackends_num_max, sizeof(audiobackend_t*)));
|
||||
static audiobackend_t **audiobackends = NULL;
|
||||
static audiobackend_t *audiobackend_current = NULL;
|
||||
|
||||
bool RegisterAudioBackend(audiobackend_t *backend)
|
||||
{
|
||||
printf("RegisterAUdio!\n");
|
||||
/* This function announces the availability of an audio backend to reicast. */
|
||||
// Check if backend is valid
|
||||
if (backend == NULL)
|
||||
|
@ -44,10 +38,16 @@ bool RegisterAudioBackend(audiobackend_t *backend)
|
|||
printf("ERROR: Tried to register invalid audio backend (NULL pointer).\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (backend->slug == "auto" || backend->slug == "none") {
|
||||
printf("ERROR: Tried to register invalid audio backend (slug \"%s\" is a reserved keyword).\n", backend->slug.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// First call to RegisterAudioBackend(), create the backend structure;
|
||||
if (audiobackends == NULL)
|
||||
audiobackends = static_cast<audiobackend_t**>(calloc(audiobackends_num_max, sizeof(audiobackend_t*)));
|
||||
|
||||
// Check if we need to allocate addition memory for storing the pointers and allocate if neccessary
|
||||
if (audiobackends_num_registered == audiobackends_num_max)
|
||||
{
|
||||
|
@ -67,41 +67,15 @@ bool RegisterAudioBackend(audiobackend_t *backend)
|
|||
}
|
||||
audiobackends = new_ptr;
|
||||
}
|
||||
|
||||
audiobackends[audiobackends_num_registered] = backend;
|
||||
audiobackends_num_registered++;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RegisterAllAudioBackends() {
|
||||
#if HOST_OS==OS_WINDOWS
|
||||
RegisterAudioBackend(&audiobackend_directsound);
|
||||
#endif
|
||||
#if ANDROID
|
||||
RegisterAudioBackend(&audiobackend_android);
|
||||
#endif
|
||||
#if USE_OMX
|
||||
RegisterAudioBackend(&audiobackend_omx);
|
||||
#endif
|
||||
#if USE_ALSA
|
||||
RegisterAudioBackend(&audiobackend_alsa);
|
||||
#endif
|
||||
#if USE_OSS
|
||||
RegisterAudioBackend(&audiobackend_oss);
|
||||
#endif
|
||||
#if USE_PULSEAUDIO
|
||||
RegisterAudioBackend(&audiobackend_pulseaudio);
|
||||
#endif
|
||||
#if USE_LIBAO
|
||||
RegisterAudioBackend(&audiobackend_libao);
|
||||
#endif
|
||||
#if HOST_OS == OS_DARWIN
|
||||
RegisterAudioBackend(&audiobackend_coreaudio);
|
||||
#endif
|
||||
audiobackends_registered = true;
|
||||
}
|
||||
|
||||
static audiobackend_t* GetAudioBackend(std::string slug)
|
||||
{
|
||||
printf("AudioBackend: %s\n", slug);
|
||||
if (slug == "none")
|
||||
{
|
||||
printf("WARNING: Audio backend set to \"none\"!\n");
|
||||
|
@ -135,7 +109,8 @@ static audiobackend_t* GetAudioBackend(std::string slug)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
u32 PushAudio(void* frame, u32 amt, bool wait) {
|
||||
u32 PushAudio(void* frame, u32 amt, bool wait)
|
||||
{
|
||||
if (audiobackend_current != NULL) {
|
||||
return audiobackend_current->push(frame, amt, wait);
|
||||
}
|
||||
|
@ -151,6 +126,7 @@ u32 asRingUsedCount()
|
|||
//s32 sz=(WritePtr+1)%RingBufferSampleCount-ReadPtr;
|
||||
//return sz<0?sz+RingBufferSampleCount:sz;
|
||||
}
|
||||
|
||||
u32 asRingFreeCount()
|
||||
{
|
||||
return RingBufferSampleCount-asRingUsedCount();
|
||||
|
@ -178,11 +154,6 @@ void InitAudio()
|
|||
|
||||
cfgSaveInt("audio","disable",0);
|
||||
|
||||
if (!audiobackends_registered) {
|
||||
//FIXME: There might some nicer way to do this.
|
||||
RegisterAllAudioBackends();
|
||||
}
|
||||
|
||||
if (audiobackend_current != NULL) {
|
||||
printf("ERROR: The audio backend \"%s\" (%s) has already been initialized, you need to terminate it before you can call audio_init() again!\n", audiobackend_current->slug.c_str(), audiobackend_current->name.c_str());
|
||||
return;
|
||||
|
@ -194,6 +165,7 @@ void InitAudio()
|
|||
printf("WARNING: Running without audio!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Initializing audio backend \"%s\" (%s)...\n", audiobackend_current->slug.c_str(), audiobackend_current->name.c_str());
|
||||
audiobackend_current->init();
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "hw/maple/maple_devs.h"
|
||||
#include "hw/maple/maple_if.h"
|
||||
#include "hw/naomi/naomi_cart.h"
|
||||
#include "oslib/audiobackend_android.h"
|
||||
#include "oslib/audiostream.h"
|
||||
#include "imgread/common.h"
|
||||
#include "rend/gui.h"
|
||||
#include "cfg/cfg.h"
|
||||
|
@ -529,6 +529,9 @@ audiobackend_t audiobackend_android = {
|
|||
&androidaudio_term
|
||||
};
|
||||
|
||||
static bool android = RegisterAudioBackend(&audiobackend_android);
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_AudioBackend_setInstance(JNIEnv *env, jobject obj, jobject instance)
|
||||
{
|
||||
if (g_audioBackend != NULL)
|
||||
|
|
Loading…
Reference in New Issue